• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java MaxLatticeDefault类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



MaxLatticeDefault类属于cc.mallet.fst包,在下文中一共展示了MaxLatticeDefault类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: apply

import cc.mallet.fst.MaxLatticeDefault; //导入依赖的package包/类
/**
 * Apply a transducer to an input sequence to produce the k highest-scoring
 * output sequences.
 *
 * @param model the <code>Transducer</code>
 * @param input the input sequence
 * @param k the number of answers to return
 * @return array of the k highest-scoring output sequences
 */
public static Sequence[] apply(Transducer model, Sequence input, int k)
{
  Sequence[] answers;
  if (k == 1) {
    answers = new Sequence[1];
    answers[0] = model.transduce (input);
  }
  else {
    MaxLatticeDefault lattice =
            new MaxLatticeDefault (model, input, null, cacheSizeOption.value());

    answers = lattice.bestOutputSequences(k).toArray(new Sequence[0]);
  }
  return answers;
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:25,代码来源:SimpleTaggerWithConstraints.java


示例2: infoForDoc

import cc.mallet.fst.MaxLatticeDefault; //导入依赖的package包/类
private static ExtorInfo infoForDoc (String doc, String desc, String idx, DocumentExtraction docextr,
                                         CRFExtractor extor, boolean showLattice)
  {
//    Instance c2 = new Instance (doc, null, null, null, extor.getTokenizationPipe ());
//    TokenSequence input = (TokenSequence) c2.getData ();
    TokenSequence input = (TokenSequence) docextr.getInput (); 
    LabelSequence target = docextr.getTarget ();
    Sequence predicted = docextr.getPredictedLabels ();

    ExtorInfo info = new ExtorInfo (input, predicted, target, desc, idx);

    if (showLattice == true) {
      CRF crf = extor.getCrf();
      // xxx perhaps the next two lines could be a transducer method???
      Instance carrier = extor.getFeaturePipe().pipe(new Instance (input, null, null, null));
      info.fvs = (FeatureVectorSequence) carrier.getData ();
      info.lattice = new MaxLatticeDefault (crf, (Sequence) carrier.getData(), null);
      info.bestStates = info.lattice.bestOutputSequence();
    }

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


示例3: test

import cc.mallet.fst.MaxLatticeDefault; //导入依赖的package包/类
/**
 * 
 * @param num_best
 * @return
 */
@SuppressWarnings("unchecked")
public List<CRFResult> test(Integer num_best) {
	List<CRFResult> groups = new ArrayList<CRFResult>();
	for (Instance instance : this.test_data) {
		FeatureVectorSequence input = (FeatureVectorSequence) instance.getData();
		List<Sequence<Object>> seqs = null;
		if (num_best > 1)
			seqs = new MaxLatticeDefault(model, input, null, 100000).bestOutputSequences(num_best);
		else
			seqs = Arrays.asList((Sequence<Object>) model.transduce(input));
		if (isError(seqs, input))
			System.err.println("[ERROR] Error output at " + input);

		List<List<String>> outputs = new ArrayList<List<String>>();
		for (Sequence<Object> seq : seqs)
			outputs.add(toTagStrings(seq));

		groups.add(new CRFResult(input, outputs));
	}

	return groups;
}
 
开发者ID:hakchul77,项目名称:irnlp_toolkit,代码行数:28,代码来源:MalletWrapper.java


示例4: getStatistics

import cc.mallet.fst.MaxLatticeDefault; //导入依赖的package包/类
private void getStatistics(CRF crf, Instance inst,
		Map<Instance, Double> entropyMap, Map<Instance, Double> probMap,
		boolean setTarget) {
	FeatureVectorSequence input = (FeatureVectorSequence) inst.getData();
	MaxLatticeDefault maxLattice = new MaxLatticeDefault(crf, input);
	Sequence output = maxLattice.bestOutputSequence();
	double labeled = new SumLatticeDefault(crf, input, output)
			.getTotalWeight();
	SumLattice lattice = new SumLatticeDefault(crf, input, true);
	double unlabeled = lattice.getTotalWeight();
	EntropyLattice entropyLattice = new EntropyLattice(input,
			lattice.getGammas(), lattice.getXis(), crf, null, 1);
	double entropy = -entropyLattice.getEntropy();
	double prob = Math.exp(labeled - unlabeled);
	entropyMap.put(inst, entropy);
	probMap.put(inst, prob);
	if (setTarget) {
		inst.unLock();
		int n = output.size();
		LabelSequence seq = new LabelSequence(
				(LabelAlphabet) crf.getOutputAlphabet(), n);
		for (int i = 0; i < output.size(); i++) {
			seq.add(output.get(i));
		}
		inst.setTarget(seq);
		inst.lock();
	}
}
 
开发者ID:siqil,项目名称:udaner,代码行数:29,代码来源:CRFTrainerByBootstrapping.java


示例5: testViterbi

import cc.mallet.fst.MaxLatticeDefault; //导入依赖的package包/类
public void testViterbi ()
{
	double weight = new MaxLatticeDefault (transducer, seq).bestWeight();
	System.out.println ("weight = "+weight);
	assertTrue (weight == seqWeight);
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:7,代码来源:TestFeatureTransducer.java


示例6: testMaxLattice

import cc.mallet.fst.MaxLatticeDefault; //导入依赖的package包/类
public void testMaxLattice() {
	int inputVocabSize = 1;
	int numStates = 2;
	Alphabet inputAlphabet = new Alphabet();
	for (int i = 0; i < inputVocabSize; i++)
		inputAlphabet.lookupIndex("feature" + i);
	Alphabet outputAlphabet = new Alphabet();

	CRF crf = new CRF(inputAlphabet, outputAlphabet);

	String[] stateNames = new String[numStates];
	for (int i = 0; i < numStates; i++)
		stateNames[i] = "state" + i;
	crf.addFullyConnectedStates(stateNames);

	crf.setWeightsDimensionDensely();
	crf.getState(0).setInitialWeight(1.0);
	crf.getState(1).setInitialWeight(Transducer.IMPOSSIBLE_WEIGHT);
	crf.getState(0).setFinalWeight(0.0);
	crf.getState(1).setFinalWeight(0.0);
	crf.setParameter(0, 0, 0, Transducer.IMPOSSIBLE_WEIGHT); // state0
	// self-transition
	crf.setParameter(0, 1, 0, 1.0); // state0->state1
	crf.setParameter(1, 1, 0, 1.0); // state1 self-transition
	crf.setParameter(1, 0, 0, Transducer.IMPOSSIBLE_WEIGHT); // state1->state0

	FeatureVectorSequence fvs = new FeatureVectorSequence(
			new FeatureVector[] {
					new FeatureVector((Alphabet) crf.getInputAlphabet(),
							new double[] { 1 }),
					new FeatureVector((Alphabet) crf.getInputAlphabet(),
							new double[] { 1 }),
					new FeatureVector((Alphabet) crf.getInputAlphabet(),
							new double[] { 1 }), });

	MaxLattice lattice = new MaxLatticeDefault(crf, fvs);
	Sequence<Transducer.State> viterbiPath = lattice.bestStateSequence();
	// We start in state0
	assertTrue(viterbiPath.get(0) == crf.getState(0));
	// We go to state1
	assertTrue(viterbiPath.get(1) == crf.getState(1));
	// And on through a self-transition to state1 again
	assertTrue(viterbiPath.get(2) == crf.getState(1));
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:45,代码来源:TestCRF.java


示例7: testStateAddWeights

import cc.mallet.fst.MaxLatticeDefault; //导入依赖的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


示例8: bestSequences

import cc.mallet.fst.MaxLatticeDefault; //导入依赖的package包/类
public opennlp.tools.util.Sequence[] bestSequences(int numSequences,
    T[] sequence, Object[] additionalContext,
    BeamSearchContextGenerator<T> cg, SequenceValidator<T> validator) {

  // TODO: CRF.getInputAlphabet
  Alphabet dataAlphabet = model.getInputPipe().getAlphabet();
  
  FeatureVector featureVectors[] = new FeatureVector[sequence.length];
  
  // TODO:: The feature generator needs to get the detected sequence in the end
  // to update the adaptive data!
  String prior[] = new String[sequence.length];
  Arrays.fill(prior, "s"); // <- HACK, this will degrade performance!
  
  // TODO: Put together a feature generator which doesn't fail if outcomes is null!
  for (int i = 0; i < sequence.length; i++) {
    String features[] = cg.getContext(i, sequence, null, additionalContext);
    
    List<Integer> malletFeatureList = new ArrayList<>(features.length);
    
    for (int featureIndex = 0; featureIndex < features.length; featureIndex++) {
      if (dataAlphabet.contains(features[featureIndex])) {
        malletFeatureList.add(dataAlphabet.lookupIndex(features[featureIndex]));
      }
    }

    int malletFeatures[] = new int[malletFeatureList.size()];
    for (int k = 0; k < malletFeatureList.size(); k++) {
      malletFeatures[k] = malletFeatureList.get(k);
    }
    
    // Note: Might contain a feature more than once ... will that work ?!
    featureVectors[i] = new FeatureVector(dataAlphabet, malletFeatures);
  }
  
  FeatureVectorSequence malletSequence = new FeatureVectorSequence(featureVectors);
  
  Sequence[] answers = null;
  if (numSequences == 1) {
    answers = new Sequence[1];
    answers[0] = model.transduce(malletSequence);
  } else {
    MaxLatticeDefault lattice = new MaxLatticeDefault(model, malletSequence, null, 3);

    answers = lattice.bestOutputSequences(numSequences).toArray(new Sequence[0]);
  }

  opennlp.tools.util.Sequence[] outcomeSequences = new opennlp.tools.util.Sequence[answers.length];
  
  for (int i = 0; i < answers.length; i++) {
    Sequence seq = answers[i];
    
    List<String> outcomes = new ArrayList<>(seq.size());
    
    for (int j = 0; j < seq.size(); j++) {
      outcomes.add(seq.get(j).toString());
    }
    
    outcomeSequences[i] = new opennlp.tools.util.Sequence(outcomes);
  }
  
  return outcomeSequences;
}
 
开发者ID:kottmann,项目名称:opennlp-mallet-addon,代码行数:64,代码来源:TransducerModel.java


示例9: ignoretestViterbi

import cc.mallet.fst.MaxLatticeDefault; //导入依赖的package包/类
public void ignoretestViterbi ()
{
	double weight = new MaxLatticeDefault (transducer, seq).bestWeight();
	System.out.println ("weight = "+weight);
	assertTrue (weight == seqWeight);
}
 
开发者ID:cmoen,项目名称:mallet,代码行数:7,代码来源:TestFeatureTransducer.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java SecretResolverFactory类代码示例发布时间:2022-05-22
下一篇:
Java Window类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap