Package opennlp.maxent

Examples of opennlp.maxent.EventCollectorAsStream


  public static void train(String[] args) throws IOException {
      FileReader datafr = new FileReader(new File(args[0]));
      File output = new File(args[1]);
      EventStream evc =
        new EventCollectorAsStream(new TokEventCollector(datafr));
      train(evc, output);
  }
View Full Code Here


    modelsByType = new HashMap<String,GISModel>();
    for(String type : eventsByType.keySet()) {
      DataIndexer di = null;
      List<Event> evs = eventsByType.get(type);
      if(evs.size() == 1) evs.add(evs.get(0));
      di = new TwoPassDataIndexer(new EventCollectorAsStream(new SimpleEventCollector(evs)), 1);
      modelsByType.put(type, GIS.trainModel(trainingCycles, di));
    }
  }
View Full Code Here

    if(useUber) {
      List<Event> evs = new ArrayList<Event>();
      for(String prevTagg : evsByPrev.keySet()) {
        evs.addAll(evsByPrev.get(prevTagg));
      }
      DataIndexer di = new TwoPassDataIndexer(new EventCollectorAsStream(new SimpleEventCollector(evs)), featureCutOff);
      ubermodel = GIS.trainModel(trainingCycles, di);
    } else {
      for(String prevTagg : evsByPrev.keySet()) {
        if(Oscar3Props.getInstance().verbose) System.out.println(prevTagg);
        List<Event> evs = evsByPrev.get(prevTagg);
        if(featureSel) {
          evs = new FeatureSelector().selectFeatures(evs);           
        }   
        if(evs.size() == 1) {
          evs.add(evs.get(0));
        }
        DataIndexer di = null;
        try {
          di = new TwoPassDataIndexer(new EventCollectorAsStream(new SimpleEventCollector(evs)), featureCutOff);
          gmByPrev.put(prevTagg, GIS.trainModel(trainingCycles, di));
        } catch (Exception e) {
          di = new TwoPassDataIndexer(new EventCollectorAsStream(new SimpleEventCollector(evs)), 1);       
          gmByPrev.put(prevTagg, GIS.trainModel(trainingCycles, di));
       
      }
    }
  }
View Full Code Here

      trainEvents.add(new Event(be.getClassLabel(), be.getFeatures().getSet().toArray(new String[0])));
    }
    for(BagEvent be : testBagEvents) {
      testEvents.add(new Event(be.getClassLabel(), be.getFeatures().getSet().toArray(new String[0])));
    }
    DataIndexer di = new TwoPassDataIndexer(new EventCollectorAsStream(new SimpleEventCollector(trainEvents)), 1);
    GISModel gm = GIS.trainModel(100, di);
   
    //ClassificationEvaluator ce = new ClassificationEvaluator();
   
    for(Event event : testEvents) {
View Full Code Here

      Event event = new Event(type, f.toArray(new String[0]));
      events.add(event);
    }
    if(events.size() == 1) events.add(events.get(0));
    DataIndexer di = new TwoPassDataIndexer(new EventCollectorAsStream(new SimpleEventCollector(events)), 3);
    GISModel gm = GIS.trainModel(100, di);
   
    ClassificationEvaluator ce = new ClassificationEvaluator();

    List<Double> chemList = new ArrayList<Double>();
View Full Code Here

      List<Event> trainData = events.subList(0, events.size()/2);
      //trainData = new FeatureSelector().selectFeatures(trainData, 200.0);
      List<Event> testData = events.subList(events.size()/2, events.size());
     
      if(trainData.size() == 1) trainData.add(trainData.get(0));
      DataIndexer di = new TwoPassDataIndexer(new EventCollectorAsStream(new SimpleEventCollector(trainData)), 1);
      GISModel gm = GIS.trainModel(100, di);
     
      ClassificationEvaluator ce = new ClassificationEvaluator();
     
      for(Event event : testData) {
View Full Code Here

          events.add(ev);
        }
      }
      if(events.size() < 2) continue;
      DataIndexer di = null;
      di = new TwoPassDataIndexer(new EventCollectorAsStream(new SimpleEventCollector(events)), 1);
      if(Oscar3Props.getInstance().verbose) System.out.println(di);
      GISModel gm = GIS.trainModel(100, di);
      classifiers.put(type, gm);
    }
  }
View Full Code Here

      String outcome = "E";
      if(isChem.get(s)) outcome = "C";
      events.add(new Event(outcome, getFeatures(s)));
    }
    SimpleEventCollector sec = new SimpleEventCollector(events);
    DataIndexer di = new TwoPassDataIndexer(new EventCollectorAsStream(sec), 1);
    GISModel gis = GIS.trainModel(100, di);
   
    System.out.println(gis.getIndex("FOO"));
    if(true) return;
   
   
    long time = System.currentTimeMillis();
    StringGISModelWriter sgmw = new StringGISModelWriter(gis);
    sgmw.persist();
    String modelStr = sgmw.toString();

    //System.out.println(modelStr);
   
    StringGISModelReader sgmr = new StringGISModelReader(modelStr);
    gis = sgmr.getModel();
    System.out.println("Round trip in " + (System.currentTimeMillis() - time));
    System.out.println(modelStr.length());
   
    //if(true) return;
   
    GISModel gis2 = null;
   
    if(false) {
      List<Event> events2 = new ArrayList<Event>();
      for(String s : batch2) {
        double prob = gis.eval(getFeatures(s))[gis.getIndex("C")];
        String outcome = "E";
        if(isChem.get(s)) outcome = "C";
        events.add(new Event(outcome, probToFeatures(prob)));
      }
      sec = new SimpleEventCollector(events);
      di = new TwoPassDataIndexer(new EventCollectorAsStream(sec), 2);
      gis2 = GIS.trainModel(1000, di);     
    }
   
    double score = 0.0;
    List<Double> trialScores = new ArrayList<Double>();
View Full Code Here

   
    List<Event> trainData = events.subList(0, events.size()/2);
    List<Event> testData = events.subList(events.size()/2, events.size());
   
    if(trainData.size() == 1) trainData.add(trainData.get(0));
    DataIndexer di = new TwoPassDataIndexer(new EventCollectorAsStream(new SimpleEventCollector(trainData)), 1);
    GISModel gm = GIS.trainModel(100, di);
   
    ClassificationEvaluator ce = new ClassificationEvaluator();
   
    for(Event event : testData) {
View Full Code Here

        trainEvents.add(new Event(be.getClassLabel(), be.getFeatures().getSet().toArray(new String[0])));
      }
      for(BagEvent be : testBagEvents) {
        testEvents.add(new Event(be.getClassLabel(), be.getFeatures().getSet().toArray(new String[0])));
      }
      DataIndexer di = new TwoPassDataIndexer(new EventCollectorAsStream(new SimpleEventCollector(trainEvents)), 1);
      GISModel gm = GIS.trainModel(100, di);
     
      //ClassificationEvaluator ce = new ClassificationEvaluator();
     
      for(Event event : testEvents) {
View Full Code Here

TOP

Related Classes of opennlp.maxent.EventCollectorAsStream

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.