Package cc.mallet.types

Examples of cc.mallet.types.Sequence


    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()];
        for (int j = 0; j < input.size(); j++) {
          for (int k = 0; k < crf.numStates(); k++) {
            for (int l = 0; l < crf.numStates(); l++) {
              cachedDots[j][k][l] = Transducer.IMPOSSIBLE_WEIGHT;
            }
          }
View Full Code Here


        test(new NoopTransducerTrainer(crf), eval, testData);
      }
      else {
        boolean includeInput = includeInputOption.value();
        for (int i = 0; i < testData.size(); i++) {
          Sequence input = (Sequence)testData.get(i).getData();
          Sequence[] outputs = apply(crf, input, nBestOption.value);
          int k = outputs.length;
          boolean error = false;
          for (int a = 0; a < k; a++) {
            if (outputs[a].size() != input.size()) {
              logger.info("Failed to decode input sequence " + i + ", answer " + a);
              error = true;
            }
          }
          if (! error) {
            for (int j = 0; j < input.size(); j++) {
              StringBuffer buf = new StringBuffer();
              for (int a = 0; a < k; a++) {
                buf.append(outputs[a].get(j).toString()).append(" ");
              }
              if (includeInput) {
                FeatureVector fv = (FeatureVector)input.get(j);
                buf.append(fv.toString(true));               
              }
              System.out.println(buf.toString());
            }
            System.out.println();
View Full Code Here

  }

  public double elementwiseAccuracy (Sequence referenceOutput)
  {
    int accuracy = 0;
    Sequence output = bestOutputSequence();
    assert (referenceOutput.size() == output.size());
    for (int i = 0; i < output.size(); i++) {
      //logger.fine("tokenAccuracy: ref: "+referenceOutput.get(i)+" viterbi: "+output.get(i));
      if (referenceOutput.get(i).toString().equals (output.get(i).toString())) {
        accuracy++;
      }
    }
    logger.info ("Number correct: " + accuracy + " out of " + output.size());
    return ((double)accuracy)/output.size();
  }
View Full Code Here

    return ((double)accuracy)/output.size();
  }

  public double tokenAccuracy (Sequence referenceOutput, PrintWriter out)
  {
    Sequence output = bestOutputSequence();
    int accuracy = 0;
    String testString;
    assert (referenceOutput.size() == output.size());
    for (int i = 0; i < output.size(); i++) {
      //logger.fine("tokenAccuracy: ref: "+referenceOutput.get(i)+" viterbi: "+output.get(i));
      testString = output.get(i).toString();
      if (out != null) {
        out.println(testString);
      }
      if (referenceOutput.get(i).toString().equals (testString)) {
        accuracy++;
      }
    }
    logger.info ("Number correct: " + accuracy + " out of " + output.size());
    return ((double)accuracy)/output.size();
  }
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);
    }
    return accuracy/ilist.size();
View Full Code Here

    }

    public Instance pipe(Instance carrier) {
      StringBuffer sb = new StringBuffer();
      String source = (String) carrier.getSource();
      Sequence as = (Sequence) carrier.getTarget();
      // int startLabelIndex = as.getAlphabet().lookupIndex("start");
      for (int i = 0; i < source.length(); i++) {
        System.out.println("target[" + i + "]=" + as.get(i).toString());
        if (as.get(i).toString().equals("start") && i != 0)
          sb.append(' ');
        sb.append(source.charAt(i));
      }
      carrier.setSource(sb.toString());
      System.out.println("carrier.getSource() = " + carrier.getSource());
View Full Code Here

    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))]++;
      }
    }

  NumberFormat formatter = NumberFormat.getInstance();
View Full Code Here

      else
      {
        boolean includeInput = includeInputOption.value();
        for (int i = 0; i < testData.size(); i++)
        {
          Sequence input = (Sequence)testData.get(i).getData();
          Sequence[] outputs = apply(crf, input, nBestOption.value);
          int k = outputs.length;
          boolean error = false;
          for (int a = 0; a < k; a++) {
            if (outputs[a].size() != input.size()) {
              logger.info("Failed to decode input sequence " + i + ", answer " + a);
              error = true;
            }
          }
          if (!error) {
            for (int j = 0; j < input.size(); j++)
            {
               StringBuffer buf = new StringBuffer();
              for (int a = 0; a < k; a++)
                 buf.append(outputs[a].get(j).toString()).append(" ");
              if (includeInput) {
                FeatureVector fv = (FeatureVector)input.get(j);
                buf.append(fv.toString(true));               
              }
              System.out.println(buf.toString());
            }
            System.out.println();
View Full Code Here

      else
      {
        boolean includeInput = includeInputOption.value();
        for (int i = 0; i < testData.size(); i++)
        {
          Sequence input = (Sequence)testData.get(i).getData();
          Sequence[] outputs = apply(crf, input, nBestOption.value);
          int k = outputs.length;
          boolean error = false;
          for (int a = 0; a < k; a++) {
            if (outputs[a].size() != input.size()) {
              logger.info("Failed to decode input sequence " + i + ", answer " + a);
              error = true;
            }
          }
          if (!error) {
            for (int j = 0; j < input.size(); j++)
            {
               StringBuffer buf = new StringBuffer();
              for (int a = 0; a < k; a++)
                 buf.append(outputs[a].get(j).toString()).append(" ");
              if (includeInput) {
                FeatureVector fv = (FeatureVector)input.get(j);
                buf.append(fv.toString(true));               
              }
              System.out.println(buf.toString());
            }
            System.out.println();
View Full Code Here

      klfi.induceFeaturesFor (testing, false, false);
    }
    Sequence[] ret = new Sequence[testing.size()];
    for (int i = 0; i < testing.size(); i++) {
      Instance instance = testing.get(i);
      Sequence input = (Sequence) instance.getData();
      Sequence trueOutput = (Sequence) instance.getTarget();
      assert (input.size() == trueOutput.size());
      Sequence predOutput = new MaxLatticeDefault(this, input).bestOutputSequence();
      assert (predOutput.size() == trueOutput.size());
      ret[i] = predOutput;
    }
    return ret;
  }
View Full Code Here

TOP

Related Classes of cc.mallet.types.Sequence

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.