Package opennlp.tools.ml.model

Examples of opennlp.tools.ml.model.MaxentModel


    String sequence[] = new String[0];
    BeamSearchContextGenerator<String> cg = new IdentityFeatureGenerator(sequence);

    String outcomes[] = new String[] {"1", "2", "3"};
    MaxentModel model = new IdentityModel(outcomes);

    BeamSearch<String> bs = new BeamSearch<String>(3, cg, model);

    Sequence seq = bs.bestSequence(sequence, null);
    assertNotNull(seq);
View Full Code Here


  public void testBestSequenceOneElementInput() {
    String sequence[] = {"1"};
    BeamSearchContextGenerator<String> cg = new IdentityFeatureGenerator(sequence);

    String outcomes[] = new String[] {"1", "2", "3"};
    MaxentModel model = new IdentityModel(outcomes);

    BeamSearch<String> bs = new BeamSearch<String>(3, cg, model);

    Sequence seq = bs.bestSequence(sequence, null);
    assertNotNull(seq);
View Full Code Here

  public void testBestSequence() {
    String sequence[] = {"1", "2", "3", "2", "1"};
    BeamSearchContextGenerator<String> cg = new IdentityFeatureGenerator(sequence);

    String outcomes[] = new String[] {"1", "2", "3"};
    MaxentModel model = new IdentityModel(outcomes);

    BeamSearch<String> bs = new BeamSearch<String>(2, cg, model);

    Sequence seq = bs.bestSequence(sequence, null);
    assertNotNull(seq);
View Full Code Here

  public void testBestSequenceWithValidator() {
    String sequence[] = {"1", "2", "3", "2", "1"};
    BeamSearchContextGenerator<String> cg = new IdentityFeatureGenerator(sequence);

    String outcomes[] = new String[] {"1", "2", "3"};
    MaxentModel model = new IdentityModel(outcomes);

    BeamSearch<String> bs = new BeamSearch<String>(2, cg, model, new SequenceValidator<String>(){

      public boolean validSequence(int i, String[] inputSequence,
          String[] outcomesSequence, String outcome) {
View Full Code Here

    // build
    System.err.println("Training builder");
    ObjectStream<Event> bes = new ParserEventStream(parseSamples, rules,
        ParserEventTypeEnum.BUILD, mdict);
    Map<String, String> buildReportMap = new HashMap<String, String>();
    MaxentModel buildModel = TrainUtil.train(bes, mlParams.getSettings("build"), buildReportMap);
    opennlp.tools.parser.chunking.Parser.mergeReportIntoManifest(manifestInfoEntries, buildReportMap, "build");

    parseSamples.reset();

    // check
    System.err.println("Training checker");
    ObjectStream<Event>  kes = new ParserEventStream(parseSamples, rules,
        ParserEventTypeEnum.CHECK);
    Map<String, String> checkReportMap = new HashMap<String, String>();
    MaxentModel checkModel = TrainUtil.train(kes, mlParams.getSettings("check"), checkReportMap);
    opennlp.tools.parser.chunking.Parser.mergeReportIntoManifest(manifestInfoEntries, checkReportMap, "check");

    parseSamples.reset();

    // attach
    System.err.println("Training attacher");
    ObjectStream<Event>  attachEvents = new ParserEventStream(parseSamples, rules,
        ParserEventTypeEnum.ATTACH);
    Map<String, String> attachReportMap = new HashMap<String, String>();
    MaxentModel attachModel = TrainUtil.train(attachEvents, mlParams.getSettings("attach"), attachReportMap);
    opennlp.tools.parser.chunking.Parser.mergeReportIntoManifest(manifestInfoEntries, attachReportMap, "attach");

    // TODO: Remove cast for HeadRules
    return new ParserModel(languageCode, buildModel, checkModel,
        attachModel, posModel, chunkModel,
View Full Code Here

    // build
    System.err.println("Training builder");
    ObjectStream<Event> bes = new ParserEventStream(parseSamples, rules, ParserEventTypeEnum.BUILD, mdict);
    Map<String, String> buildReportMap = new HashMap<String, String>();
    MaxentModel buildModel = TrainUtil.train(bes, mlParams.getSettings("build"), buildReportMap);
    mergeReportIntoManifest(manifestInfoEntries, buildReportMap, "build");

    parseSamples.reset();

    // tag
    POSModel posModel = POSTaggerME.train(languageCode, new PosSampleStream(parseSamples),
        mlParams.getParameters("tagger"), null, null);

    parseSamples.reset();

    // chunk
    ChunkerModel chunkModel = ChunkerME.train(languageCode,
        new ChunkSampleStream(parseSamples),
        new ChunkContextGenerator(), mlParams.getParameters("chunker"));

    parseSamples.reset();

    // check
    System.err.println("Training checker");
    ObjectStream<Event> kes = new ParserEventStream(parseSamples, rules, ParserEventTypeEnum.CHECK);
    Map<String, String> checkReportMap = new HashMap<String, String>();
    MaxentModel checkModel = TrainUtil.train(kes, mlParams.getSettings("check"), checkReportMap);
    mergeReportIntoManifest(manifestInfoEntries, checkReportMap, "check");

    // TODO: Remove cast for HeadRules
    return new ParserModel(languageCode, buildModel, checkModel,
        posModel, chunkModel, (opennlp.tools.parser.HeadRules) rules,
View Full Code Here

    if (!isValid()) {
      throw new IllegalArgumentException("trainParams are not valid!");
    }

    MaxentModel model = doTrain(events);
    addToReport(AbstractTrainer.TRAINER_TYPE_PARAM,
        EventModelSequenceTrainer.SEQUENCE_VALUE);
    return model;
  }
View Full Code Here

      beamSize = Integer.parseInt(beamSizeString);
    }

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

    MaxentModel nameFinderModel = null;

    SequenceClassificationModel<String> seqModel = null;

    TrainerType trainerType = TrainerFactory.getTrainerType(trainParams.getSettings());
View Full Code Here

      featureGenerator = generator;
    } else {
      featureGenerator = createFeatureGenerator();
    }

    MaxentModel nameFinderModel = null;

    SequenceClassificationModel<String> seqModel = null;

    TrainerType trainerType = TrainerFactory.getTrainerType(trainParams.getSettings());
View Full Code Here

  public String[] getOrderedTags(List<String> words, List<String> tags, int index,double[] tprobs) {

    if (modelPackage.getPosModel() != null) {

      MaxentModel posModel = modelPackage.getPosModel();

      double[] probs = posModel.eval(contextGen.getContext(index,
          words.toArray(new String[words.size()]),
          tags.toArray(new String[tags.size()]),null));

      String[] orderedTags = new String[probs.length];
      for (int i = 0; i < probs.length; i++) {
        int max = 0;
        for (int ti = 1; ti < probs.length; ti++) {
          if (probs[ti] > probs[max]) {
            max = ti;
          }
        }
        orderedTags[i] = posModel.getOutcome(max);
        if (tprobs != null){
          tprobs[i]=probs[max];
        }
        probs[max] = 0;
      }
View Full Code Here

TOP

Related Classes of opennlp.tools.ml.model.MaxentModel

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.