diff --git a/run b/run index 2362606..f79ecfe 100755 --- a/run +++ b/run @@ -652,7 +652,7 @@ addMode('tables', 'QA on HTML tables', lambda { |e| l( }), # Fig parameters selo(:cldir, 'execDir', '_OUTPATH_', '.'), - o('overwriteExecDir'), o('addToView', 13), o('jarFiles', 'libsempre/*'), + o('overwriteExecDir'), o('addToView', 15), o('jarFiles', 'libsempre/*'), sel(:cldir, l(), '>/dev/null'), # Set environment for table execution o('executor', 'tables.lambdadcs.LambdaDCSExecutor'), @@ -660,6 +660,7 @@ addMode('tables', 'QA on HTML tables', lambda { |e| l( o('NumberFn.unitless'), o('NumberFn.alsoTestByConversion'), o('TypeInference.typeLookup', 'tables.TableTypeLookup'), o('JoinFn.specializedTypeCheck', false), o('JoinFn.typeInference', true), + o('Learner.outputPredValues'), # Value Evaluator letDefault(:eval, 'value'), sel(:eval, { @@ -741,19 +742,24 @@ addMode('tables', 'QA on HTML tables', lambda { |e| l( tablesDataPaths, # Verbosity o('FeatureVector.ignoreZeroWeight'), - o('maxPrintedPredictions', 10), o('maxPrintedTrue', 10), o('logFeaturesLimit', 10), + o('logFeaturesLimit', 10), o('LambdaDCSException.noErrorMessage'), letDefault(:verbose, 0), sel(:verbose, - l(), l( + o('maxPrintedPredictions', 1), o('maxPrintedTrue', 1), + nil), + l( + o('maxPrintedPredictions', 10), o('maxPrintedTrue', 10), o('putCellNameInCanonicalUtterance'), o('showUtterance'), nil), l( + o('maxPrintedPredictions', 10), o('maxPrintedTrue', 10), o('putCellNameInCanonicalUtterance'), o('showUtterance'), o('summarizeRuleTime'), o('summarizeDenotations'), nil), l( + o('maxPrintedPredictions', 10), o('maxPrintedTrue', 10), o('putCellNameInCanonicalUtterance'), o('showUtterance'), o('summarizeRuleTime'), o('summarizeDenotations'), o('showRules'), diff --git a/src/edu/stanford/nlp/sempre/BooleanValue.java b/src/edu/stanford/nlp/sempre/BooleanValue.java index ae478b8..497683d 100644 --- a/src/edu/stanford/nlp/sempre/BooleanValue.java +++ b/src/edu/stanford/nlp/sempre/BooleanValue.java @@ -19,6 +19,9 @@ public class BooleanValue extends Value { return tree; } + @Override public String sortString() { return "" + value; } + @Override public String pureString() { return "" + value; } + @Override public int hashCode() { return Boolean.valueOf(value).hashCode(); } @Override public boolean equals(Object o) { if (this == o) return true; diff --git a/src/edu/stanford/nlp/sempre/DateValue.java b/src/edu/stanford/nlp/sempre/DateValue.java index 56d186d..3aa71f9 100644 --- a/src/edu/stanford/nlp/sempre/DateValue.java +++ b/src/edu/stanford/nlp/sempre/DateValue.java @@ -86,6 +86,7 @@ public class DateValue extends Value { + "-" + (month == -1 ? "xx" : String.format("%02d", month)) + "-" + (day == -1 ? "xx" : String.format("%02d", day)); } + @Override public String pureString() { return isoString(); } @Override public int hashCode() { int hash = 0x7ed55d16; diff --git a/src/edu/stanford/nlp/sempre/ExampleUtils.java b/src/edu/stanford/nlp/sempre/ExampleUtils.java index 9bc16dd..91a317b 100644 --- a/src/edu/stanford/nlp/sempre/ExampleUtils.java +++ b/src/edu/stanford/nlp/sempre/ExampleUtils.java @@ -119,6 +119,29 @@ public final class ExampleUtils { out.close(); } + public static void writePredictionTSV(int iter, String group, Example ex) { + String basePath = "preds-iter" + iter + "-" + group + ".tsv"; + String outPath = Execution.getFile(basePath); + if (outPath == null) return; + PrintWriter out = IOUtils.openOutAppendHard(outPath); + + List fields = new ArrayList<>(); + fields.add(ex.id); + + if (!ex.predDerivations.isEmpty()) { + Derivation deriv = ex.predDerivations.get(0); + if (deriv.value instanceof ListValue) { + List values = ((ListValue) deriv.value).values; + for (Value v : values) { + fields.add(v.pureString().replaceAll("\\s+", " ").trim()); + } + } + } + + out.println(String.join("\t", fields)); + out.close(); + } + //read lisptree and write json public static void main(String[] args) { Dataset dataset = new Dataset(); diff --git a/src/edu/stanford/nlp/sempre/Learner.java b/src/edu/stanford/nlp/sempre/Learner.java index 6b2ce83..dc45d03 100644 --- a/src/edu/stanford/nlp/sempre/Learner.java +++ b/src/edu/stanford/nlp/sempre/Learner.java @@ -27,6 +27,8 @@ public class Learner { @Option(gloss = "Write predDerivations to examples file (huge)") public boolean outputPredDerivations = false; + @Option(gloss = "Write predicted values to a TSV file") + public boolean outputPredValues = false; @Option(gloss = "Dump all features and compatibility scores") public boolean dumpFeaturesAndCompatibility = false; @@ -148,7 +150,7 @@ public class Learner { params.update(counts); LogInfo.end_track(); } - + public void onlineLearnExampleByFormula(Example ex, List formulas) { HashMap counts = new HashMap<>(); for (Derivation deriv : ex.predDerivations) @@ -222,8 +224,11 @@ public class Learner { addFeedback(ex); // Write out examples and predictions - if (opts.outputPredDerivations && Builder.opts.parser.equals("FloatingParser")) { - ExampleUtils.writeParaphraseSDF(iter, group, ex, opts.outputPredDerivations); + if (opts.outputPredDerivations) { + ExampleUtils.writeParaphraseSDF(iter, group, ex, true); + } + if (opts.outputPredValues) { + ExampleUtils.writePredictionTSV(iter, group, ex); } // To save memory diff --git a/src/edu/stanford/nlp/sempre/NameValue.java b/src/edu/stanford/nlp/sempre/NameValue.java index 3a82556..38d99f9 100644 --- a/src/edu/stanford/nlp/sempre/NameValue.java +++ b/src/edu/stanford/nlp/sempre/NameValue.java @@ -42,6 +42,7 @@ public class NameValue extends Value { } @Override public String sortString() { return id; } + @Override public String pureString() { return description == null ? id : description; } @Override public int hashCode() { return id.hashCode(); } @Override public boolean equals(Object o) { diff --git a/src/edu/stanford/nlp/sempre/NumberValue.java b/src/edu/stanford/nlp/sempre/NumberValue.java index 6408f1b..cd48725 100644 --- a/src/edu/stanford/nlp/sempre/NumberValue.java +++ b/src/edu/stanford/nlp/sempre/NumberValue.java @@ -40,6 +40,7 @@ public class NumberValue extends Value { } @Override public String sortString() { return "" + value; } + @Override public String pureString() { return "" + value; } @Override public int hashCode() { return Double.valueOf(value).hashCode(); } @Override public boolean equals(Object o) { diff --git a/src/edu/stanford/nlp/sempre/StringValue.java b/src/edu/stanford/nlp/sempre/StringValue.java index b67c426..91ebda6 100644 --- a/src/edu/stanford/nlp/sempre/StringValue.java +++ b/src/edu/stanford/nlp/sempre/StringValue.java @@ -20,6 +20,7 @@ public class StringValue extends Value { } @Override public String sortString() { return "\"" + value + "\""; } + @Override public String pureString() { return value; } @Override public int hashCode() { return value.hashCode(); } @Override public boolean equals(Object o) { diff --git a/src/edu/stanford/nlp/sempre/UriValue.java b/src/edu/stanford/nlp/sempre/UriValue.java index baec2d6..e039898 100644 --- a/src/edu/stanford/nlp/sempre/UriValue.java +++ b/src/edu/stanford/nlp/sempre/UriValue.java @@ -20,6 +20,9 @@ public class UriValue extends Value { return tree; } + @Override public String sortString() { return "" + value; } + @Override public String pureString() { return "" + value; } + @Override public int hashCode() { return value.hashCode(); } @Override public boolean equals(Object o) { if (this == o) return true; diff --git a/src/edu/stanford/nlp/sempre/Value.java b/src/edu/stanford/nlp/sempre/Value.java index a69aa2a..486d5ec 100644 --- a/src/edu/stanford/nlp/sempre/Value.java +++ b/src/edu/stanford/nlp/sempre/Value.java @@ -24,6 +24,9 @@ public abstract class Value { // (optional) String used for sorting Values. The default is to call toString() public String sortString() { return toString(); } + // (optional) String without the LispTree structure. The default is to call toString() + public String pureString() { return toString(); } + @JsonCreator public static Value fromString(String str) { return Values.fromLispTree(LispTree.proto.parseFromString(str)); diff --git a/tables/README.md b/tables/README.md index 2197eb8..700944a 100644 --- a/tables/README.md +++ b/tables/README.md @@ -33,7 +33,7 @@ Running the code ./run @mode=tables @data=u-1 @feat=all @train=1 -maxex train,100 dev,100 - The command should take less than an hour. + The command should take less than 30 minutes. * To train on the complete development set, remove `-maxex train,100 dev,100`