From a9ab6c8f7a0f1d4e36078c57ec5b91f532443784 Mon Sep 17 00:00:00 2001 From: Sida Wang Date: Tue, 4 Apr 2017 18:13:22 -0700 Subject: [PATCH] bug fix for more numbers and colors --- interactive/analyze_definitions.ipynb | 29 +++++++++++++++++-- interactive/run | 10 +++---- interactive/voxelurn.grammar | 2 +- src/edu/stanford/nlp/sempre/Derivation.java | 2 +- src/edu/stanford/nlp/sempre/Trie.java | 5 ++-- .../nlp/sempre/interactive/DALAnalyzer.java | 1 - .../nlp/sempre/interactive/DALExecutor.java | 22 +------------- .../sempre/interactive/GrammarInducer.java | 2 +- .../sempre/interactive/InteractiveMaster.java | 5 ++++ .../nlp/sempre/interactive/Simulator.java | 4 +++ 10 files changed, 48 insertions(+), 34 deletions(-) diff --git a/interactive/analyze_definitions.ipynb b/interactive/analyze_definitions.ipynb index 6e27a06..bf5d4c0 100644 --- a/interactive/analyze_definitions.ipynb +++ b/interactive/analyze_definitions.ipynb @@ -16,12 +16,28 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 39, "metadata": { "collapsed": false, "scrolled": false }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "887\n", + "log.file\tstate/execs/887.exec/log\n", + "Simulator.reqParams\tgrammar=1&cite=1&learn=1&logging=0\n", + "Simulator.logFiles\t./interactive/queries/freebuildbig-0206.def.json.gz\n", + "500 lines in plotInfo\n", + "[]\n", + "errors:20, stats.uncaught_error:0\n", + "{'total_rules': 608, 'total_failed': 151, 'total_def_queries': 480, 'total_body': 1812}\n", + "failpercent: 0.0833\n" + ] + } + ], "source": [ "import csv\n", "import numpy as np\n", @@ -79,6 +95,15 @@ "\n", "print_stats()" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] } ], "metadata": { diff --git a/interactive/run b/interactive/run index 06f92d2..59ebb59 100755 --- a/interactive/run +++ b/interactive/run @@ -106,7 +106,7 @@ l('python ./#{$path}/community-server/install-deps.py'), nil)}) addMode('community', 'start the community server', lambda { |e| l( -l('python ./#{$path}/community-server/server.py -- port 8403'), +l("python ./#{$path}/community-server/server.py -- port 8403"), nil)}) addMode('simulator', 'run the simulator', lambda { |e| l( @@ -171,10 +171,10 @@ addMode('voxelurn', 'interactive semantic parsing in a VoxelWorld', lambda { |e| o('Parser.pruneErrorValues', true), o('Parser', 'interactive.BeamFloatingParser'), o('Parser.callSetEvaluation', false), - o('Parser.coarsePrune', 'false'), + o('Parser.coarsePrune', 'true'), o('Parser.beamSize', 50), - o('BeamFloatingParser.maxNewTreesPerSpan', 10000), + o('BeamFloatingParser.maxNewTreesPerSpan', 5001), o('ParserState.customExpectedCounts', 'None'), selo(0, 'BeamFloatingParser.floatStrategy', 'Never', 'NoParse', 'Always'), @@ -216,8 +216,8 @@ addMode('voxelurn', 'interactive semantic parsing in a VoxelWorld', lambda { |e| o('NumberFn.allowedRange', 0, 100), o('SimpleLexicon.inPaths', "./#{$path}/csscolors.lexicon"), - # o('Grammar.tags', 'morecolors'), - # o('Grammar.tags', 'morenumbers', 'morecolors'), + #o('Grammar.tags', 'morenumbers', 'morecolors'), + o('Grammar.tags', 'morecolors', 'morenumbers'), lambda { |e| system 'mkdir -p ./int-output/'; nil}, lambda { |e| system 'mkdir -p ./int-output/log/'; nil}, diff --git a/interactive/voxelurn.grammar b/interactive/voxelurn.grammar index c5c1792..a284d3b 100644 --- a/interactive/voxelurn.grammar +++ b/interactive/voxelurn.grammar @@ -56,7 +56,7 @@ (rule $Number ($TOKEN) (NumberFn) (anchored 1))) (when morecolors - (rule $Color ($TOKEN) (SimpleLexiconFn (type color)) (anchored 1))) + (rule $Color ($TOKEN) (SimpleLexiconFn) (anchored 1))) (when (not morenumbers) (for @num (0 1 2 3 4 5 6 7 8 9 10) diff --git a/src/edu/stanford/nlp/sempre/Derivation.java b/src/edu/stanford/nlp/sempre/Derivation.java index c3ca601..4c0ae1d 100644 --- a/src/edu/stanford/nlp/sempre/Derivation.java +++ b/src/edu/stanford/nlp/sempre/Derivation.java @@ -541,7 +541,7 @@ public class Derivation implements SemanticFn.Callable, HasScore { } public boolean allAnchored() { - if (rule.isFloating() || rule.isInduced() || !this.allAnchored) { + if (rule.isInduced() || !this.allAnchored) { this.allAnchored = false; return false; } else { diff --git a/src/edu/stanford/nlp/sempre/Trie.java b/src/edu/stanford/nlp/sempre/Trie.java index 4c2f2ee..86103d0 100644 --- a/src/edu/stanford/nlp/sempre/Trie.java +++ b/src/edu/stanford/nlp/sempre/Trie.java @@ -1,8 +1,9 @@ package edu.stanford.nlp.sempre; import java.util.ArrayList; -import java.util.HashMap; import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.Map; import java.util.Set; /** @@ -11,7 +12,7 @@ import java.util.Set; */ public class Trie { public ArrayList rules = new ArrayList<>(); - HashMap children = new HashMap<>(); + Map children = new LinkedHashMap<>(); // Set of LHS categories of all rules in this subtree public Set cats = new HashSet<>(); diff --git a/src/edu/stanford/nlp/sempre/interactive/DALAnalyzer.java b/src/edu/stanford/nlp/sempre/interactive/DALAnalyzer.java index 64c77d5..69efaad 100644 --- a/src/edu/stanford/nlp/sempre/interactive/DALAnalyzer.java +++ b/src/edu/stanford/nlp/sempre/interactive/DALAnalyzer.java @@ -25,7 +25,6 @@ public class DALAnalyzer extends LanguageAnalyzer { private static final String[] numbers = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten" }; - private static final String[] determiners = { "the", "a", "an", "that" }; @Override public LanguageInfo analyze(String utterance) { diff --git a/src/edu/stanford/nlp/sempre/interactive/DALExecutor.java b/src/edu/stanford/nlp/sempre/interactive/DALExecutor.java index ef750f7..54aecdc 100644 --- a/src/edu/stanford/nlp/sempre/interactive/DALExecutor.java +++ b/src/edu/stanford/nlp/sempre/interactive/DALExecutor.java @@ -13,27 +13,7 @@ import com.google.common.collect.Lists; import com.google.common.collect.ObjectArrays; import com.google.common.collect.Sets; -import edu.stanford.nlp.sempre.ActionFormula; -import edu.stanford.nlp.sempre.AggregateFormula; -import edu.stanford.nlp.sempre.ArithmeticFormula; -import edu.stanford.nlp.sempre.BooleanValue; -import edu.stanford.nlp.sempre.CallFormula; -import edu.stanford.nlp.sempre.ContextValue; -import edu.stanford.nlp.sempre.ErrorValue; -import edu.stanford.nlp.sempre.Executor; -import edu.stanford.nlp.sempre.Formula; -import edu.stanford.nlp.sempre.Formulas; -import edu.stanford.nlp.sempre.JoinFormula; -import edu.stanford.nlp.sempre.ListValue; -import edu.stanford.nlp.sempre.MergeFormula; -import edu.stanford.nlp.sempre.NameValue; -import edu.stanford.nlp.sempre.NotFormula; -import edu.stanford.nlp.sempre.NumberValue; -import edu.stanford.nlp.sempre.ReverseFormula; -import edu.stanford.nlp.sempre.StringValue; -import edu.stanford.nlp.sempre.SuperlativeFormula; -import edu.stanford.nlp.sempre.Value; -import edu.stanford.nlp.sempre.ValueFormula; +import edu.stanford.nlp.sempre.*; import fig.basic.LogInfo; import fig.basic.Option; diff --git a/src/edu/stanford/nlp/sempre/interactive/GrammarInducer.java b/src/edu/stanford/nlp/sempre/interactive/GrammarInducer.java index 7aaef07..404d90e 100644 --- a/src/edu/stanford/nlp/sempre/interactive/GrammarInducer.java +++ b/src/edu/stanford/nlp/sempre/interactive/GrammarInducer.java @@ -111,7 +111,7 @@ public class GrammarInducer { LogInfo.logs("Simple Packing", chartList.size()); LogInfo.logs("chartList.size = %d", chartList.size()); LogInfo.log("Potential packings: "); - this.matches.forEach(d -> LogInfo.logs("%f: %s\t", d.getScore(), d.formula)); + this.matches.forEach(d -> LogInfo.logs("%f: %s\t %s", d.getScore(), d.formula, d.allAnchored())); LogInfo.logs("packing: %s", packing); LogInfo.logs("formulaToCat: %s", formulaToCat); } diff --git a/src/edu/stanford/nlp/sempre/interactive/InteractiveMaster.java b/src/edu/stanford/nlp/sempre/interactive/InteractiveMaster.java index 138e561..a9e4cf1 100644 --- a/src/edu/stanford/nlp/sempre/interactive/InteractiveMaster.java +++ b/src/edu/stanford/nlp/sempre/interactive/InteractiveMaster.java @@ -276,7 +276,12 @@ public class InteractiveMaster extends Master { throw BadInteractionException.headIsEmpty(head); if (isNonsense(exHead)) throw BadInteractionException.nonSenseDefinition(head); + + boolean coarsePrune = Parser.opts.coarsePrune; + Parser.opts.coarsePrune = false; BeamFloatingParserState state = (BeamFloatingParserState) parser.parse(params, exHead, true); + Parser.opts.coarsePrune = coarsePrune; + if (GrammarInducer.getParseStatus(exHead) == GrammarInducer.ParseStatus.Core) throw BadInteractionException.headIsCore(head); diff --git a/src/edu/stanford/nlp/sempre/interactive/Simulator.java b/src/edu/stanford/nlp/sempre/interactive/Simulator.java index 73e0263..fce8401 100644 --- a/src/edu/stanford/nlp/sempre/interactive/Simulator.java +++ b/src/edu/stanford/nlp/sempre/interactive/Simulator.java @@ -90,6 +90,8 @@ public class Simulator implements Runnable { @Option public static boolean useThreads = false; @Option + public static long maxQueries = Long.MAX_VALUE; + @Option public static String reqParams = "grammar=0&cite=0&learn=0"; @Option public static List logFiles = null; @@ -117,6 +119,8 @@ public class Simulator implements Runnable { for (String l : lines) { numLinesRead++; + if (numLinesRead > maxQueries) + break; LogInfo.logs("Line %d", numLinesRead); if (!useThreads) { executeLine(l);