コード例 #1
0
ファイル: SerializedDumper.java プロジェクト: Ashwaray/sempre
  private LispTree exampleToLispTree(ParserState state) {
    LispTree tree = LispTree.proto.newList();
    tree.addChild("example");

    // Basic information
    Example ex = state.ex;
    if (ex.id != null) tree.addChild(LispTree.proto.newList("id", ex.id));
    if (ex.utterance != null) tree.addChild(LispTree.proto.newList("utterance", ex.utterance));
    if (ex.targetFormula != null)
      tree.addChild(LispTree.proto.newList("targetFormula", ex.targetFormula.toLispTree()));
    if (ex.targetValue != null)
      tree.addChild(LispTree.proto.newList("targetValue", ex.targetValue.toLispTree()));
    if (ex.context != null) tree.addChild(ex.context.toLispTree());

    // Language info
    if (ex.languageInfo != null) {
      if (ex.languageInfo.tokens != null)
        tree.addChild(
            LispTree.proto.newList("tokens", LispTree.proto.newList(ex.languageInfo.tokens)));
      if (ex.languageInfo.lemmaTokens != null)
        tree.addChild(
            LispTree.proto.newList(
                "lemmaTokens", LispTree.proto.newList(ex.languageInfo.lemmaTokens)));
      if (ex.languageInfo.posTags != null)
        tree.addChild(
            LispTree.proto.newList("posTags", LispTree.proto.newList(ex.languageInfo.posTags)));
      if (ex.languageInfo.nerTags != null)
        tree.addChild(
            LispTree.proto.newList("nerTags", LispTree.proto.newList(ex.languageInfo.nerTags)));
      if (ex.languageInfo.nerValues != null)
        tree.addChild(
            LispTree.proto.newList("nerValues", LispTree.proto.newList(ex.languageInfo.nerValues)));
    }

    // Derivations
    LispTree derivations = LispTree.proto.newList();
    derivations.addChild("derivations");
    List<Derivation> preds = state.predDerivations;
    for (int i = 0; i < preds.size(); i++) {
      Derivation deriv = preds.get(i);
      if (!isPruned(deriv)) {
        derivations.addChild(deriv.toLispTree());
      }
    }
    tree.addChild(derivations);

    return tree;
  }
コード例 #2
0
ファイル: ConfusionMatrices.java プロジェクト: kurige/sempre
 private void updateConfusionMatrix(
     ConfusionMatrix m, Example ex, 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;
     m.fn += gold * (1.0d - pred);
     m.fp += (1.0d - gold) * pred;
     m.tn += (1.0d - gold) * (1.0d - pred);
   }
 }