当前位置: 首页>>代码示例>>Java>>正文


Java CRFTrainerByLabelLikelihood.trainIncremental方法代码示例

本文整理汇总了Java中cc.mallet.fst.CRFTrainerByLabelLikelihood.trainIncremental方法的典型用法代码示例。如果您正苦于以下问题:Java CRFTrainerByLabelLikelihood.trainIncremental方法的具体用法?Java CRFTrainerByLabelLikelihood.trainIncremental怎么用?Java CRFTrainerByLabelLikelihood.trainIncremental使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cc.mallet.fst.CRFTrainerByLabelLikelihood的用法示例。


在下文中一共展示了CRFTrainerByLabelLikelihood.trainIncremental方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testTokenAccuracy

import cc.mallet.fst.CRFTrainerByLabelLikelihood; //导入方法依赖的package包/类
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);

}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:23,代码来源:TestCRF.java

示例2: testSpaceViewer

import cc.mallet.fst.CRFTrainerByLabelLikelihood; //导入方法依赖的package包/类
public void testSpaceViewer () throws IOException
{
  Pipe pipe = TestMEMM.makeSpacePredictionPipe ();
  String[] data0 = { TestCRF.data[0] };
  String[] data1 = { TestCRF.data[1] };

  InstanceList training = new InstanceList (pipe);
  training.addThruPipe (new ArrayIterator (data0));
  InstanceList testing = new InstanceList (pipe);
  testing.addThruPipe (new ArrayIterator (data1));

  CRF crf = new CRF (pipe, null);
  crf.addFullyConnectedStatesForLabels ();
  CRFTrainerByLabelLikelihood crft = new CRFTrainerByLabelLikelihood (crf);
  crft.trainIncremental (training);

  CRFExtractor extor = TestLatticeViewer.hackCrfExtor (crf);
  Extraction extraction = extor.extract (new ArrayIterator (data1));

  if (!outputDir.exists ()) outputDir.mkdir ();
  DocumentViewer.writeExtraction (outputDir, extraction);
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:23,代码来源:TestDocumentViewer.java

示例3: ignoretestTokenAccuracy

import cc.mallet.fst.CRFTrainerByLabelLikelihood; //导入方法依赖的package包/类
public void ignoretestTokenAccuracy() {
	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);

}
 
开发者ID:cmoen,项目名称:mallet,代码行数:23,代码来源:TestCRF.java

示例4: ignoretestSpaceViewer

import cc.mallet.fst.CRFTrainerByLabelLikelihood; //导入方法依赖的package包/类
public void ignoretestSpaceViewer () throws IOException
{
  Pipe pipe = TestMEMM.makeSpacePredictionPipe ();
  String[] data0 = { TestCRF.data[0] };
  String[] data1 = { TestCRF.data[1] };

  InstanceList training = new InstanceList (pipe);
  training.addThruPipe (new ArrayIterator (data0));
  InstanceList testing = new InstanceList (pipe);
  testing.addThruPipe (new ArrayIterator (data1));

  CRF crf = new CRF (pipe, null);
  crf.addFullyConnectedStatesForLabels ();
  CRFTrainerByLabelLikelihood crft = new CRFTrainerByLabelLikelihood (crf);
  crft.trainIncremental (training);

  CRFExtractor extor = TestLatticeViewer.hackCrfExtor (crf);
  Extraction extraction = extor.extract (new ArrayIterator (data1));

  if (!outputDir.exists ()) outputDir.mkdir ();
  DocumentViewer.writeExtraction (outputDir, extraction);
}
 
开发者ID:cmoen,项目名称:mallet,代码行数:23,代码来源:TestDocumentViewer.java

示例5: testSpaceViewer

import cc.mallet.fst.CRFTrainerByLabelLikelihood; //导入方法依赖的package包/类
public void testSpaceViewer () throws FileNotFoundException
{
  Pipe pipe = TestMEMM.makeSpacePredictionPipe ();
  String[] data0 = { TestCRF.data[0] };
  String[] data1 = { TestCRF.data[1] };

  InstanceList training = new InstanceList (pipe);
  training.addThruPipe (new ArrayIterator (data0));
  InstanceList testing = new InstanceList (pipe);
  testing.addThruPipe (new ArrayIterator (data1));

  CRF crf = new CRF (pipe, null);
  crf.addFullyConnectedStatesForLabels ();
  CRFTrainerByLabelLikelihood crft = new CRFTrainerByLabelLikelihood (crf);
  crft.trainIncremental (training);

  CRFExtractor extor = hackCrfExtor (crf);
  Extraction extration = extor.extract (new ArrayIterator (data1));

  PrintStream out = new PrintStream (new FileOutputStream (htmlFile));
  LatticeViewer.extraction2html (extration, extor, out);
  out.close();

  out = new PrintStream (new FileOutputStream (latticeFile));
  LatticeViewer.extraction2html (extration, extor, out, true);
  out.close();


}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:30,代码来源:TestLatticeViewer.java

示例6: ignoretestSpaceViewer

import cc.mallet.fst.CRFTrainerByLabelLikelihood; //导入方法依赖的package包/类
public void ignoretestSpaceViewer () throws FileNotFoundException
{
  Pipe pipe = TestMEMM.makeSpacePredictionPipe ();
  String[] data0 = { TestCRF.data[0] };
  String[] data1 = { TestCRF.data[1] };

  InstanceList training = new InstanceList (pipe);
  training.addThruPipe (new ArrayIterator (data0));
  InstanceList testing = new InstanceList (pipe);
  testing.addThruPipe (new ArrayIterator (data1));

  CRF crf = new CRF (pipe, null);
  crf.addFullyConnectedStatesForLabels ();
  CRFTrainerByLabelLikelihood crft = new CRFTrainerByLabelLikelihood (crf);
  crft.trainIncremental (training);

  CRFExtractor extor = hackCrfExtor (crf);
  Extraction extration = extor.extract (new ArrayIterator (data1));

  PrintStream out = new PrintStream (new FileOutputStream (htmlFile));
  LatticeViewer.extraction2html (extration, extor, out);
  out.close();

  out = new PrintStream (new FileOutputStream (latticeFile));
  LatticeViewer.extraction2html (extration, extor, out, true);
  out.close();


}
 
开发者ID:cmoen,项目名称:mallet,代码行数:30,代码来源:TestLatticeViewer.java

示例7: testFrozenWeights

import cc.mallet.fst.CRFTrainerByLabelLikelihood; //导入方法依赖的package包/类
public void testFrozenWeights() {
	Pipe p = makeSpacePredictionPipe();

	InstanceList instances = new InstanceList(p);
	instances.addThruPipe(new ArrayIterator(data));

	CRF crf1 = new CRF(p.getDataAlphabet(), p.getTargetAlphabet());
	crf1.addFullyConnectedStatesForLabels();
	CRFTrainerByLabelLikelihood crft1 = new CRFTrainerByLabelLikelihood(
			crf1);
	crft1.trainIncremental(instances);

	CRF crf2 = new CRF(p.getDataAlphabet(), p.getTargetAlphabet());
	crf2.addFullyConnectedStatesForLabels();
	// Freeze some weights, before training
	for (int i = 0; i < crf2.getWeights().length; i += 2)
		crf2.freezeWeights(i);
	CRFTrainerByLabelLikelihood crft2 = new CRFTrainerByLabelLikelihood(
			crf2);
	crft2.trainIncremental(instances);

	SparseVector[] w = crf2.getWeights();
	double[] b = crf2.getDefaultWeights();
	for (int i = 0; i < w.length; i += 2) {
		assertEquals(0.0, b[i], 1e-10);
		for (int loc = 0; loc < w[i].numLocations(); loc++) {
			assertEquals(0.0, w[i].valueAtLocation(loc), 1e-10);
		}
	}

	// Check that the frozen weights has worse likelihood
	Optimizable.ByGradientValue optable1 = crft1
			.getOptimizableCRF(instances);
	Optimizable.ByGradientValue optable2 = crft2
			.getOptimizableCRF(instances);
	double val1 = optable1.getValue();
	double val2 = optable2.getValue();
	assertTrue(
			"Error: Freezing weights does not harm log-likelihood!  Full "
					+ val1 + ", Frozen " + val2, val1 > val2);
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:42,代码来源:TestCRF.java

示例8: testStateAddWeights

import cc.mallet.fst.CRFTrainerByLabelLikelihood; //导入方法依赖的package包/类
public void testStateAddWeights() {
	Pipe p = makeSpacePredictionPipe(); // This used to be
	// MEMM.makeSpacePredictionPipe(),
	// but I don't know why -akm 12/2007
	InstanceList training = new InstanceList(p);
	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
	// used
	output = new MaxLatticeDefault(crf, input).bestOutputSequence();
	notstartFound = false;
	for (int i = 0; i < output.size() - 1; i++) {
		if (output.get(i).toString().equals("notstart")) {
			notstartFound = true;
		}
	}
	assertTrue(!notstartFound);
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:53,代码来源:TestCRF.java


注:本文中的cc.mallet.fst.CRFTrainerByLabelLikelihood.trainIncremental方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。