本文整理汇总了Java中opennlp.tools.chunker.ChunkerME.train方法的典型用法代码示例。如果您正苦于以下问题:Java ChunkerME.train方法的具体用法?Java ChunkerME.train怎么用?Java ChunkerME.train使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类opennlp.tools.chunker.ChunkerME
的用法示例。
在下文中一共展示了ChunkerME.train方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: trainChunker
import opennlp.tools.chunker.ChunkerME; //导入方法依赖的package包/类
public static void trainChunker(final String inResource, String outFile) throws IOException {
InputStreamFactory inputStreamFactory = new InputStreamFactory() {
@Override
public InputStream createInputStream() throws IOException {
return Trainer.class.getResourceAsStream(inResource);
}
};
ChunkSampleStream samples = new ChunkSampleStream(new PlainTextByLineStream(inputStreamFactory, StandardCharsets.UTF_8));
TrainingParameters trainingParameters = new TrainingParameters();
trainingParameters.put(TrainingParameters.ITERATIONS_PARAM, "70");
trainingParameters.put(TrainingParameters.CUTOFF_PARAM, "1");
ChunkerFactory chunkerFactory = ChunkerFactory.create(null);
ChunkerModel model = ChunkerME.train("en", samples, trainingParameters, chunkerFactory);
//ChunkerME.train("en", samples, 1, 70);
samples.close();
FileOutputStream out = new FileOutputStream(outFile);
model.serialize(out);
out.close();
}
示例2: train
import opennlp.tools.chunker.ChunkerME; //导入方法依赖的package包/类
public final ChunkerModel train(final TrainingParameters params) {
// features
if (getChunkerFactory() == null) {
throw new IllegalStateException(
"Classes derived from AbstractTrainer must "
+ " create a ChunkerFactory features!");
}
// training model
ChunkerModel trainedModel = null;
ChunkerEvaluator chunkerEvaluator = null;
try {
trainedModel = ChunkerME.train(lang, trainSamples, params,
getChunkerFactory());
final Chunker chunker = new ChunkerME(trainedModel);
chunkerEvaluator = new ChunkerEvaluator(chunker);
chunkerEvaluator.evaluate(this.testSamples);
} catch (IOException e) {
System.err.println("IO error while loading traing and test sets!");
e.printStackTrace();
System.exit(1);
}
System.out.println("Final result: " + chunkerEvaluator.getFMeasure());
return trainedModel;
}