Package cc.mallet.types

Examples of cc.mallet.types.Instance


      resetExpectations();

      /* Fill in expectations for each instance */
      for (int i = 0; i < numInstances; i++)
      {
        Instance instance = trainData.get(i);

        /* Compute marginals for each clique */
        long unrollStart = System.currentTimeMillis ();
        ACRF.UnrolledGraph unrolled = new ACRF.UnrolledGraph (instance, templates, fixedTmpls);
        long unrollEnd = System.currentTimeMillis ();
        unrollTime += (unrollEnd - unrollStart);

        if (unrolled.numVariables () == 0) continue;   // Happens if all nodes are pruned.

        /* Save the expected value of each feature for when we
           compute the gradient. */
        Assignment observations = unrolled.getAssignment ();
        double value = collectExpectationsAndValue (unrolled, observations);

        if (Double.isInfinite(value))
        {
          if (initializingInfiniteValues) {
            logger.warning ("Instance " + instance.getName() +
                            " has infinite value; skipping.");
            infiniteValues.set (i);
            continue;
          } else if (!infiniteValues.get(i)) {
            logger.warning ("Infinite value on instance "+instance.getName()+
                            "returning -infinity");
            return Double.NEGATIVE_INFINITY;
/*
            printDebugInfo (unrolled);
            throw new IllegalStateException
              ("Instance " + instance.getName()+ " used to have non-infinite"
               + " value, but now it has infinite value.");
*/
          }
        } else if (Double.isNaN (value)) {
          System.out.println("NaN on instance "+i+" : "+instance.getName ());
          printDebugInfo (unrolled);
/*          throw new IllegalStateException
            ("Value is NaN in ACRF.getValue() Instance "+i);
*/
          logger.warning ("Value is NaN in ACRF.getValue() Instance "+i+" : "+
View Full Code Here


    public void collectConstraints (InstanceList ilist)
    {
      for (int inum = 0; inum < ilist.size(); inum++) {
        logger.finest ("*** Collecting constraints for instance "+inum);
        Instance inst = ilist.get (inum);
        ACRF.UnrolledGraph unrolled = new ACRF.UnrolledGraph (inst, templates, null, true);
        Assignment assn = unrolled.getAssignment ();
        collectConstraintsForGraph (unrolled, assn);
      }
    }
View Full Code Here

      i++;
      j = i + 1;
    } else {
      j++;
    }
    return new Instance(neighbor, null, null, null);
  }
View Full Code Here

        new SGML2TokenSequence()
//        new SGML2TokenSequence (new CharSequenceLexer (Pattern.compile (".")), "O")
        });

      for (int i = 0; i < args.length; i++) {
        Instance carrier = p.instanceFrom(new Instance (new File(args[i]), null, null, null));
        TokenSequence data = (TokenSequence) carrier.getData();
        TokenSequence target = (TokenSequence) carrier.getTarget();
        logger.finer ("===");
        logger.info (args[i]);
        for (int j = 0; j < data.size(); j++)
          logger.info (target.get(j).getText()+" "+data.get(j).getText());
      }
View Full Code Here

  public Instance[] instancesFrom (Iterator<Instance> source)
  {
    source = this.newIteratorFrom(source);
    if (!source.hasNext())
      return new Instance[0];
    Instance inst = source.next();
    if (!source.hasNext())
      return new Instance[] {inst};
    ArrayList<Instance> ret = new ArrayList<Instance>();
    ret.add(inst);
    while (source.hasNext())
View Full Code Here

    public SimplePipeInstanceIterator (Iterator<Instance> source) {
      this.source = source;
    }
    public boolean hasNext () { return source.hasNext(); }
    public Instance next() {
      Instance input = source.next();
      if (!precondition(input))
        return input;
      else
        return pipe (input);
      }
View Full Code Here

  private boolean[][] labelConnectionsIn (InstanceList trainingSet, String start)
  {
    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

            Object data = deserializeObject (in);
            Object target = deserializeObject (in);
            Object name = in.readObject ();
            Object source = in.readObject ();
            double weight = in.readDouble ();
            page.add (new Instance (data, target, name, source), weight);
        }
       
        return page;
    }
View Full Code Here

    for (int i = 0; i < parameters.weights.length; i++)
      for (int j = parameters.weights[i].numLocations()-1; j >= 0; j--)
        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) {
View Full Code Here

    // 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,
          indices, afv1.getValues(), indices.length + m_predRanks2add.length);

      for (int j = 0; j < m_predRanks2add.length; j++) {
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.