Package cc.mallet.types

Examples of cc.mallet.types.FeatureVector


      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();
            int index = ti.getIndex();
            int nwi = source.weightsIndices[index].length;
            for (int wi = 0; wi < nwi; wi++) {
              int weightsIndex = source.weightsIndices[index][wi];
              for (int i = 0; i < input.numLocations(); i++) {
                int featureIndex = input.indexAtLocation(i);
                if ((globalFeatureSelection == null || globalFeatureSelection.contains(featureIndex))
                    && (featureSelections == null
                        || featureSelections[weightsIndex] == null
                        || featureSelections[weightsIndex].contains(featureIndex)))
                  weightsPresent[weightsIndex].set (featureIndex);
              }
            }
          }
          public void incrementInitialState (Transducer.State s, double count) {  }
          public void incrementFinalState (Transducer.State s, double count) {  }
        });
      }
      // ...and also do it for the paths selected by the current model (so we will get some negative weights)
      if (useSomeUnsupportedTrick && this.getParametersAbsNorm() > 0) {
        if (i == 0)
          logger.info ("CRF: Incremental training detected.  Adding weights for some unsupported features...");
        // (do this once some training is done)
        sumLatticeFactory.newSumLattice (this, input, null, new Transducer.Incrementor() {
          public void incrementTransition (Transducer.TransitionIterator ti, double count) {
            if (count < 0.2) // Only create features for transitions with probability above 0.2
              return// This 0.2 is somewhat arbitrary -akm
            State source = (CRF.State)ti.getSourceState();
            FeatureVector input = (FeatureVector)ti.getInput();
            int index = ti.getIndex();
            int nwi = source.weightsIndices[index].length;
            for (int wi = 0; wi < nwi; wi++) {
              int weightsIndex = source.weightsIndices[index][wi];
              for (int i = 0; i < input.numLocations(); i++) {
                int featureIndex = input.indexAtLocation(i);
                if ((globalFeatureSelection == null || globalFeatureSelection.contains(featureIndex))
                    && (featureSelections == null
                        || featureSelections[weightsIndex] == null
                        || featureSelections[weightsIndex].contains(featureIndex)))
                  weightsPresent[weightsIndex].set (featureIndex);
View Full Code Here


    fs.add (dict.lookupIndex ("l"));
    fs.add (dict.lookupIndex ("l"));
    fs.add (dict.lookupIndex ("u"));
    fs.add (dict.lookupIndex ("m"));
    //System.out.println (fs.toString());
    fv = new FeatureVector (fs);
    //System.out.println (fs.toString());
    //System.out.println (fv.toString());
  }
View Full Code Here

     * @throws IOException
     */
    private void serializeObject (ObjectOutputStream out, Object obj)
    throws IOException {
        if (obj instanceof FeatureVector) {
            FeatureVector features = (FeatureVector) obj;
            out.writeChar (TYPE_FEATURE_VECTOR);
            out.writeObject (features.getIndices ());
            out.writeObject (features.getValues ());
        }
        else if (obj instanceof Label) {
                out.writeChar (TYPE_LABEL);
                out.writeObject (((Label) obj).toString ());
        } else {
View Full Code Here

            obj = ldict.lookupLabel (name);
            break;
        case TYPE_FEATURE_VECTOR:
            int[] indices = (int[]) in.readObject ();
            double[] values = (double[]) in.readObject ();
            obj = new FeatureVector(getDataAlphabet (), indices, values);
            break;
        case TYPE_OBJECT:
            obj = in.readObject ();
            break;
        default:
View Full Code Here

    assert(fvs.size() == ls.size());

    Object instName = (inst.getName() == null ? "NONAME" : inst.getName());
   
    for (int j = 0; j < fvs.size(); j++) {
      FeatureVector fv = fvs.getFeatureVector(j);
      int[] indices = fv.getIndices();
      FeatureVector data = new AugmentableFeatureVector (alphabetsPipe.getDataAlphabet(),
          indices, fv.getValues(), indices.length);
      Labeling target = ls.getLabelAtPosition(j);
      String name = instName.toString() + "_@_POS_" + (j + 1);
      Object source = inst.getSource();
      Instance toAdd = alphabetsPipe.pipe(new Instance(data, target, name, source));
View Full Code Here

    crf.setParameter(1, 1, 0, 1.0); // state1 self-transition
    crf.setParameter(1, 0, 0, Transducer.IMPOSSIBLE_WEIGHT); // state1->state0

    FeatureVectorSequence fvs = new FeatureVectorSequence(
        new FeatureVector[] {
            new FeatureVector((Alphabet) crf.getInputAlphabet(),
                new double[] { 1 }),
            new FeatureVector((Alphabet) crf.getInputAlphabet(),
                new double[] { 1 }),
            new FeatureVector((Alphabet) crf.getInputAlphabet(),
                new double[] { 1 }), });

    SumLattice lattice = new SumLatticeDefault(crf, fvs, true);
    // We start in state0
    assertTrue(lattice.getGammaProbability(0, crf.getState(0)) == 1.0);
View Full Code Here

    crf.setParameter(1, 1, 0, 1.0); // state1 self-transition
    crf.setParameter(1, 0, 0, Transducer.IMPOSSIBLE_WEIGHT); // state1->state0

    FeatureVectorSequence fvs = new FeatureVectorSequence(
        new FeatureVector[] {
            new FeatureVector((Alphabet) crf.getInputAlphabet(),
                new double[] { 1 }),
            new FeatureVector((Alphabet) crf.getInputAlphabet(),
                new double[] { 1 }),
            new FeatureVector((Alphabet) crf.getInputAlphabet(),
                new double[] { 1 }), });

    MaxLattice lattice = new MaxLatticeDefault(crf, fvs);
    Sequence<Transducer.State> viterbiPath = lattice.bestStateSequence();
    // We start in state0
View Full Code Here

    CRF crf = new CRF(inputAlphabet, outputAlphabet);
    CRF saveCRF = crf;
    // inputAlphabet = (Feature.Alphabet) crf.getInputAlphabet();
    FeatureVectorSequence fvs = new FeatureVectorSequence(
        new FeatureVector[] {
            new FeatureVector(crf.getInputAlphabet(), new int[] {
                1, 2, 3 }),
            new FeatureVector(crf.getInputAlphabet(), new int[] {
                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));
View Full Code Here

        }

        for (int j = 0; j < s.trainingSet.size(); j++) {
          Instance instance = s.trainingSet.get (j);
          double instWeight = s.trainingSet.getInstanceWeight (j);
          FeatureVector fv = (FeatureVector) instance.getData ();
          String labelString = (String) instance.getTarget ();
          TransitionIterator iter = new TransitionIterator (s, fv, gatherConstraints?labelString:null, memm);
          while (iter.hasNext ()) {
            // gsc
            iter.nextState(); // advance the iterator
View Full Code Here

            }
          }
        }

        if (viterbiOutputStream != null) {
          FeatureVector fv = (FeatureVector) input.get(j);
          //viterbiOutputStream.println (tokens.charAt(j)+" "+trueOutput.get(j).toString()+
          //'/'+predOutput.get(j).toString()+"  "+ fv.toString(true));
          if (sourceTokenSequence != null)
            viterbiOutputStream.print (sourceTokenSequence.get(j).getText()+": ");
          viterbiOutputStream.println (trueOutput.get(j).toString()+
                                       '/'+predOutput.get(j).toString()+"  "+ fv.toString(true));
           
        }
      }
    }
    DecimalFormat f = new DecimalFormat ("0.####");
View Full Code Here

TOP

Related Classes of cc.mallet.types.FeatureVector

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.