Package opennlp.tools.ml.model

Examples of opennlp.tools.ml.model.OnePassRealValueDataIndexer


  @Test
  public void testTrainModelReturnsAQNModel() throws Exception {
    // given
    RealValueFileEventStream rvfes1 = new RealValueFileEventStream(
        "src/test/resources/data/opennlp/maxent/real-valued-weights-training-data.txt")
    DataIndexer testDataIndexer = new OnePassRealValueDataIndexer(rvfes1,1);
    // when
    QNModel trainedModel = new QNTrainer(false).trainModel(ITERATIONS, testDataIndexer);
    // then
    assertNotNull(trainedModel);
  }
View Full Code Here


  @Test
  public void testInTinyDevSet() throws Exception {
    // given
    RealValueFileEventStream rvfes1 = new RealValueFileEventStream(
        "src/test/resources/data/opennlp/maxent/real-valued-weights-training-data.txt")
    DataIndexer testDataIndexer = new OnePassRealValueDataIndexer(rvfes1,1);
    // when
    QNModel trainedModel = new QNTrainer(15, true).trainModel(ITERATIONS, testDataIndexer);
    String[] features2Classify = new String[] {
        "feature2","feature3", "feature3",
        "feature3","feature3", "feature3",
View Full Code Here

  @Test
  public void testModel() throws IOException {
      // given
      RealValueFileEventStream rvfes1 = new RealValueFileEventStream(
          "src/test/resources/data/opennlp/maxent/real-valued-weights-training-data.txt")
      DataIndexer testDataIndexer = new OnePassRealValueDataIndexer(rvfes1,1);
      // when
      QNModel trainedModel = new QNTrainer(15, true).trainModel(
          ITERATIONS, testDataIndexer);
     
      assertTrue(trainedModel.equals(trainedModel))
View Full Code Here

  @Test
  public void testSerdeModel() throws IOException {
      // given
      RealValueFileEventStream rvfes1 = new RealValueFileEventStream(
          "src/test/resources/data/opennlp/maxent/real-valued-weights-training-data.txt")
      DataIndexer testDataIndexer = new OnePassRealValueDataIndexer(rvfes1,1);
      // when
      QNModel trainedModel = new QNTrainer(5, 700, true).trainModel(ITERATIONS, testDataIndexer);
     
      ByteArrayOutputStream modelBytes = new ByteArrayOutputStream();
      GenericModelWriter modelWriter = new GenericModelWriter(trainedModel,
View Full Code Here

    StringReader smallReader = new StringReader(smallValues);
    ObjectStream<Event> smallEventStream = new RealBasicEventStream(
        new PlainTextByLineStream(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);
    ObjectStream<Event> largeEventStream = new RealBasicEventStream(
        new PlainTextByLineStream(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 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

import opennlp.tools.ml.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

  @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);
    NegLogLikelihood objectFunction = new NegLogLikelihood(testDataIndexer);
    // when
    int correctDomainDimension = testDataIndexer.getPredLabels().length
        * testDataIndexer.getOutcomeLabels().length;
    // then
    assertEquals(correctDomainDimension, objectFunction.getDimension());
  }
View Full Code Here

  @Test
  public void testInitialSanity() 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);
    NegLogLikelihood objectFunction = new NegLogLikelihood(testDataIndexer);
    // when
    double[] initial = objectFunction.getInitialPoint();
    // then
    for (int i = 0; i < initial.length; i++) {
View Full Code Here

  @Test
  public void testGradientSanity() 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);
    NegLogLikelihood objectFunction = new NegLogLikelihood(testDataIndexer);
    // when
    double[] initial = objectFunction.getInitialPoint();
    double[] gradientAtInitial = objectFunction.gradientAt(initial);
    // then
View Full Code Here

TOP

Related Classes of opennlp.tools.ml.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.