From: Xiaowen P. <dor...@ya...> - 2007-08-27 09:15:20
|
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[] a= rgs) throws Exception { =0A CRFAppl crf =3D new CRFAppl();=0A............= .=0A crf.train();=0A crf.test();=0A}=0A=0Apublic void train() throw= s Exception {=0A allocModel();=0A double featureWts[] =3D crfModel.= 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(dataPa= th + "/featureOutput.txt");=0A crfModel.read(dataPath + "/crfOutput.txt");= =0A crfModel.apply(testRecord);=0A crfModel.write(dataPath + "/testOutput= .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 g= ot such exceptions:=0AException in thread "main" java.lang.NumberFormatExce= ption: For input string: "Main,"=0A at java.lang.NumberFormatException.forI= nputString(Unknown Source)=0A at java.lang.Integer.parseInt(Unknown Source)= =0A at java.lang.Integer.parseInt(Unknown Source)=0A at iitb.Model.WordsInT= rain.read(WordsInTrain.java:134)=0A at iitb.Model.FeatureGenImpl.read(Featu= reGenImpl.java:363)=0A at app.CRFAppl.test(CRFAppl.java:164)=0A at app.CRFA= ppl.main(CRFAppl.java:108)=0A=0AI tracked in but only find the key uses spa= ce(" ") to seperate tokens but the trained data does not. Why does it happe= n? or I have some misunderstandings?=0AAre these read mothods nessessary, i= f I test it immediately after the train() method?=0A=0AThanks & Regards,=0A= =0ADoris Pan=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/ |