Package opennlp.model

Examples of opennlp.model.OnePassRealValueDataIndexer


import opennlp.model.RealValueFileEventStream;

public class RealValueFileEventStreamTest extends TestCase {

  public void testLastLineBug() throws IOException {
    OnePassRealValueDataIndexer indexer;
    RealValueFileEventStream rvfes;
   
    rvfes = new RealValueFileEventStream(
        "src/test/resources/data/opennlp/maxent/io/rvfes-bug-data-ok.txt");
    try {
      indexer = new OnePassRealValueDataIndexer(rvfes, 1);
    } finally {
      rvfes.close();
    }
    assertEquals(1, indexer.getOutcomeLabels().length);

    rvfes = new RealValueFileEventStream(
        "src/test/resources/data/opennlp/maxent/io/rvfes-bug-data-broken.txt");
    try {
      indexer = new OnePassRealValueDataIndexer(rvfes, 1);
    } finally {
      rvfes.close();
    }
    assertEquals(1, indexer.getOutcomeLabels().length);
  }
View Full Code Here


  public void testRealValuedWeightsVsRepeatWeighting() throws IOException {
    GISModel realModel;
    RealValueFileEventStream rvfes1 = new RealValueFileEventStream("src/test/resources/data/opennlp/maxent/real-valued-weights-training-data.txt");
    try {
      realModel = GIS.trainModel(100,new OnePassRealValueDataIndexer(rvfes1,1));
    } finally {
      rvfes1.close();
    }

    GISModel repeatModel;
    FileEventStream rvfes2 = new FileEventStream("src/test/resources/data/opennlp/maxent/repeat-weighting-training-data.txt");
    try {
      repeatModel = GIS.trainModel(100,new OnePassRealValueDataIndexer(rvfes2,1));
    } finally {
      rvfes2.close();
    }

    String[] features2Classify = new String[] {"feature2","feature5"};
View Full Code Here

        if (!real) {
          model = GIS.trainModel(es, maxit, cutoff, sigma);
        } else {
          model = GIS.trainModel(maxit,
         new OnePassRealValueDataIndexer(es, cutoff),             
         USE_SMOOTHING);
        }

  writer = new SuffixSensitiveGISModelWriter(model, outputFile);
View Full Code Here

    StringReader smallReader = new StringReader(smallValues);
    EventStream smallEventStream = new RealBasicEventStream(
        new PlainTextByLineDataStream(smallReader));

    MaxentModel smallModel = GIS.trainModel(100,
        new OnePassRealValueDataIndexer(smallEventStream, 0), false);
    String[] contexts = smallTest.split(" ");
    float[] values = RealValueFileEventStream.parseContexts(contexts);
    double[] smallResults = smallModel.eval(contexts, values);

    String smallResultString = smallModel.getAllOutcomes(smallResults);
    System.out.println("smallResults: " + smallResultString);

    StringReader largeReader = new StringReader(largeValues);
    EventStream largeEventStream = new RealBasicEventStream(
        new PlainTextByLineDataStream(largeReader));

    MaxentModel largeModel = GIS.trainModel(100,
        new OnePassRealValueDataIndexer(largeEventStream, 0), false);
    contexts = largeTest.split(" ");
    values = RealValueFileEventStream.parseContexts(contexts);
    double[] largeResults = largeModel.eval(contexts, values);

    String largeResultString = smallModel.getAllOutcomes(largeResults);
View Full Code Here

public class RealValueModelTest extends TestCase {

  public void testRealValuedWeightsVsRepeatWeighting() throws IOException {
    RealValueFileEventStream rvfes1 = new RealValueFileEventStream("src/test/resources/data/opennlp/maxent/real-valued-weights-training-data.txt");
    GISModel realModel = GIS.trainModel(100,new OnePassRealValueDataIndexer(rvfes1,1));

    FileEventStream rvfes2 = new FileEventStream("src/test/resources/data/opennlp/maxent/repeat-weighting-training-data.txt");
    GISModel repeatModel = GIS.trainModel(100,new OnePassRealValueDataIndexer(rvfes2,1));

    String[] features2Classify = new String[] {"feature2","feature5"};
    double[] realResults = realModel.eval(features2Classify);
    double[] repeatResults = repeatModel.eval(features2Classify);
View Full Code Here

public class RealValueFileEventStreamTest extends TestCase {

  public void testLastLineBug() throws IOException {
    RealValueFileEventStream rvfes = new RealValueFileEventStream(
        "src/test/resources/data/opennlp/maxent/io/rvfes-bug-data-ok.txt");
    OnePassRealValueDataIndexer indexer = new OnePassRealValueDataIndexer(
        rvfes, 1);
    assertEquals(1, indexer.getOutcomeLabels().length);

    rvfes = new RealValueFileEventStream(
        "src/test/resources/data/opennlp/maxent/io/rvfes-bug-data-broken.txt");
    indexer = new OnePassRealValueDataIndexer(rvfes, 1);
    assertEquals(1, indexer.getOutcomeLabels().length);
  }
View Full Code Here

       
          if (!real) {
            model = GIS.trainModel(es,USE_SMOOTHING);
          }
          else {
            model = GIS.trainModel(100, new OnePassRealValueDataIndexer(es,0), USE_SMOOTHING);
          }
        }
        else if (type.equals("perceptron")){
          System.err.println("Perceptron training");
          model = new PerceptronTrainer().trainModel(10, new OnePassDataIndexer(es,0),0);
View Full Code Here

       
          if (!real) {
            model = GIS.trainModel(es,USE_SMOOTHING);
          }
          else {
            model = GIS.trainModel(100, new OnePassRealValueDataIndexer(es,0), USE_SMOOTHING);
          }
          writer =  new SuffixSensitiveGISModelWriter(model, outputFile);
        }
        else if (type.equals("perceptron")){
          System.err.println("Perceptron training");
View Full Code Here

        if (!real) {
          model = GIS.trainModel(es, maxit, cutoff, sigma);
        } else {
          model = GIS.trainModel(maxit,
         new OnePassRealValueDataIndexer(es, cutoff),             
         USE_SMOOTHING);
        }

  writer = new SuffixSensitiveGISModelWriter(model, outputFile);
View Full Code Here

  @Test
  public void testDomainDimensionSanity() throws IOException {
    // given
    RealValueFileEventStream rvfes1 = new RealValueFileEventStream("src/test/resources/data/opennlp/maxent/real-valued-weights-training-data.txt", "UTF-8")
    DataIndexer testDataIndexer = new OnePassRealValueDataIndexer(rvfes1,1);
    LogLikelihoodFunction objectFunction = new LogLikelihoodFunction(testDataIndexer);
    // when
    int correctDomainDimension = testDataIndexer.getPredLabels().length * testDataIndexer.getOutcomeLabels().length;
    // then
    assertEquals(correctDomainDimension, objectFunction.getDomainDimension());
  }
View Full Code Here

TOP

Related Classes of opennlp.model.OnePassRealValueDataIndexer

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.