crf.addFullyConnectedStatesForLabels(); CRFTrainerByLabelLikelihood crft = new CRFTrainerByLabelLikelihood(crf); crft.setUseSparseWeights(useSparseWeights); if (testValueAndGradient) { Optimizable.ByGradientValue minable = crft
crf.addFullyConnectedStatesForLabels(); CRFTrainerByLabelLikelihood crft = new CRFTrainerByLabelLikelihood(crf); crft.setUseSparseWeights(useSparseWeights); if (testValueAndGradient) { Optimizable.ByGradientValue minable = crft
crft.setUseSparseWeights(false); crft.setUseSomeUnsupportedTrick(false); crft.setUseSparseWeights(true); crft.setUseSomeUnsupportedTrick(true); crft.setUseSparseWeights(true); crft.setUseSomeUnsupportedTrick(false);
crft.setUseSparseWeights(false);
crft.setUseSparseWeights(false); crft.setUseSomeUnsupportedTrick(false); crft.setUseSparseWeights(true); crft.setUseSomeUnsupportedTrick(true); crft.setUseSparseWeights(true); crft.setUseSomeUnsupportedTrick(false);
crft.setUseSparseWeights(false); crft.setUseSomeUnsupportedTrick(false); crft.setUseSparseWeights(true); crft.setUseSomeUnsupportedTrick(true); crft.setUseSparseWeights(true); crft.setUseSomeUnsupportedTrick(false);
public void testTokenAccuracy() { Pipe p = makeSpacePredictionPipe(); InstanceList instances = new InstanceList(p); instances.addThruPipe(new ArrayIterator(data)); InstanceList[] lists = instances.split(new Random(777), new double[] { .5, .5 }); CRF crf = new CRF(p.getDataAlphabet(), p.getTargetAlphabet()); crf.addFullyConnectedStatesForLabels(); CRFTrainerByLabelLikelihood crft = new CRFTrainerByLabelLikelihood(crf); crft.setUseSparseWeights(true); crft.trainIncremental(lists[0]); TokenAccuracyEvaluator eval = new TokenAccuracyEvaluator(lists, new String[] { "Train", "Test" }); eval.evaluateInstanceList(crft, lists[1], "Test"); assertEquals(0.9409, eval.getAccuracy("Test"), 0.001); }
public void testDenseFeatureSelection() { Pipe p = makeSpacePredictionPipe(); InstanceList instances = new InstanceList(p); instances.addThruPipe(new ArrayIterator(data)); // Test that dense observations wights aren't added for // "default-feature" edges. CRF crf1 = new CRF(p, null); crf1.addOrderNStates(instances, new int[] { 0 }, null, "start", null, null, true); CRFTrainerByLabelLikelihood crft1 = new CRFTrainerByLabelLikelihood( crf1); crft1.setUseSparseWeights(false); crft1.train(instances, 1); // Set weights dimension int nParams1 = crft1.getOptimizableCRF(instances).getNumParameters(); CRF crf2 = new CRF(p, null); crf2.addOrderNStates(instances, new int[] { 0, 1 }, new boolean[] { false, true }, "start", null, null, true); CRFTrainerByLabelLikelihood crft2 = new CRFTrainerByLabelLikelihood( crf2); crft2.setUseSparseWeights(false); crft2.train(instances, 1); // Set weights dimension int nParams2 = crft2.getOptimizableCRF(instances).getNumParameters(); assertEquals(nParams2, nParams1 + 4); }
public void testDenseFeatureSelection() { Pipe p = makeSpacePredictionPipe(); InstanceList instances = new InstanceList(p); instances.addThruPipe(new ArrayIterator(data)); // Test that dense observations wights aren't added for // "default-feature" edges. CRF crf1 = new CRF(p, null); crf1.addOrderNStates(instances, new int[] { 0 }, null, "start", null, null, true); CRFTrainerByLabelLikelihood crft1 = new CRFTrainerByLabelLikelihood( crf1); crft1.setUseSparseWeights(false); crft1.train(instances, 1); // Set weights dimension int nParams1 = crft1.getOptimizableCRF(instances).getNumParameters(); CRF crf2 = new CRF(p, null); crf2.addOrderNStates(instances, new int[] { 0, 1 }, new boolean[] { false, true }, "start", null, null, true); CRFTrainerByLabelLikelihood crft2 = new CRFTrainerByLabelLikelihood( crf2); crft2.setUseSparseWeights(false); crft2.train(instances, 1); // Set weights dimension int nParams2 = crft2.getOptimizableCRF(instances).getNumParameters(); assertEquals(nParams2, nParams1 + 4); }
public void testTokenAccuracy() { Pipe p = makeSpacePredictionPipe(); InstanceList instances = new InstanceList(p); instances.addThruPipe(new ArrayIterator(data)); InstanceList[] lists = instances.split(new Random(777), new double[] { .5, .5 }); CRF crf = new CRF(p.getDataAlphabet(), p.getTargetAlphabet()); crf.addFullyConnectedStatesForLabels(); CRFTrainerByLabelLikelihood crft = new CRFTrainerByLabelLikelihood(crf); crft.setUseSparseWeights(true); crft.trainIncremental(lists[0]); TokenAccuracyEvaluator eval = new TokenAccuracyEvaluator(lists, new String[] { "Train", "Test" }); eval.evaluateInstanceList(crft, lists[1], "Test"); assertEquals(0.9409, eval.getAccuracy("Test"), 0.001); }