Package opennlp.tools.util

Examples of opennlp.tools.util.TrainingParameters


 
  public static ParserModel train(String languageCode,
      ObjectStream<Parse> parseSamples, HeadRules rules, int iterations, int cut)
      throws IOException {
   
    TrainingParameters params = new TrainingParameters();
    params.put("dict", TrainingParameters.CUTOFF_PARAM, Integer.toString(cut));

    params.put("tagger", TrainingParameters.CUTOFF_PARAM, Integer.toString(cut));
    params.put("tagger", TrainingParameters.ITERATIONS_PARAM, Integer.toString(iterations));
    params.put("chunker", TrainingParameters.CUTOFF_PARAM, Integer.toString(cut));
    params.put("chunker", TrainingParameters.ITERATIONS_PARAM, Integer.toString(iterations));
    params.put("check", TrainingParameters.CUTOFF_PARAM, Integer.toString(cut));
    params.put("check", TrainingParameters.ITERATIONS_PARAM, Integer.toString(iterations));
    params.put("build", TrainingParameters.CUTOFF_PARAM, Integer.toString(cut));
    params.put("build", TrainingParameters.ITERATIONS_PARAM, Integer.toString(iterations));
   
    return train(languageCode, parseSamples, rules, params);
  }
View Full Code Here


 
  // its optional, passing null is allowed
  public static TrainingParameters loadTrainingParameters(String paramFile,
      boolean supportSequenceTraining) {
   
    TrainingParameters params = null;
   
    if (paramFile != null) {
     
      checkInputFile("Training Parameter", new File(paramFile));
     
      InputStream paramsIn = null;
      try {
        paramsIn = new FileInputStream(new File(paramFile));
       
        params = new opennlp.tools.util.TrainingParameters(paramsIn);
      } catch (IOException e) {
        throw new TerminateToolException(-1, "Error during parameters loading: " + e.getMessage(), e);
      }
      finally {
        try {
          if (paramsIn != null)
            paramsIn.close();
        } catch (IOException e) {
          //sorry that this can fail
        }
      }
     
      if (!TrainUtil.isValid(params.getSettings())) {
        throw new TerminateToolException(1, "Training parameters file '" + paramFile + "' is invalid!");
      }
     
      if (!supportSequenceTraining && TrainUtil.isSequenceTraining(params.getSettings())) {
        throw new TerminateToolException(1, "Sequence training is not supported!");
      }
    }
   
    return params;
View Full Code Here

    try(FileInputStream inStream = new FileInputStream(inFile)){
      ObjectStream<String> lineStream = new PlainTextByLineStream(inStream, charset);
      ObjectStream<SentenceSample> sampleStream = new SentenceSampleStream(lineStream);

      // Training Parameters
      TrainingParameters mlParams = new TrainingParameters();
      mlParams.put(TrainingParameters.ALGORITHM_PARAM, "MAXENT");
      mlParams.put(TrainingParameters.ITERATIONS_PARAM, Integer.toString(iters));
      mlParams.put(TrainingParameters.CUTOFF_PARAM, Integer.toString(cut));

      // Abbreviations dictionary
      // TODO: Actually import a Dictionary of abbreviations
      Dictionary dict = new Dictionary();
View Full Code Here

  public void testSentenceDetector() throws IOException {

    InputStream in = getClass().getResourceAsStream(
        "/opennlp/tools/sentdetect/Sentences.txt");

    TrainingParameters mlParams = new TrainingParameters();
    mlParams.put(TrainingParameters.ITERATIONS_PARAM, Integer.toString(100));
    mlParams.put(TrainingParameters.CUTOFF_PARAM, Integer.toString(0));

    SentenceModel sentdetectModel = SentenceDetectorME.train(
        "en", new SentenceSampleStream(new PlainTextByLineStream(new InputStreamReader(in))), true, null, mlParams);

    assertEquals("en", sentdetectModel.getLanguage());
View Full Code Here

      new DocumentSample("0", new String[]{"x", "y", "z"}),
      new DocumentSample("0", new String[]{"x", "y", "z", "5", "6"}),
      new DocumentSample("0", new String[]{"x", "y", "z", "7", "8"})
    });

    TrainingParameters params = new TrainingParameters();
    params.put(TrainingParameters.ITERATIONS_PARAM, Integer.toString(100));
    params.put(TrainingParameters.CUTOFF_PARAM, Integer.toString(0));

    DoccatModel model = DocumentCategorizerME.train("x-unspecified", samples,
            params, new BagOfWordsFeatureGenerator());

    DocumentCategorizer doccat = new DocumentCategorizerME(model);
View Full Code Here

        new Span(0, 3)}));
    samples.add(new TokenSample("yes,", new Span[]{
        new Span(0, 3),
        new Span(3, 4)}));

    TrainingParameters mlParams = new TrainingParameters();
    mlParams.put(TrainingParameters.ITERATIONS_PARAM, Integer.toString(100));
    mlParams.put(TrainingParameters.CUTOFF_PARAM, Integer.toString(0));

    return TokenizerME.train("en", new CollectionObjectStream<TokenSample>(samples), true,
        mlParams);
  }
View Full Code Here

        "/opennlp/tools/tokenize/token.train");

    ObjectStream<TokenSample> samples = new TokenSampleStream(
        new PlainTextByLineStream(new InputStreamReader(trainDataIn, "UTF-8")));

    TrainingParameters mlParams = new TrainingParameters();
    mlParams.put(TrainingParameters.ITERATIONS_PARAM, Integer.toString(100));
    mlParams.put(TrainingParameters.CUTOFF_PARAM, Integer.toString(0));

    return TokenizerME.train("en", samples, true, mlParams);
  }
View Full Code Here

    String encoding = "UTF-8";

    ObjectStream<ChunkSample> sampleStream = new ChunkSampleStream(
        new PlainTextByLineStream(new InputStreamReader(in, encoding)));

    TrainingParameters params = new TrainingParameters();
    params.put(TrainingParameters.ITERATIONS_PARAM, Integer.toString(70));
    params.put(TrainingParameters.CUTOFF_PARAM, Integer.toString(1));

    ChunkerModel chunkerModel = ChunkerME.train("en", sampleStream, params, new ChunkerFactory());

    this.chunker = new ChunkerME(chunkerModel);
  }
View Full Code Here

  public static ParserModel train(String languageCode,
      ObjectStream<Parse> parseSamples, HeadRules rules, int iterations, int cut)
      throws IOException {

    TrainingParameters params = new TrainingParameters();
    params.put("dict", TrainingParameters.CUTOFF_PARAM, Integer.toString(cut));

    params.put("tagger", TrainingParameters.CUTOFF_PARAM, Integer.toString(cut));
    params.put("tagger", TrainingParameters.ITERATIONS_PARAM, Integer.toString(iterations));
    params.put("chunker", TrainingParameters.CUTOFF_PARAM, Integer.toString(cut));
    params.put("chunker", TrainingParameters.ITERATIONS_PARAM, Integer.toString(iterations));
    params.put("check", TrainingParameters.CUTOFF_PARAM, Integer.toString(cut));
    params.put("check", TrainingParameters.ITERATIONS_PARAM, Integer.toString(iterations));
    params.put("build", TrainingParameters.CUTOFF_PARAM, Integer.toString(cut));
    params.put("build", TrainingParameters.ITERATIONS_PARAM, Integer.toString(iterations));

    return train(languageCode, parseSamples, rules, params);
  }
View Full Code Here

   * @return A dictionary object.
   */
  public static Dictionary buildDictionary(ObjectStream<Parse> data, HeadRules rules, int cutoff)
      throws IOException {

    TrainingParameters params = new TrainingParameters();
    params.put("dict", TrainingParameters.CUTOFF_PARAM, Integer.toString(cutoff));

    return buildDictionary(data, rules, params);
  }
View Full Code Here

TOP

Related Classes of opennlp.tools.util.TrainingParameters

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.