training.addThruPipe(new ArrayIterator(data)); // This used to be
// MEMM.data, but I
// don't know why -akm
// 12/2007
CRF crf = new CRF(p, null);
crf.addFullyConnectedStatesForLabels();
CRFTrainerByLabelLikelihood crft = new CRFTrainerByLabelLikelihood(crf);
crft.trainIncremental(training);
// Check that the notstart state is used at test time
Sequence input = (Sequence) training.get(0).getData();
Sequence output = new MaxLatticeDefault(crf, input)
.bestOutputSequence();
boolean notstartFound = false;
for (int i = 0; i < output.size(); i++) {
if (output.get(i).toString().equals("notstart")) {
notstartFound = true;
}
}
System.err.println(output.toString());
assertTrue(notstartFound);
// Now add -infinite weight onto a transition, and make sure that it's
// honored.
CRF.State state = crf.getState("notstart");
int widx = crf.getWeightsIndex("BadBad");
int numFeatures = crf.getInputAlphabet().size();
SparseVector w = new SparseVector(new double[numFeatures]);
w.setAll(Double.NEGATIVE_INFINITY);
crf.setWeights(widx, w);
state.addWeight(0, "BadBad");
state.addWeight(1, "BadBad");
// Verify that this effectively prevents the notstart state from being