Package cc.mallet.fst

Examples of cc.mallet.fst.CRF


      }
    } else
      testFile = new FileReader(new File(args[restArgs]));

    Pipe p = null;
    CRF crf = null;
    TransducerEvaluator eval = null;
    if (continueTrainingOption.value || !trainOption.value) {
      if (modelOption.value == null)
      {
        commandOptions.printUsage(true);
        throw new IllegalArgumentException("Missing model file option");
      }
      ObjectInputStream s =
        new ObjectInputStream(new FileInputStream(modelOption.value));
      crf = (CRF) s.readObject();
      s.close();
      p = crf.getInputPipe();
    }
    else {
      p = new SimpleTaggerSentence2FeatureVectorSequence();
      p.getTargetAlphabet().lookupIndex(defaultOption.value);
    }
View Full Code Here


      else {
        constraints2.add(constraint);
      }
    }
   
    CRF crf = (CRF)transducer;
   
    double dotEx = this.runForward(crf, constraints1, constraints2, gammas, xis, reverseTrans, fvs);
    this.runBackward(crf, gammas, xis, reverseTrans, reverseTransIndices, fvs, dotEx, gradient);
    //check(constraints,gammas,xis,fvs);
  }
View Full Code Here

    Sequence predicted = docextr.getPredictedLabels ();

    ExtorInfo info = new ExtorInfo (input, predicted, target, desc, idx);

    if (showLattice == true) {
      CRF crf = extor.getCrf();
      // xxx perhaps the next two lines could be a transducer method???
      Instance carrier = extor.getFeaturePipe().pipe(new Instance (input, null, null, null));
      info.fvs = (FeatureVectorSequence) carrier.getData ();
      info.lattice = new MaxLatticeDefault (crf, (Sequence) carrier.getData(), null);
      info.bestStates = info.lattice.bestOutputSequence();
View Full Code Here

    Pipe p = makeSpacePredictionPipe();

    InstanceList instances = new InstanceList(p);
    instances.addThruPipe(new ArrayIterator(data));

    CRF crf1 = new CRF(p, null);
    crf1.addFullyConnectedStatesForLabels();
    CRFTrainerByLabelLikelihood crft1 = new CRFTrainerByLabelLikelihood(
        crf1);
    crft1.train(instances, 10); // Let's get some parameters

    Instance inst = instances.get(0);
    Sequence input = (Sequence) inst.getData();
    SumLatticeDefault lattice = new SumLatticeDefault(crf1, input,
        (Sequence) inst.getTarget(), null, true);
    for (int ip = 0; ip < lattice.length() - 1; ip++) {
      for (int i = 0; i < crf1.numStates(); i++) {
        Transducer.State state = crf1.getState(i);
        Transducer.TransitionIterator it = state.transitionIterator(
            input, ip);
        double gamma = lattice.getGammaProbability(ip, state);
        double xiSum = 0;
        while (it.hasNext()) {
View Full Code Here

    training.addThruPipe(new ArrayIterator(data)); // This used to be
    // MEMM.data, but I
    // don't know why -akm
    // 12/2007

    CRF crf = new CRF(p, null);
    crf.addFullyConnectedStatesForLabels();
    CRFTrainerByLabelLikelihood crft = new CRFTrainerByLabelLikelihood(crf);
    crft.trainIncremental(training);

    // Check that the notstart state is used at test time
    Sequence input = (Sequence) training.get(0).getData();
    Sequence output = new MaxLatticeDefault(crf, input)
        .bestOutputSequence();

    boolean notstartFound = false;
    for (int i = 0; i < output.size(); i++) {
      if (output.get(i).toString().equals("notstart")) {
        notstartFound = true;
      }
    }
    System.err.println(output.toString());
    assertTrue(notstartFound);

    // Now add -infinite weight onto a transition, and make sure that it's
    // honored.
    CRF.State state = crf.getState("notstart");
    int widx = crf.getWeightsIndex("BadBad");
    int numFeatures = crf.getInputAlphabet().size();
    SparseVector w = new SparseVector(new double[numFeatures]);
    w.setAll(Double.NEGATIVE_INFINITY);
    crf.setWeights(widx, w);

    state.addWeight(0, "BadBad");
    state.addWeight(1, "BadBad");

    // Verify that this effectively prevents the notstart state from being
View Full Code Here

  private static String oldCrfFile = "test/edu/umass/cs/mallet/base/fst/crf.cnl03.ser.gz";
  private static String testString = "John NNP B-NP O\nDoe NNP I-NP O\nsaid VBZ B-VP O\nhi NN B-NP O\n";

  public void skiptestOldCrf() {
    CRF crf = (CRF) FileUtils.readObject(new File(oldCrfFile));
    Instance inst = crf.getInputPipe().instanceFrom(
        new Instance(testString, null, null, null));
    Sequence output = crf.transduce((Sequence) inst.getData());
    String std = output.toString();
    assertEquals(" B-PER I-PER O O", std);
  }
View Full Code Here

TOP

Related Classes of cc.mallet.fst.CRF

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.