Package cc.mallet.types

Examples of cc.mallet.types.Instance


      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 x = 0; x < t2.size(); x++) {
          logger.info("xxx pred:" + t2.getClassification(x).getLabeling().getBestLabel() + " true:" + t2.getClassification(x).getInstance().getLabeling());
        }*/
       
        for (int i = 0; i < fold[1].size(); i++) {
          Instance inst = fold[1].get(i);
          m_table.put(inst.getName(), foldClassifier);
        }
      }
    }
View Full Code Here

          + crf.averageTokenAccuracy(lists[0]));
      System.out.println("Testing  Accuracy after training = "
          + crf.averageTokenAccuracy(lists[1]));
      System.out.println("Training results:");
      for (int i = 0; i < lists[0].size(); i++) {
        Instance inst = lists[0].get(i);
        Sequence input = (Sequence) inst.getData();
        Sequence output = crf.transduce(input);
        System.out.println(output);
      }
      System.out.println("Testing results:");
      for (int i = 0; i < lists[1].size(); i++) {
        Instance inst = lists[1].get(i);
        Sequence input = (Sequence) inst.getData();
        Sequence output = crf.transduce(input);
        System.out.println(output);
      }
    }
  }
View Full Code Here

                                  ClusterUtils.copyAndMergeInstances(clustering,
                                                                     ii, ij),
                                  ii, ij);       
    }
    totalCount++;
    return new Instance(neighbor, null, null, null);
  }
View Full Code Here

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

                                                                    labelj),
                                  ii,
                                  new int[]{ij[random.nextInt(ij.length)]});           
    }
    totalCount++;
    return new Instance(neighbor, null, null, null);
  }
View Full Code Here

                                  ClusterUtils.copyAndMergeClusters(clustering,  labeli, labelj),
                                  sampleFromArray(clustering.getIndicesWithLabel(labeli), random, 1),
                                  sampleFromArray(clustering.getIndicesWithLabel(labelj), random, 1));           
    }
    totalCount++;
    return new Instance(neighbor, null, null, null);
  }
View Full Code Here

    int totalTokens;

    Transducer transducer = trainer.getTransducer();
    totalTokens = numCorrectTokens = 0;
    for (int i = 0; i < instances.size(); i++) {
      Instance instance = instances.get(i);
      Sequence input = (Sequence) instance.getData();
      Sequence trueOutput = (Sequence) instance.getTarget();
      assert (input.size() == trueOutput.size());
      //System.err.println ("TokenAccuracyEvaluator "+i+" length="+input.size());
      Sequence predOutput = transducer.transduce (input);
      assert (predOutput.size() == trueOutput.size());
View Full Code Here

    // here and possibly leave some instances without
    // cluster assignments.

    ArrayList<Instance> instances = new ArrayList<Instance>(instList.size());
    for (int i = 0; i < instList.size(); i++) {
      Instance ins = instList.get(i);
      SparseVector sparse = (SparseVector) ins.getData();
      if (sparse.numLocations() == 0)
        continue;

      instances.add(ins);
    }

    // Add next center that has the MAX of the MIN of the distances from
    // each of the previous j-1 centers (idea from Andrew Moore tutorial,
    // not sure who came up with it originally)

    for (int i = 0; i < numClusters; i++) {
      double max = 0;
      int selected = 0;
      for (int k = 0; k < instances.size(); k++) {
        double min = Double.MAX_VALUE;
        Instance ins = instances.get(k);
        SparseVector inst = (SparseVector) ins.getData();
        for (int j = 0; j < clusterMeans.size(); j++) {
          SparseVector centerInst = clusterMeans.get(j);
          double dist = metric.distance(centerInst, inst);
          if (dist < min)
            min = dist;

        }
        if (min > max) {
          selected = k;
          max = min;
        }
      }

      Instance newCenter = instances.remove(selected);
      clusterMeans.add((SparseVector) newCenter.getData());
    }

  }
View Full Code Here

TOP

Related Classes of cc.mallet.types.Instance

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.