Package cc.mallet.fst

Examples of cc.mallet.fst.CRF$State


      }
    } 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

    @Override
    public CompletionContext<State> buildContext(
        SelectionModel selection, DocumentParser parser) {
      JsonArray<Token> tokens = JsonCollections.createArray();
      State state = TestUtils.createMockState();
      tokens.add(new Token(null, NULL, ""));
      ParseResult<State> parseResult = new ParseResult<State>(tokens, state) {};
      return buildContext(
          new ParseUtils.ExtendedParseResult<State>(parseResult, ParseUtils.Context.IN_CODE));
    }
View Full Code Here

   * @param anchorToUpdate the optional anchor that this method will update
   */
  private boolean parseImplCm2(Line line, int lineNumber, int numLinesToProcess,
      @Nullable Anchor anchorToUpdate, ParsedTokensRecipient tokensRecipient) {

    State parserState = loadParserStateForBeginningOfLine(line);
    if (parserState == null) {
      return false;
    }

    Line previousLine = line.getPreviousLine();

    for (int numLinesProcessed = 0; line != null && numLinesProcessed < numLinesToProcess;) {
      State stateToSave = parserState;
      if (line.getText().length() > LINE_LENGTH_LIMIT) {
        // Save the initial state instead of state at the end of line.
        stateToSave = parserState.copy(codeMirrorParser);
      }

View Full Code Here

    parseImplCm2(line, -1, 1, null, tokensRecipient);
    return tokensRecipient.tokens;
  }

  int getIndentation(Line line) {
    State stateBefore = loadParserStateForBeginningOfLine(line);
    String textAfter = line.getText();
    textAfter = textAfter.substring(StringUtils.lengthOfStartingWhitespace(textAfter));
    return codeMirrorParser.indent(stateBefore, textAfter);
  }
View Full Code Here

   *
   * @return copy of corresponding parser state, or {@code null} if the state
   *         if not known yet (previous line wasn't parsed).
   */
  private <T extends State> T loadParserStateForBeginningOfLine(TaggableLine line) {
    State state;
    if (line.isFirstLine()) {
      state = codeMirrorParser.defaultState();
    } else {
      state = line.getPreviousLine().getTag(LINE_TAG_END_OF_LINE_PARSER_STATE_SNAPSHOT);
      state = (state == null) ? null : state.copy(codeMirrorParser);
    }

    @SuppressWarnings("unchecked")
    T result = (T) state;
    return result;
View Full Code Here

TOP

Related Classes of cc.mallet.fst.CRF$State

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.