From: Xiaowen P. <dor...@ya...> - 2007-08-27 10:36:11
|
Hi Dear,=0A I used the CRF code to generate the parameters successfully,= but when I read them in and apply to a new test data I got exceptions. I h= ave 2 questions:=0A 1.How to prepare the parameter of the method: CRF.ap= ply(DataSequence dataSeq). As for the DataSequence, there are two fields, x= and y. But in the test data, there should only be x logically. So,how to p= repare this dataSeq (I have implemented the interface DataSequence).=0A 2.= Why doesn't this kind of code work?=0A =0Apublic static void main(String[] = args) throws Exception { =0A CRFAppl crf =3D new CRFAppl();=0A...........= ..=0A crf.train();=0A crf.test();=0A}=0A =0Apublic void train() thr= ows Exception {=0A allocModel();=0A double featureWts[] =3D crfMode= l.train(trainDataIter);=0A crfModel.write(dataPath + "/crfOutput.txt");= =0A featureGen.write(dataPath + "/featureOutput.txt");=0A}=0A =0Apublic= void test() throws Exception {=0A allocModel();=0A featureGen.read(dataP= ath + "/featureOutput.txt");=0A crfModel.read(dataPath + "/crfOutput.txt")= ;=0A crfModel.apply(testRecord);=0A crfModel.write(dataPath + "/testOutpu= t.txt");=0A}=0A =0Avoid allocModel() throws Exception {=0A featureGen = =3D new FeatureGenImpl("naive", 8, true);=0A featureGen.train(trainData= Iter);=0A crfModel=3Dnew CRF(8,featureGen, "numLabels 8");=0A}=0A =0AI = got such exceptions:=0AException in thread "main" java.lang.NumberFormatExc= eption: For input string: "Main,"=0A at java.lang.NumberFormatException.for= InputString(Unknown Source)=0A at java.lang.Integer.parseInt(Unknown Source= )=0A at java.lang.Integer.parseInt(Unknown Source)=0A at iitb.Model.WordsIn= Train.read(WordsInTrain.java:134)=0A at iitb.Model.FeatureGenImpl.read(Feat= ureGenImpl.java:363)=0A at app.CRFAppl.test(CRFAppl.java:164)=0A at app.CRF= Appl.main(CRFAppl.java:108)=0A =0AI tracked in but only find the key uses s= pace(" ") to seperate tokens but the trained data does not. Why does it hap= pen? or I have some misunderstandings?=0AAre these read mothods nessessary,= if I test it immediately after the train() method?=0A =0AThanks & Regards,= =0A =0ADoris Pan=0A=0A=0A=0A=D1=C5=BB=A2=D3=CA=CF=E4=A3=AC=D2=D4=B0=B2=C8= =AB=D6=F8=B3=C6=A3=AC=CA=C7=D6=B5=B5=C3=D0=C5=C0=B5=B5=C4=D3=CA=CF=E4=D7=A8= =BC=D2=A3=A1=0A=0A=0A ________________________________________________= ___________ =0A=D1=C5=BB=A2=C3=E2=B7=D1=D3=CA=CF=E4=A3=AC=C8=AB=C7=F2=B5=DA= =D2=BB=D3=CA=CF=E4=C6=B7=C5=C6=A3=A1 =0Ahttp://mail.yahoo.com.cn/ |