Package edu.stanford.nlp.sempre

Examples of edu.stanford.nlp.sempre.Derivation


                                     double compatDecisionThreshold,
                                     double probDecisionThreshold) {
    List<Derivation> derivations = ex.getPredDerivations();
    double[] probs = Derivation.getProbs(derivations, 1.0d);
    for (int i = 0; i < derivations.size(); i++) {
      Derivation deriv = derivations.get(i);
      double gold, pred;
      if (compatDecisionThreshold == -1.0d)
        gold = deriv.getCompatibility();
      else
        gold = (deriv.getCompatibility() > compatDecisionThreshold) ? 1.0d : 0.0d;
      if (probDecisionThreshold == -1.0d)
        pred = probs[i];
      else
        pred = (probs[i] > probDecisionThreshold) ? 1.0d : 0.0d;
      m.tp += gold * pred;
 
View Full Code Here


      List<Derivation> firstDerivs = first.getPredDerivations();

      LogInfo.logs("STAT %s", first.getEvaluation().summary());

      for (int j = 0; j < firstDerivs.size(); j++) {
        Derivation firstDeriv = firstDerivs.get(j);
        LogInfo.begin_track("Ex %d, derivation %d", i, j);
        if (firstDeriv.getCompatibility() == 1.0d)
          LogInfo.log("DERIV CORRECT");
        else
          LogInfo.log("DERIV WRONG");
        LogInfo.logs("DERIV %s", firstDeriv);

        // TODO no executor stats being written/loaded at present.
        //firstDeriv.getExecutorStats().logStats(""+j);

        List<Pair<String, Double>> topFeatures;
        List<Pair<String, Double>> botFeatures;
        if (row.size() >= 2) {
          Integer derivIndex = rowDerivIndices.get(1).get(firstDeriv);
          Derivation secondDeriv = (derivIndex == null)
                                   ? null
                                   : row.get(1).getPredDerivations().get(derivIndex);
          topFeatures = getTopFeatures(
              topN,
              params.get(0),
              params.get(1),
              firstDeriv,
              secondDeriv,
              false);
          botFeatures = getTopFeatures(
              topN,
              params.get(0),
              params.get(1),
              firstDeriv,
              secondDeriv,
              true);
        } else {
          topFeatures = getTopFeatures(
              topN,
              params.get(0),
              null,
              firstDeriv,
              null,
              false);
          botFeatures = getTopFeatures(
              topN,
              params.get(0),
              null,
              firstDeriv,
              null,
              true);
        }

        String[] positions = new String[row.size()];
        String[][] chart = new String[topFeatures.size() + botFeatures.size()][row.size()];
        String[][] totals = new String[4][row.size()];

        for (int k = 0; k < row.size(); k++) {
          Integer derivIndex = rowDerivIndices.get(k).get(firstDeriv);

          // Positions
          positions[k] = String.format("%12s", (derivIndex == null) ? "~" : ("" + derivIndex));

          // Features
          // Walk down topFeatures and up botFeatures at the same time.
          int n = Math.max(topFeatures.size(), botFeatures.size());
          for (int f = 0; f < n; f++) {
            if (f < topFeatures.size()) {
              String featureName = topFeatures.get(f).getFirst();
              double val = params.get(k).getWeight(featureName);
              chart[f][k] = String.format("%12.4f", val);
            }
            if (f < botFeatures.size()) {
              String featureName = botFeatures.get(f).getFirst();
              double val = params.get(k).getWeight(featureName);
              chart[chart.length - 1 - f][k] = String.format("%12.4f", val);
            }
          }

          // Totals
          if (derivIndex == null) {
            totals[0][k] = totals[1][k] = totals[2][k] = totals[3][k] = String.format("%12s", "~");
          } else {
            Derivation deriv = row.get(k).getPredDerivations().get(derivIndex);
            totals[0][k] = String.format("%12.4f", deriv.getScore());
            totals[1][k] = String.format("%12.4f", deriv.getProb());
            totals[2][k] = String.format("%12.4f", deriv.getCompatibility());
            totals[3][k] = String.format("%12d", deriv.getMaxBeamPosition());
          }
        }
        LogInfo.log("");

        LogInfo.logs("%-40s\t%12s%s", "POS", "", Joiner.on(' ').join(positions));
View Full Code Here

    if(ex.getPredDerivations().size()==0)
      return new TDoubleMap<EntityInstance>();

    LogInfo.begin_track("Generating entity distribtuion");
    Pair<Context,Interval> bestPair = null;
    Derivation bestDeriv = null;

    for(Derivation currDeriv: ex.getPredDerivations()) {
      Pair<Context,Interval> currPair = ParaphraseUtils.extractContextIntervalPair(currDeriv, ex);
      if(bestPair==null || firstBetter(currPair,currDeriv,bestPair,bestDeriv,ex)) {
        if(opts.verbose>=3 && bestDeriv != null)
          LogInfo.logs("ParaphraseLearner: replacing context %s with formula %s for context %s with formula %s",bestPair,bestDeriv.formula,currPair,currDeriv.formula);
        bestPair = currPair;
        bestDeriv = currDeriv;
      }
    }

    TDoubleMap<EntityInstance> res = new TDoubleMap<EntityInstance>();
    Context bestContext = bestPair.getFirst();
    Interval bestInterval = bestPair.getSecond();
    EntityInstance entityInstance = new EntityInstance(bestContext,
        ex.languageInfo.lemmaPhrase(bestInterval.start, bestInterval.end),
        bestInterval, bestDeriv.formula, bestDeriv.getAllFeatureVector(),bestDeriv.type);

    if(opts.verbose>=3)
      LogInfo.logs("ParaphraseLearner: generated entity instance=%s",entityInstance);
    res.put(entityInstance, 1.0);
    LogInfo.end_track();
View Full Code Here

TOP

Related Classes of edu.stanford.nlp.sempre.Derivation

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.