Package cc.mallet.types

Examples of cc.mallet.types.FeatureSequence


  private boolean[][] labelConnectionsIn(InstanceList trainingSet) {
    int numLabels = outputAlphabet.size();
    boolean[][] connections = new boolean[numLabels][numLabels];
    for (Instance instance : trainingSet) {
      FeatureSequence output = (FeatureSequence) instance.getTarget();
      for (int j = 1; j < output.size(); j++) {
        int sourceIndex = outputAlphabet.lookupIndex(output.get(j - 1));
        int destIndex = outputAlphabet.lookupIndex(output.get(j));
        assert (sourceIndex >= 0 && destIndex >= 0);
        connections[sourceIndex][destIndex] = true;
      }
    }
    return connections;
View Full Code Here


      }
      initialEstimator = new Multinomial.LaplaceEstimator(
          transitionAlphabet);
    }
    for (Instance instance : ilist) {
      FeatureSequence input = (FeatureSequence) instance.getData();
      FeatureSequence output = (FeatureSequence) instance.getTarget();
      new SumLatticeDefault(this, input, output, new Incrementor());
    }
    initialMultinomial = initialEstimator.estimate();
    for (int i = 0; i < numStates(); i++) {
      emissionMultinomial[i] = emissionEstimator[i].estimate();
View Full Code Here

  {
    int numLabels = outputAlphabet.size();
    boolean[][] connections = new boolean[numLabels][numLabels];
    for (int i = 0; i < trainingSet.size(); i++) {
      Instance instance = trainingSet.get(i);
      FeatureSequence output = (FeatureSequence) instance.getTarget();
      for (int j = 1; j < output.size(); j++) {
        int sourceIndex = outputAlphabet.lookupIndex (output.get(j-1));
        int destIndex = outputAlphabet.lookupIndex (output.get(j));
        assert (sourceIndex >= 0 && destIndex >= 0);
        connections[sourceIndex][destIndex] = true;
      }
    }
View Full Code Here

        weightsPresent[i].set (parameters.weights[i].indexAtLocation(j));
    // Put in the weights in the training set
    for (int i = 0; i < trainingData.size(); i++) {
      Instance instance = trainingData.get(i);
      FeatureVectorSequence input = (FeatureVectorSequence) instance.getData();
      FeatureSequence output = (FeatureSequence) instance.getTarget();
      // gsc: trainingData can have unlabeled instances as well
      if (output != null && output.size() > 0) {
        // Do it for the paths consistent with the labels...
        sumLatticeFactory.newSumLattice (this, input, output, new Transducer.Incrementor() {
          public void incrementTransition (Transducer.TransitionIterator ti, double count) {
            State source = (CRF.State)ti.getSourceState();
            FeatureVector input = (FeatureVector)ti.getInput();
View Full Code Here

    long start = System.nanoTime();

    try {
      ArrayList<String> tokens = (ArrayList<String>) carrier.getData();
      FeatureSequence featureSequence =
        new FeatureSequence ((Alphabet) getDataAlphabet(), tokens.size());
      for (int i = 0; i < tokens.size(); i++) {
        featureSequence.add (tokens.get(i));
      }
      carrier.setData(featureSequence);
     
      totalNanos += System.nanoTime() - start;
    } catch (ClassCastException cce) {
View Full Code Here

  FeatureVector fv;
 
  protected void setUp ()
  {
    dict = new Alphabet ();
    fs = new FeatureSequence (dict, 2);
    fs.add (dict.lookupIndex ("a"));
    fs.add (dict.lookupIndex ("n"));
    fs.add (dict.lookupIndex ("d"));
    fs.add (dict.lookupIndex ("r"));
    fs.add (dict.lookupIndex ("e"));
View Full Code Here

                1, 2, 3 }),
            new FeatureVector(crf.getInputAlphabet(), new int[] {
                1, 2, 3 }),
            new FeatureVector(crf.getInputAlphabet(), new int[] {
                1, 2, 3 }), });
    FeatureSequence ss = new FeatureSequence(crf.getOutputAlphabet(),
        new int[] { 0, 1, 2, 3 });
    InstanceList ilist = new InstanceList(new Noop(inputAlphabet,
        outputAlphabet));
    ilist.add(fvs, ss, null, null);
View Full Code Here

  }
 
  public void testNewPutSizeFreeze ()
  {
    Alphabet dict = new Alphabet ();
    FeatureSequence fs = new FeatureSequence (dict, 10);
    fs.add (dict.lookupIndex ("apple"));
    fs.add (dict.lookupIndex ("bear"));
    fs.add (dict.lookupIndex ("car"));
    fs.add (dict.lookupIndex ("door"));
    assertTrue (fs.size() == 4);
    double[] weights = new double[4];
    fs.addFeatureWeightsTo (weights);
    assertTrue (weights[1] == 1.0);

    fs.add (dict.lookupIndex ("bear"));
    int[] feats = fs.toFeatureIndexSequence();
    assertTrue (feats[0] == 0);
    assertTrue (feats[1] == 1);
    assertTrue (feats[2] == 2);
    assertTrue (feats[3] == 3);
    assertTrue (feats[4] == 1);
View Full Code Here

    double logLikelihood = Double.NEGATIVE_INFINITY, prevLogLikelihood;
    for (int iter = 0; iter < numIterations; iter++) {
      prevLogLikelihood = logLikelihood;
      logLikelihood = 0;
      for (Instance inst : trainingSet) {
        FeatureSequence input = (FeatureSequence) inst.getData();
        FeatureSequence output = (FeatureSequence) inst.getTarget();
        double obsLikelihood = new SumLatticeDefault(hmm, input,
            output, hmm.new Incrementor()).getTotalWeight();
        logLikelihood += obsLikelihood;
      }
      logger.info("getValue() (observed log-likelihood) = "
          + logLikelihood);

      if (unlabeledSet != null) {
        int numEx = 0;
        for (Instance inst : unlabeledSet) {
          numEx++;
          if (numEx % 100 == 0) {
            System.err.print(numEx + ". ");
            System.err.flush();
          }
          FeatureSequence input = (FeatureSequence) inst.getData();
          double hiddenLikelihood = new SumLatticeDefault(hmm, input,
              null, hmm.new Incrementor()).getTotalWeight();
          logLikelihood += hiddenLikelihood;
        }
        System.err.println();
View Full Code Here

    trainingGatheredFor = training;
    for (int i = 0; i < training.size(); i++) {
      Instance instance = training.get(i);
      FeatureVectorSequence input = (FeatureVectorSequence) instance.getData();
      FeatureSequence output = (FeatureSequence) instance.getTarget();
      // Do it for the paths consistent with the labels...
      new SumLatticeDefault (memm, input, output, new Transducer.Incrementor() {
        public void incrementFinalState(Transducer.State s, double count) { }
        public void incrementInitialState(Transducer.State s, double count) { }
        public void incrementTransition(Transducer.TransitionIterator ti, double count) {
View Full Code Here

TOP

Related Classes of cc.mallet.types.FeatureSequence

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.