Package cc.mallet.types

Examples of cc.mallet.types.Instance


    }
    public boolean hasNext () {
      return doesHaveNext;
    }
    public Instance next() {
      Instance ret = nextInstance;
      doesHaveNext = false;
      while (source.hasNext()) {
          nextInstance = source.next();
          if (((FeatureVector)nextInstance.getData()).numLocations() > 0) {
            doesHaveNext = true;
View Full Code Here


  }

  public Void call() throws Exception {
    for (int ii = start; ii < end; ii++) {
      if (instancesWithConstraints.get(ii)) {
        Instance instance = data.get(ii);
        SumLatticeDefault lattice = new SumLatticeDefault(
          this.crf, (FeatureVectorSequence)instance.getData(),
          null, null, true);
        lattices.add(lattice);
      }
      else {
        lattices.add(null);
View Full Code Here

      memmt.train(lists[0], 1);
      System.out.println("Training Accuracy after training = " + memm.averageTokenAccuracy(lists[0]));
      System.out.println("Testing  Accuracy after training = " + memm.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 = memm.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 = memm.transduce (input);
        System.out.println (output);
      }
    }
  }
View Full Code Here

    int numInfWeight = 0;

    double value = 0;
    double unlabeledWeight, labeledWeight, weight;
    for (int ii = batchAssignments[0]; ii < batchAssignments[1]; ii++) {
      Instance instance = trainingSet.get(ii);
      double instanceWeight = trainingSet.getInstanceWeight(instance);
      FeatureVectorSequence input = (FeatureVectorSequence) instance.getData();
      FeatureSequence output = (FeatureSequence) instance.getTarget();

      labeledWeight = new SumLatticeDefault (this.crf, input, output, null).getTotalWeight();
      if (Double.isInfinite (labeledWeight)) {
        ++numInfLabeledWeight;
      }
View Full Code Here

        nextInstance = next();
      return nextInstance;
    }
    public Instance next () {
      if (nextInstance != null) {
        Instance tmp = nextInstance;
        nextInstance = null;
        return tmp;
      } else {
        return source.next();
      }
View Full Code Here

      for (Pipe p : pipes)
        iterators.add (new GateKeepingInstanceIterator (source, p));
    }
    public boolean hasNext () { return source.hasNext(); }
    public Instance next() {
      Instance input = source.peekNext();
      for (int i = 0; i < pipes.size(); i++) {
        if (pipes.get(i).precondition(input)) {
          return iterators.get(i).next();
        }
      }
View Full Code Here

    int numInfWeight = 0;
   
    // Calculate the value of each instance, and also fill in expectations
    double unlabeledWeight, labeledWeight, weight;
    for (int ii = 0; ii < trainingSet.size(); ii++) {
      Instance instance = trainingSet.get(ii);
      double instanceWeight = trainingSet.getInstanceWeight(instance);
      FeatureVectorSequence input = (FeatureVectorSequence) instance.getData();
      FeatureSequence output = (FeatureSequence) instance.getTarget();
      labeledWeight = new SumLatticeDefault (this.crf, input, output, (Transducer.Incrementor)null).getTotalWeight();
      String instanceName = instance.getName() == null ? "instance#"+ii : instance.getName().toString();
      //System.out.println ("labeledWeight = "+labeledWeight);
      if (Double.isInfinite (labeledWeight)) {
        ++numInfLabeledWeight;
        logger.warning (instanceName + " has -infinite labeled weight.\n"+(instance.getSource() != null ? instance.getSource() : ""));
      }
     
      Transducer.Incrementor incrementor = instanceWeight == 1.0 ? expectations.new Incrementor() : expectations.new WeightedIncrementor (instanceWeight);
      unlabeledWeight = new SumLatticeDefault (this.crf, input, null, incrementor).getTotalWeight();
      //System.out.println ("unlabeledWeight = "+unlabeledWeight);
      if (Double.isInfinite (unlabeledWeight)) {
        ++numInfUnlabeledWeight;
        logger.warning (instance.getName().toString() + " has -infinite unlabeled weight.\n"+(instance.getSource() != null ? instance.getSource() : ""));
      }
     
      // Here weight is log(conditional probability correct label sequence)
      weight = labeledWeight - unlabeledWeight;
      //System.out.println ("Instance "+ii+" CRF.MaximizableCRF.getWeight = "+weight);
View Full Code Here

    totalTokens = numCorrectTokens = 0;
    numTrueSegments = numPredictedSegments = numCorrectSegments = 0;
    numCorrectSegmentsInAlphabet = numCorrectSegmentsOOV = 0;
    numIncorrectSegmentsInAlphabet = numIncorrectSegmentsOOV = 0;
    for (int i = 0; i < data.size(); i++) {
      Instance instance = data.get(i);
      Sequence input = (Sequence) instance.getData();
      //String tokens = null;
      //if (instance.getSource() != null)
      //tokens = (String) instance.getSource().toString();
      Sequence trueOutput = (Sequence) instance.getTarget();
      assert (input.size() == trueOutput.size());
      Sequence predOutput = model.transduce (input);
      assert (predOutput.size() == trueOutput.size());
      boolean trueStart, predStart;
      for (int j = 0; j < trueOutput.size(); j++) {
View Full Code Here

    constraints = new CRF.Factors(crf.getParameters());
    expectations = new CRF.Factors(crf.getParameters());

    constraints.zero();
    for (int ii = 0; ii < trainingSet.size(); ii++) {
      Instance inst = trainingSet.get(ii);
      Sequence input = (Sequence) inst.getData();

      SumLatticePR geLatt =
        new SumLatticePR(crf, ii, input, null, auxModel, cachedDots[ii], false, null, null, true);
      double gammas[][] = geLatt.getGammas();
View Full Code Here

   
    public Double call() throws Exception {
      double value = 0;
     
      for (int ii = start; ii < end; ii++) {
        Instance inst = trainingSet.get(ii);
        Sequence input = (Sequence) inst.getData();
        double initProbs[] = initialProbList.get(ii);
        double finalProbs[] = finalProbList.get(ii);
        double transProbs[][][] = transitionProbList.get(ii);

        double[][][] cachedDots = new double[input.size()][crf.numStates()][crf.numStates()];
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.