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

Java MaxentModel类代码示例

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

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



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

示例1: train

import opennlp.tools.ml.model.MaxentModel; //导入依赖的package包/类
public static AgeClassifyModel train(String languageCode,
       ObjectStream<AuthorAgeSample> samples, TrainingParameters trainParams,
      	AgeClassifyFactory factory) throws IOException {

Map<String, String> entries = new HashMap<String, String>();

MaxentModel ageModel = null;

TrainerType trainerType = AgeClassifyTrainerFactory
    .getTrainerType(trainParams.getSettings());

ObjectStream<Event> eventStream = new AgeClassifyEventStream(samples,
    factory.createContextGenerator());

EventTrainer trainer = AgeClassifyTrainerFactory
    .getEventTrainer(trainParams.getSettings(), entries);
ageModel = trainer.train(eventStream);

Map<String, String> manifestInfoEntries = new HashMap<String, String>();

return new AgeClassifyModel(languageCode, ageModel, manifestInfoEntries,
			    factory);
   }
 
开发者ID:USCDataScience,项目名称:AgePredictor,代码行数:24,代码来源:AgeClassifyME.java


示例2: initialize

import opennlp.tools.ml.model.MaxentModel; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void initialize(UimaContext ctx) throws ResourceInitializationException {
    super.initialize(ctx);
    //
    modelAggregate = modelAggregateHolder.getModel();
    //
    if (sequenceValidatorClassName != null) {
        sequenceValidator = InitializableFactory.create(ctx, sequenceValidatorClassName,
                SequenceValidator.class);
    }
    //
    POSTaggerFactory factory = modelAggregate.getFactory();
    MaxentModel posModel = modelAggregate.getPosModel();
    BeamSearchContextGenerator<Token> contextGen = factory.getContextGenerator();
    beam = new BeamSearch<>(beamSize, contextGen, posModel, sequenceValidator, 0);
}
 
开发者ID:textocat,项目名称:textokit-core,代码行数:18,代码来源:OpenNLPPosTagger.java


示例3: LemmatizerME

import opennlp.tools.ml.model.MaxentModel; //导入依赖的package包/类
/**
 * Initializes the current instance with the provided model and the default
 * beam size of 3.
 * 
 * @param model
 *          the model
 */
public LemmatizerME(LemmatizerModel model) {

  LemmatizerFactory factory = model.getFactory();
  int defaultBeamSize = LemmatizerME.DEFAULT_BEAM_SIZE;
  String beamSizeString = model
      .getManifestProperty(BeamSearch.BEAM_SIZE_PARAMETER);
  if (beamSizeString != null) {
    defaultBeamSize = Integer.parseInt(beamSizeString);
  }

  contextGenerator = factory.getContextGenerator();
  beamSize = defaultBeamSize;

  sequenceValidator = factory.getSequenceValidator();

  if (model.getLemmatizerSequenceModel() != null) {
    this.model = model.getLemmatizerSequenceModel();
  } else {
    this.model = new opennlp.tools.ml.BeamSearch<String>(beamSize,
        (MaxentModel) model.getLemmatizerSequenceModel(), 0);
  }
}
 
开发者ID:ixa-ehu,项目名称:ixa-pipe-pos,代码行数:30,代码来源:LemmatizerME.java


示例4: getLemmatizerSequenceModel

import opennlp.tools.ml.model.MaxentModel; //导入依赖的package包/类
public SequenceClassificationModel<String> getLemmatizerSequenceModel() {

    Properties manifest = (Properties) artifactMap.get(MANIFEST_ENTRY);

    if (artifactMap.get(LEMMATIZER_MODEL_ENTRY_NAME) instanceof MaxentModel) {
      String beamSizeString = manifest.getProperty(BeamSearch.BEAM_SIZE_PARAMETER);

      int beamSize = LemmatizerME.DEFAULT_BEAM_SIZE;
      if (beamSizeString != null) {
        beamSize = Integer.parseInt(beamSizeString);
      }

      return new BeamSearch<>(beamSize, (MaxentModel) artifactMap.get(LEMMATIZER_MODEL_ENTRY_NAME));
    }
    else if (artifactMap.get(LEMMATIZER_MODEL_ENTRY_NAME) instanceof SequenceClassificationModel) {
      return (SequenceClassificationModel) artifactMap.get(LEMMATIZER_MODEL_ENTRY_NAME);
    }
    else {
      return null;
    }
  }
 
开发者ID:ixa-ehu,项目名称:ixa-pipe-pos,代码行数:22,代码来源:LemmatizerModel.java


示例5: ProfilerModel

import opennlp.tools.ml.model.MaxentModel; //导入依赖的package包/类
public ProfilerModel(String languageCode, MaxentModel profilerModel,
  Map<String, String> manifestInfoEntries, ProfilerFactory factory) {
  super(COMPONENT_NAME, languageCode, manifestInfoEntries, factory);

  artifactMap.put(PROFILER_MODEL_ENTRY_NAME, profilerModel);
  checkArtifactMap();
}
 
开发者ID:beylerian,项目名称:profiler,代码行数:8,代码来源:ProfilerModel.java


示例6: POSModel

import opennlp.tools.ml.model.MaxentModel; //导入依赖的package包/类
public POSModel(String languageCode, MaxentModel posModel,
                Map<String, String> manifestInfoEntries, POSTaggerFactory posFactory) {

    super(COMPONENT_NAME, languageCode, manifestInfoEntries, posFactory);

    if (posModel == null)
        throw new IllegalArgumentException("The maxentPosModel param must not be null!");

    artifactMap.put(POS_MODEL_ENTRY_NAME, posModel);
    checkArtifactMap();
}
 
开发者ID:textocat,项目名称:textokit-core,代码行数:12,代码来源:POSModel.java


示例7: validateArtifactMap

import opennlp.tools.ml.model.MaxentModel; //导入依赖的package包/类
@Override
protected void validateArtifactMap() throws InvalidFormatException {
    super.validateArtifactMap();

    if (!(artifactMap.get(POS_MODEL_ENTRY_NAME) instanceof MaxentModel)) {
        throw new InvalidFormatException("POS model is incomplete!");
    }
}
 
开发者ID:textocat,项目名称:textokit-core,代码行数:9,代码来源:POSModel.java


示例8: train

import opennlp.tools.ml.model.MaxentModel; //导入依赖的package包/类
public void train() throws IOException {
    if (languageCode == null) {
        throw new IllegalStateException("languageCode is not provided");
    }
    if (modelOutFile == null) {
        throw new IllegalStateException("model output path is not provided");
    }
    if (trainParams == null) {
        throw new IllegalStateException("training parameters are not set");
    }
    if (sentenceStream == null) {
        throw new IllegalStateException("sentence stream is not configured");
    }
    if (taggerFactory == null) {
        throw new IllegalStateException("tagger factory is not configured");
    }
    Map<String, String> manifestInfoEntries = new HashMap<>();
    BeamSearchContextGenerator<Token> contextGenerator = taggerFactory.getContextGenerator();

    MaxentModel posModel;
    try {
        if (TrainerFactory.TrainerType.EVENT_MODEL_TRAINER.equals(
                TrainerFactory.getTrainerType(trainParams.getSettings()))) {

            ObjectStream<Event> es = new POSTokenEventStream<>(sentenceStream, contextGenerator);
            EventTrainer trainer = TrainerFactory.getEventTrainer(trainParams.getSettings(), manifestInfoEntries);
            posModel = trainer.train(es);
        } else {
            throw new UnsupportedOperationException("Sequence training");
            //POSSampleSequenceStream ss = new POSSampleSequenceStream(samples, contextGenerator);
            // posModel = TrainUtil.train(ss, trainParams.getSettings(), manifestInfoEntries);
        }
    } finally {
        sentenceStream.close();
    }
    POSModel modelAggregate = new POSModel(languageCode,
            posModel, manifestInfoEntries, taggerFactory);
    CmdLineUtil.writeModel("PoS-tagger", modelOutFile, modelAggregate);
}
 
开发者ID:textocat,项目名称:textokit-core,代码行数:40,代码来源:OpenNLPPosTaggerTrainer.java


示例9: LemmatizerModel

import opennlp.tools.ml.model.MaxentModel; //导入依赖的package包/类
public LemmatizerModel(String languageCode, MaxentModel lemmatizerModel, int beamSize,
    Map<String, String> manifestInfoEntries, LemmatizerFactory factory) {
  super(COMPONENT_NAME, languageCode, manifestInfoEntries, factory);
  artifactMap.put(LEMMATIZER_MODEL_ENTRY_NAME, lemmatizerModel);

  Properties manifest = (Properties) artifactMap.get(MANIFEST_ENTRY);
  manifest.put(BeamSearch.BEAM_SIZE_PARAMETER, Integer.toString(beamSize));
  checkArtifactMap();
}
 
开发者ID:ixa-ehu,项目名称:ixa-pipe-pos,代码行数:10,代码来源:LemmatizerModel.java


示例10: doTrain

import opennlp.tools.ml.model.MaxentModel; //导入依赖的package包/类
@Override
public MaxentModel doTrain(DataIndexer indexer) throws IOException {

  List<Double> vy = new ArrayList<Double>();
  List<Feature[]> vx = new ArrayList<Feature[]>();

  // outcomes
  int outcomes[] = indexer.getOutcomeList();

  int max_index = 0;
  
  // For each event ...
  for (int i = 0; i < indexer.getContexts().length; i++) {

    int outcome = outcomes[i];
    vy.add(Double.valueOf(outcome));

    int features[] = indexer.getContexts()[i];

    Feature[] x;
    if (bias >= 0) {
      x = new Feature[features.length + 1];
    } else {
      x = new Feature[features.length];
    }

    // for each feature ...
    for (int fi = 0; fi < features.length; fi++) {
      // TODO: SHOUDL BE indexer.getNumTimesEventsSeen()[i] and not fi !!!
      x[fi] = new FeatureNode(features[fi] + 1, indexer.getNumTimesEventsSeen()[i]);
    } 

    if (features.length > 0) {
      max_index = Math.max(max_index, x[features.length - 1].getIndex());
    }
    
    vx.add(x);
  }

  Problem problem = constructProblem(vy, vx, max_index, bias);
  Parameter parameter = new Parameter(solverType, c, eps, p);
  
  Model liblinearModel = Linear.train(problem, parameter);

  Map<String, Integer> predMap = new HashMap<String, Integer>();
  
  String predLabels[] = indexer.getPredLabels();
  for (int i = 0; i < predLabels.length; i++) {
    predMap.put(predLabels[i], i);
  }
  
  return new LiblinearModel(liblinearModel, indexer.getOutcomeLabels(), predMap);
}
 
开发者ID:apache,项目名称:opennlp-addons,代码行数:54,代码来源:LiblinearTrainer.java


示例11: createModel

import opennlp.tools.ml.model.MaxentModel; //导入依赖的package包/类
public static AgeClassifyModel createModel(String languageCode, String dataIn,
				       String tokenizer, String featureGenerators,
				       TrainingParameters trainParams) throws IOException {

SparkConf conf = new SparkConf().setAppName("AgeClassifySparkTrainer");
JavaSparkContext sc = new JavaSparkContext(conf);

AgeClassifyContextGeneratorWrapper wrapper = new AgeClassifyContextGeneratorWrapper(
    tokenizer, featureGenerators);

JavaRDD<String> data = sc.textFile(dataIn, 8).cache();
JavaRDD<EventWrapper> samples = data.map(new CreateEvents(wrapper)).cache();

/*
JavaRDD<EventWrapper> samples = data.map( 
     new Function<String, EventWrapper>() {
	 public EventWrapper call(String s) {
	     String[] parts = s.split(",");
	     
	     try {
		 if (parts[0] != "-1") {
		     Integer value = Integer.parseInt(parts[0]);
		     
		     String[] text = parts[2].split(" ");
		     return new EventWrapper(value, text);
		 } else {
		     String cat = parts[1];
		     
		     String[] text = parts[2].split(" ");
		     return new EventWrapper(cat, text);
		 }
	     } catch(Exception e) {
		 return null;
	     }
	 }
     });
*/

JavaRDD<EventWrapper> validSamples = samples.filter(
           new Function<EventWrapper, Boolean>() {
	@Override
	public Boolean call(EventWrapper s) { return s != null; }
    }).cache();

//ObjectStream<Event> eventStream = EventStreamUtil.createEventStream(samples);	
ObjectStream<Event> eventStream = EventStreamUtil.createEventStream(validSamples.collect());

Map<String, String> entries = new HashMap<String, String>();
				       					    
EventTrainer trainer = AgeClassifyTrainerFactory
           .getEventTrainer(trainParams.getSettings(), entries);
       MaxentModel ageModel = trainer.train(eventStream);

samples.unpersist();
data.unpersist();

sc.stop();

Map<String, String> manifestInfoEntries = new HashMap<String, String>();

AgeClassifyFactory factory = AgeClassifyFactory.create("AgeClassifyFactory", 
           wrapper.getTokenizer(), wrapper.getFeatureGenerators());
return new AgeClassifyModel(languageCode, ageModel, manifestInfoEntries, factory);
   }
 
开发者ID:USCDataScience,项目名称:AgePredictor,代码行数:65,代码来源:AgeClassifySparkTrainer.java


示例12: AgeClassifyModel

import opennlp.tools.ml.model.MaxentModel; //导入依赖的package包/类
public AgeClassifyModel(String languageCode, MaxentModel ageClassifyModel,
		    Map<String, String> manifestInfoEntries, AgeClassifyFactory factory) {
super(COMPONENT_NAME, languageCode, manifestInfoEntries, factory);
artifactMap.put(AUTHORAGE_MODEL_ENTRY_NAME, ageClassifyModel);
checkArtifactMap();
   }
 
开发者ID:USCDataScience,项目名称:AgePredictor,代码行数:7,代码来源:AgeClassifyModel.java


示例13: getMaxentModel

import opennlp.tools.ml.model.MaxentModel; //导入依赖的package包/类
public MaxentModel getMaxentModel() {
return (MaxentModel) artifactMap.get(AUTHORAGE_MODEL_ENTRY_NAME);
   }
 
开发者ID:USCDataScience,项目名称:AgePredictor,代码行数:4,代码来源:AgeClassifyModel.java


示例14: getMaxentModel

import opennlp.tools.ml.model.MaxentModel; //导入依赖的package包/类
public MaxentModel getMaxentModel() {
  return (MaxentModel) artifactMap.get(PROFILER_MODEL_ENTRY_NAME);
}
 
开发者ID:beylerian,项目名称:profiler,代码行数:4,代码来源:ProfilerModel.java


示例15: getPosModel

import opennlp.tools.ml.model.MaxentModel; //导入依赖的package包/类
public MaxentModel getPosModel() {
    return (MaxentModel) artifactMap.get(POS_MODEL_ENTRY_NAME);
}
 
开发者ID:textocat,项目名称:textokit-core,代码行数:4,代码来源:POSModel.java


示例16: doTrain

import opennlp.tools.ml.model.MaxentModel; //导入依赖的package包/类
public MaxentModel doTrain(DataIndexer indexer) throws IOException {
int iterations = getIterations();

MaxentModel model;

int threads = getIntParam("Threads", 1);

model = trainModel(iterations, indexer, true, false, null, 0, threads);

return model;
   }
 
开发者ID:USCDataScience,项目名称:AgePredictor,代码行数:12,代码来源:AgeClassifyGIS.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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