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


Java LabeledInstance类代码示例

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


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

示例1: main

import edu.berkeley.nlp.classify.LabeledInstance; //导入依赖的package包/类
/**
 * @param args
 */
public static void main(String[] args) {
	// create datums
	int k = 2;
	double[] dummyWeights = DoubleArrays.constantArray(1.0 / k, k);
	LabeledInstance<WordInSentence, String> datum1 = new LabeledInstance<WordInSentence, String>(
			"NN", new WordInSentence("The cats died", 1));
	LabeledInstance<WordInSentence, String> datum2 = new LabeledInstance<WordInSentence, String>(
			"VB", new WordInSentence("I killing the cat", 1));
	LabeledInstance<WordInSentence, String> datum3 = new LabeledInstance<WordInSentence, String>(
			"NN", new WordInSentence("A cats killed me", 1));
	LabeledInstance<WordInSentence, String> datum4 = new LabeledInstance<WordInSentence, String>(
			"NN", new WordInSentence("The cats lived", 1));

	// create training set
	List<LabeledInstance<WordInSentence, String>> trainingData = new ArrayList<LabeledInstance<WordInSentence, String>>();
	trainingData.add(datum1);
	trainingData.add(datum2);
	trainingData.add(datum3);

	// create test set
	List<LabeledInstance<WordInSentence, String>> testData = new ArrayList<LabeledInstance<WordInSentence, String>>();
	testData.add(datum4);

	// build classifier
	LexiconFeatureExtractor featureExtractor = new LexiconFeatureExtractor();
	MaximumEntropyClassifier.Factory<WordInSentence, LexiconFeature, String> maximumEntropyClassifierFactory = new MaximumEntropyClassifier.Factory<WordInSentence, LexiconFeature, String>(
			1.0, 20, featureExtractor);
	MaximumEntropyClassifier<WordInSentence, LexiconFeature, String> maximumEntropyClassifier = (MaximumEntropyClassifier<WordInSentence, LexiconFeature, String>) maximumEntropyClassifierFactory
			.trainClassifier(trainingData);
	System.out.println("Probabilities on test instance: "
			+ maximumEntropyClassifier.getProbabilities(datum4.getInput()));

}
 
开发者ID:text-machine-lab,项目名称:CliRel,代码行数:37,代码来源:LexiconTester.java


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