mirror of https://github.com/percyliang/sempre
Write predicted output to a TSV file.
This commit is contained in:
parent
766f6b2ada
commit
b2f0ff1aa8
12
run
12
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'),
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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<String> fields = new ArrayList<>();
|
||||
fields.add(ex.id);
|
||||
|
||||
if (!ex.predDerivations.isEmpty()) {
|
||||
Derivation deriv = ex.predDerivations.get(0);
|
||||
if (deriv.value instanceof ListValue) {
|
||||
List<Value> 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();
|
||||
|
|
|
|||
|
|
@ -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<Formula> formulas) {
|
||||
HashMap<String, Double> 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
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
|
|
|
|||
|
|
@ -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`
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue