Hi Dear,
    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 have 2 questions:
    1.How to prepare the parameter of the method: CRF.apply(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 prepare this dataSeq (I have implemented the interface DataSequence).
  2.Why doesn't this kind of code work?
 
public static void main(String[] args) throws Exception { 
  CRFAppl crf = new CRFAppl();
.............
     crf.train();
     crf.test();
}
 
public void train() throws Exception {
     allocModel();
     double featureWts[] = crfModel.train(trainDataIter);
     crfModel.write(dataPath + "/crfOutput.txt");
     featureGen.write(dataPath + "/featureOutput.txt");
}
 
public void test() throws Exception {
  allocModel();
  featureGen.read(dataPath + "/featureOutput.txt");
  crfModel.read(dataPath + "/crfOutput.txt");
  crfModel.apply(testRecord);
  crfModel.write(dataPath + "/testOutput.txt");
}
 
void  allocModel() throws Exception {
     featureGen = new FeatureGenImpl("naive", 8, true);
     featureGen.train(trainDataIter);
     crfModel=new CRF(8,featureGen, "numLabels 8");
}
 
I got such exceptions:
Exception in thread "main" java.lang.NumberFormatException: For input string: "Main,"
 at java.lang.NumberFormatException.forInputString(Unknown Source)
 at java.lang.Integer.parseInt(Unknown Source)
 at java.lang.Integer.parseInt(Unknown Source)
 at iitb.Model.WordsInTrain.read(WordsInTrain.java:134)
 at iitb.Model.FeatureGenImpl.read(FeatureGenImpl.java:363)
 at app.CRFAppl.test(CRFAppl.java:164)
 at app.CRFAppl.main(CRFAppl.java:108)
 
I tracked in but only find the key uses space(" ") to seperate tokens but the trained data does not. Why does it happen? or I have some misunderstandings?
Are these read mothods nessessary, if I test it immediately after the train() method?
 
Thanks & Regards,
 
Doris Pan


雅虎邮箱,以安全著称,是值得信赖的邮箱专家!