I already have a CRF trained model that I have trained using SimpleTagger.
SimpleTagger.main(new String[] {
"--train", "true",
"--model-file", "/Desktop/crfmodel",
"--threads", "8",
"--training-proportion", "0.8",
"--weights", "dense",
"--test", "lab",
// "--orders", "2",
"/Desktop/annotations.txt"
});
I am planning to load this model and use it for tagging. I am using this code.
public static void main(String[] args) throws Exception {
//DOCS http://mallet.cs.umass.edu/classifier-devel.php
Instance instance = getMyInstance();
Classifier classifier = loadClassifier(Paths.get("/Desktop/crfmodel").toFile());
Labeling labeling = classifier.classify(instance).getLabeling();
Label l = labeling.getBestLabel();
System.out.print(instance);
System.out.println(l);
}
private static Classifier loadClassifier(File serializedFile)
throws FileNotFoundException, IOException, ClassNotFoundException {
ObjectInputStream ois = new ObjectInputStream (new FileInputStream(serializedFile));
Classifier crf = (Classifier) ois.readObject();
ois.close();
return crf;
}
When I try to do the above I get the following error
Exception in thread "main" java.lang.ClassCastException: cc.mallet.fst.CRF cannot be cast to cc.mallet.classify.Classifier
at TagClassifier.loadClassifier(TagClassifier.java:77)
at TagClassifier.main(TagClassifier.java:64)
The error is happening in line
Classifier crf = (Classifier) ois.readObject();
May I know why this is happening. Also, if there is a correct documented way to label an input using a trained model, can you please share any links/documentation? Thank you very much in advance!!!