Package cc.mallet.types

Examples of cc.mallet.types.InstanceList


      testSource = new LineGroupIterator (new FileReader (testFile.value), Pattern.compile ("^\\s*$"), true);
    } else {
      testSource = null;
    }

    InstanceList training = new InstanceList (pipe);
    training.addThruPipe (trainSource);
    InstanceList testing = new InstanceList (pipe);
    testing.addThruPipe (testSource);

    ACRF.Template[] tmpls = parseModelFile (modelFile.value);
    ACRFEvaluator eval = createEvaluator (evalOption.value);

    Inferencer inf = createInferencer (inferencerOption.value);
View Full Code Here


  public void testStateAddWeights() {
    Pipe p = makeSpacePredictionPipe(); // This used to be
    // MEMM.makeSpacePredictionPipe(),
    // but I don't know why -akm 12/2007
    InstanceList training = new InstanceList(p);
    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++) {
View Full Code Here

            File pageFile = getFileForPage (pageId);
            ObjectInputStream in = null;
            try {
                in = new ObjectInputStream (new FileInputStream (pageFile));
                InstanceList page = deserializePage(in);
               
                this.inMemoryPageIds[bin] = pageId;
                this.inMemoryPages[bin] = page;
            } catch (Exception e) {
                System.err.println (e);
View Full Code Here

            long startTime = System.currentTimeMillis ();
            File pageFile = getFileForPage (pageId);
            ObjectOutputStream out = null;
            try {
                out = new ObjectOutputStream (new FileOutputStream (pageFile));
                InstanceList page = this.inMemoryPages[bin];
                this.inMemoryPageIds[bin] = -1;
                this.inMemoryPages[bin] = null;

                serializePage(out, page);
View Full Code Here

     * the Instance has already been allocated, no check is made to
     * catch OutOfMemoryError.
     * @return <code>true</code> if successful
     */
    public boolean add (Instance instance) {
        InstanceList page;
        if (this.size % this.instancesPerPage == 0) {
            // this is the start of a new page, swap out the one in this pages
            // spot and create a new one
            int pageId = this.size / this.instancesPerPage;
            int bin = pageId % this.inMemoryPages.length;
            swapOut (this.inMemoryPageIds[bin]);
            page = new InstanceList (this.noopPipe);
            this.inMemoryPageIds[bin] = pageId;
            this.inMemoryPages[bin] = page;
        } else {
            page = getPageForIndex (this.size, true);
        }
        boolean ret = page.add (instance);
        if (ret) {
            this.size++;
        }
        return ret;
    }
View Full Code Here

   * This method assumes the input instance contains FeatureVectorSequence as data 
   */
  public Instance pipe(Instance carrier)
  {
    FeatureVectorSequence fvs = (FeatureVectorSequence) carrier.getData();
    InstanceList ilist = convert(carrier, (Noop) m_tokenClassifiers.getInstancePipe());
    assert (fvs.size() == ilist.size());

    // For passing instances to the token classifier, each instance's data alphabet needs to
    // match that used by the token classifier at training time.  For the resulting piped
    // instance, each instance's data alphabet needs to contain token classifier's prediction
    // as features
    FeatureVector[] fva = new FeatureVector[fvs.size()];

    for (int i = 0; i < ilist.size(); i++) {
      Instance inst = ilist.get(i);
      Classification c = m_tokenClassifiers.classify(inst, ! m_inProduction);
      LabelVector lv = c.getLabelVector();
      AugmentableFeatureVector afv1 = (AugmentableFeatureVector) inst.getData();
      int[] indices = afv1.getIndices();
      AugmentableFeatureVector afv2 = new AugmentableFeatureVector(m_dataAlphabet,
View Full Code Here

  public static InstanceList convert(InstanceList ilist, Noop alphabetsPipe)
  {
    if (ilist == null) return null;
   
    // This monstrosity is necessary b/c Classifiers obtain the data/target alphabets via pipes
    InstanceList ret = new InstanceList(alphabetsPipe);

    for (Instance inst : ilist)
      ret.add(inst);
    //for (int i = 0; i < ilist.size(); i++) ret.add(convert(ilist.get(i), alphabetsPipe));

    return ret;
  }
View Full Code Here

   * the resulting InstanceList and AugmentableFeatureVectors
   * @return list of instances, each with one AugmentableFeatureVector as data
   */
  public static InstanceList convert(Instance inst, Noop alphabetsPipe)
  {
    InstanceList ret = new InstanceList(alphabetsPipe);
    Object obj = inst.getData();
    assert(obj instanceof FeatureVectorSequence);

    FeatureVectorSequence fvs = (FeatureVectorSequence) obj;
    LabelSequence ls = (LabelSequence) inst.getTarget();
    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));

      ret.add(toAdd);
    }

    return ret;
  }
View Full Code Here

    for (int i = 0; i < numStates; i++)
      stateNames[i] = "state" + i;
    crf.addFullyConnectedStates(stateNames);
    CRFTrainerByLabelLikelihood crft = new CRFTrainerByLabelLikelihood(crf);
    Optimizable.ByGradientValue mcrf = crft
        .getOptimizableCRF(new InstanceList(null));
    TestOptimizable.testGetSetParameters(mcrf);
  }
View Full Code Here

                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);

    crf.addFullyConnectedStates(stateNames);
    CRFTrainerByLabelLikelihood crft = new CRFTrainerByLabelLikelihood(crf);
    crft.setUseSparseWeights(false);
View Full Code Here

TOP

Related Classes of cc.mallet.types.InstanceList

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.