InstanceList ilist = new InstanceList(new Noop(inputAlphabet,
outputAlphabet));
ilist.add(fvs, ss, null, null);
crf.addFullyConnectedStates(stateNames);
CRFTrainerByLabelLikelihood crft = new CRFTrainerByLabelLikelihood(crf);
crft.setUseSparseWeights(false);
if (useSave) {
try {
ObjectOutputStream oos = new ObjectOutputStream(
new FileOutputStream(f));
oos.writeObject(crf);
oos.close();
} catch (IOException e) {
System.err.println("Exception writing file: " + e);
}
System.err.println("Wrote out CRF");
System.err.println("CRF parameters. hyperbolicPriorSlope: "
+ crft.getUseHyperbolicPriorSlope()
+ ". hyperbolicPriorSharpness: "
+ crft.getUseHyperbolicPriorSharpness()
+ ". gaussianPriorVariance: "
+ crft.getGaussianPriorVariance());
// And read it back in
crf = null;
try {
ObjectInputStream ois = new ObjectInputStream(
new FileInputStream(f));
crf = (CRF) ois.readObject();
ois.close();
} catch (IOException e) {
System.err.println("Exception reading file: " + e);
} catch (ClassNotFoundException cnfe) {
System.err.println("Cound not find class reading in object: "
+ cnfe);
}
System.err.println("Read in CRF.");
System.err.println("CRF parameters. hyperbolicPriorSlope: "
+ crft.getUseHyperbolicPriorSlope()
+ ". hyperbolicPriorSharpness: "
+ crft.getUseHyperbolicPriorSharpness()
+ ". gaussianPriorVariance: "
+ crft.getGaussianPriorVariance());
try {
ObjectOutputStream oos = new ObjectOutputStream(
new FileOutputStream(f2));
oos.writeObject(crf);
oos.close();
} catch (IOException e) {
System.err.println("Exception writing file: " + e);
}
System.err.println("Wrote out CRF");
crf = saveCRF;
}
Optimizable.ByGradientValue mcrf = crft.getOptimizableCRF(ilist);
double unconstrainedWeight = new SumLatticeDefault(crf, fvs)
.getTotalWeight();
double constrainedWeight = new SumLatticeDefault(crf, fvs, ss)
.getTotalWeight();
double optimizableValue = 0, gradientNorm = 0;