Ejemplo n.º 1
0
  public void doTraining() throws IOException {
    readTrainingSentences(examplesFilename);
    constructLabelVocab();
    extractFeatures();

    model.lockdownAfterFeatureExtraction();
    if (modelLoadFilename != null) {
      readWarmStartModel();
    }
    optimizationLoop();
    model.saveModelAsText(modelSaveFilename);
  }
Ejemplo n.º 2
0
  public void optimizationLoop() {
    OWLQN minimizer = new OWLQN();
    minimizer.setMaxIters(maxIter);
    minimizer.setQuiet(false);
    minimizer.setWeightsPrinting(new MyWeightsPrinter());

    double[] initialWeights = model.convertCoefsToFlat();

    double[] finalWeights =
        minimizer.minimize(new GradientCalculator(), initialWeights, l1penalty, tol, 5);

    model.setCoefsFromFlat(finalWeights);
  }
Ejemplo n.º 3
0
 public void constructLabelVocab() {
   for (Sentence s : lSentences) {
     for (String l : s.labels) {
       model.labelVocab.num(l);
     }
   }
   model.labelVocab.lock();
   model.numLabels = model.labelVocab.size();
 }
Ejemplo n.º 4
0
 public void readWarmStartModel() throws IOException {
   assert model.featureVocab.isLocked();
   Model warmModel = Model.loadModelFromText(modelLoadFilename);
   Model.copyCoefsForIntersectingFeatures(warmModel, model);
 }