Package cc.mallet.types

Examples of cc.mallet.types.Instance


        new CharSequenceRemoveHTML() });
    InstanceList list = new InstanceList(pipe);
    list.addThruPipe(new FileIterator(htmldir, FileIterator.STARTING_DIRECTORIES));

    for (int index = 0; index < list.size(); index++) {
      Instance inst = list.get(index);
      System.err.println(inst.getData());
    }

  }
View Full Code Here


        for (int listIndex = 0; listIndex < this.lists.length; listIndex++) {
            if (this.lists[listIndex] != null) {
                Iterator<Instance> i = this.lists[listIndex].iterator ();
                boolean hasNext = i.hasNext ();
                while (hasNext) {
                    Instance o = i.next ();
                    buf.append (String.valueOf (o));
                    hasNext = i.hasNext ();
                    if (listIndex < this.lists.length || hasNext) {
                        buf.append (", ");
                    }
View Full Code Here

   */
  public double averageTokenAccuracy (InstanceList ilist)
  {
    double accuracy = 0;
    for (int i = 0; i < ilist.size(); i++) {
      Instance instance = ilist.get(i);
      Sequence input = (Sequence) instance.getData();
      Sequence output = (Sequence) instance.getTarget();
      assert (input.size() == output.size());
      Sequence predicted = maxLatticeFactory.newMaxLattice(this, input).bestOutputSequence();
      double pathAccuracy = Sequences.elementwiseAccuracy(output, predicted);
      accuracy += pathAccuracy;
      logger.fine ("Transducer path accuracy = "+pathAccuracy);
View Full Code Here

  public static void main (String[] args)
  {
    try {
      for (int i = 0; i < args.length; i++) {
        Instance carrier = new Instance (new File(args[i]), null, null, null);
        SerialPipes p = new SerialPipes (new Pipe[] {
          new Input2CharSequence (),
          new CharSequence2TokenSequence(new CharSequenceLexer())});
        carrier = p.newIteratorFrom (new SingleInstanceIterator(carrier)).next();
        TokenSequence ts = (TokenSequence) carrier.getData();
        System.out.println ("===");
        System.out.println (args[i]);
        System.out.println (ts.toString());
      }
    } catch (Exception e) {
View Full Code Here

  public void testPipesAreStupid ()
  {
    Pipe p1 = new StupidPipe ();
    Pipe p2 = new SimpleTaggerSentence2TokenSequence ();
    // initialize p2's dict
    p2.instanceFrom(new Instance (data, null, null, null));

    Pipe serial = new SerialPipes (new Pipe[] { p1, p2 });
    try {
      serial.getDataAlphabet ();
      assertTrue ("Test failed: Should have generated exception.", false);
View Full Code Here

  public void testConcatenatePipes ()
  {
    Pipe p1 = new StupidPipe ();
    Pipe p2 = new SimpleTagger.SimpleTaggerSentence2FeatureVectorSequence ();
    // initialize p2's dict
    p2.instanceFrom(new Instance (data, null, null, null));

    assertEquals (3, p2.getDataAlphabet ().size());

    Pipe serial = PipeUtils.concatenatePipes (p1, p2);
    Alphabet dict = serial.getDataAlphabet ();
View Full Code Here

    Pipe p1 = new StupidPipe ();
    Pipe p2 = new SimpleTagger.SimpleTaggerSentence2FeatureVectorSequence ();

    Pipe serial = PipeUtils.concatenatePipes (p1, p2);

    p2.instanceFrom(new Instance (data, null, null, null));
    assertEquals (3, serial.getDataAlphabet ().size ());
  }
View Full Code Here

    double[] predCounts = new double[instances.getTargetAlphabet().size()];
    double[] trueCounts = new double[instances.getTargetAlphabet().size()];

    int total = 0;
    for (int i = 0; i < instances.size(); i++) {
      Instance instance = instances.get(i);
      Sequence trueOutput = (Sequence) instance.getTarget();
      Sequence predOutput = (Sequence) transducer.getTransducer().transduce((Sequence)instance.getData());
      for (int j = 0; j < predOutput.size(); j++) {
        total++;
        predCounts[instances.getTargetAlphabet().lookupIndex(predOutput.get(j))]++;
        trueCounts[instances.getTargetAlphabet().lookupIndex(trueOutput.get(j))]++;
      }
View Full Code Here

        targetSubiterator = ((LabelSequence)superInstance.getTarget()).iterator();
      }
      // We are assuming sequences don't have zero length
      assert (dataSubiterator.hasNext());
      assert (targetSubiterator.hasNext());
      return new Instance (dataSubiterator.next(), targetSubiterator.next(),
          superInstance.getSource()+" tokensequence:"+count++,  null);
    }
View Full Code Here

      InstanceList trainingInstances = new InstanceList(pipe);
      for (int i = 0; i < training.size(); i++) {
        PairSampleIterator iterator = new PairSampleIterator(training
            .get(i), random, 0.5, training.get(i).getNumInstances());
        while(iterator.hasNext()) {
          Instance inst = iterator.next();
          trainingInstances.add(pipe.pipe(inst));
        }
      }
      logger.info("generated " + trainingInstances.size()
          + " training instances");
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.