mirror of https://github.com/percyliang/sempre
Minor edits
This commit is contained in:
parent
6fdfe96db0
commit
7eff08dd0f
2
run
2
run
|
|
@ -814,7 +814,7 @@ end
|
|||
def tablesPruningStrategies
|
||||
[
|
||||
# Formula
|
||||
"singleton",
|
||||
"atomic",
|
||||
"multipleSuperlatives",
|
||||
"sameMerge",
|
||||
"forwardBackward",
|
||||
|
|
|
|||
|
|
@ -0,0 +1,36 @@
|
|||
package edu.stanford.nlp.sempre;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A group containing one or two lists of potential child derivations.
|
||||
*
|
||||
* The motivation is to group potential child derivations based on type compatibility.
|
||||
* For example, when building (and __ __), considering all pairs of derivations
|
||||
* is time-wasting since a lot of pairs don't type-check. We instead group
|
||||
* derivations by type, and only apply the rule to the pairs that type-check.
|
||||
*
|
||||
* This idea also extends to one-argument rules. For example, for (sum ___),
|
||||
* we should only look at child derivations with number type.
|
||||
*
|
||||
* During parsing, for each DerivationGroup:
|
||||
* - For a one-argument rule (derivations2 == null):
|
||||
* Apply the rule on all derivations in derivations1
|
||||
* - For a two-argument rule (derivations2 != null):
|
||||
* Apply the rule to all pairs (d1, d2) where d1 is in derivations1 and d2 is in derivations2
|
||||
*
|
||||
* @author ppasupat
|
||||
*/
|
||||
public class ChildDerivationsGroup {
|
||||
public final List<Derivation> derivations1, derivations2;
|
||||
|
||||
public ChildDerivationsGroup(List<Derivation> derivations1) {
|
||||
this.derivations1 = derivations1;
|
||||
this.derivations2 = null;
|
||||
}
|
||||
|
||||
public ChildDerivationsGroup(List<Derivation> derivations1, List<Derivation> derivations2) {
|
||||
this.derivations1 = derivations1;
|
||||
this.derivations2 = derivations2;
|
||||
}
|
||||
}
|
||||
|
|
@ -17,7 +17,7 @@ public class DefaultDerivationPruningComputer extends DerivationPruningComputer
|
|||
super(pruner);
|
||||
}
|
||||
|
||||
public static final String singleton = "singleton";
|
||||
public static final String atomic = "atomic";
|
||||
public static final String emptyDenotation = "emptyDenotation";
|
||||
public static final String nonLambdaError = "nonLambdaError";
|
||||
public static final String tooManyValues = "tooManyValues";
|
||||
|
|
@ -30,7 +30,7 @@ public class DefaultDerivationPruningComputer extends DerivationPruningComputer
|
|||
@Override
|
||||
public Collection<String> getAllStrategyNames() {
|
||||
return Arrays.asList(
|
||||
singleton,
|
||||
atomic,
|
||||
emptyDenotation, nonLambdaError, tooManyValues,
|
||||
doubleSummarizers, sameMerge, mistypedMerge, unsortedMerge, badSummarizerHead);
|
||||
}
|
||||
|
|
@ -41,10 +41,11 @@ public class DefaultDerivationPruningComputer extends DerivationPruningComputer
|
|||
|
||||
@Override
|
||||
public String isPrunedWithoutExecution(Derivation deriv) {
|
||||
// singleton: Prune singleton formula at root.
|
||||
if (containsStrategy(singleton)) {
|
||||
// atomic: Prune atomic formula at root.
|
||||
// e.g., Prevent "Who was taller, Lincoln or Obama" --> fb:en.lincoln generated from lexicon without any computation
|
||||
if (containsStrategy(atomic)) {
|
||||
if (deriv.isRoot(pruner.ex.numTokens()) && deriv.formula instanceof ValueFormula)
|
||||
return singleton;
|
||||
return atomic;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,32 +0,0 @@
|
|||
package edu.stanford.nlp.sempre;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Represents one or two lists of derivations.
|
||||
*
|
||||
* The motivation is to group derivations based on type compatibility.
|
||||
* For example, when building (and __ __), considering all pairs of derivations
|
||||
* is time-wasting since a lot of pairs don't type-check. We instead group
|
||||
* derivations by type, and only apply the rule to the pairs that type-check.
|
||||
*
|
||||
* During parsing, for each DerivationGroup:
|
||||
* - (if derivations2 == null) apply the rule on all derivations in derivations1
|
||||
* - (otherwise) apply the rule to all pairs (d1, d2) where d1 is in derivations1
|
||||
* and d2 is in derivations2
|
||||
*
|
||||
* @author ppasupat
|
||||
*/
|
||||
public class DerivationGroup {
|
||||
public final List<Derivation> derivations1, derivations2;
|
||||
|
||||
public DerivationGroup(List<Derivation> derivations1) {
|
||||
this.derivations1 = derivations1;
|
||||
this.derivations2 = null;
|
||||
}
|
||||
|
||||
public DerivationGroup(List<Derivation> derivations1, List<Derivation> derivations2) {
|
||||
this.derivations1 = derivations1;
|
||||
this.derivations2 = derivations2;
|
||||
}
|
||||
}
|
||||
|
|
@ -125,6 +125,7 @@ public class DerivationPruner {
|
|||
// Prune based on subformula
|
||||
boolean isPrunedRecursive(Derivation deriv) {
|
||||
if (!opts.recursivePruning) {
|
||||
// If recursivePruning flag is turned off, only look at the outermost layer.
|
||||
if (opts.ensureExecuted)
|
||||
deriv.ensureExecuted(parser.executor, ex.context);
|
||||
String matchedStrategy;
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ public class FloatingParser extends Parser {
|
|||
public int trainBeamSize = -1;
|
||||
@Option(gloss = "Whether to beta reduce the formula")
|
||||
public boolean betaReduce = false;
|
||||
@Option(gloss = "DEBUG: Print amounts of time spent on each rule")
|
||||
@Option(gloss = "DEBUG: Print amount of time spent on each rule")
|
||||
public boolean summarizeRuleTime = false;
|
||||
@Option(gloss = "Stop the parser if it has used more than this amount of time (in seconds)")
|
||||
public int maxFloatingParsingTime = 600;
|
||||
|
|
@ -276,18 +276,18 @@ class FloatingParserState extends ParserState {
|
|||
*
|
||||
* The rule should be applied on all derivations (or all pairs of derivations) in each DerivationGroup.
|
||||
*/
|
||||
private Collection<DerivationGroup> getFilteredDerivations(Rule rule, Object cell1, Object cell2) {
|
||||
private Collection<ChildDerivationsGroup> getFilteredDerivations(Rule rule, Object cell1, Object cell2) {
|
||||
List<Derivation> derivations1 = getDerivations(cell1),
|
||||
derivations2 = (cell2 == null) ? null : getDerivations(cell2);
|
||||
if (!FloatingParser.opts.filterChildDerivations)
|
||||
return Collections.singleton(new DerivationGroup(derivations1, derivations2));
|
||||
return Collections.singleton(new ChildDerivationsGroup(derivations1, derivations2));
|
||||
// Try to filter down the number of partial logical forms
|
||||
if (rule.getSem().supportFilteringOnTypeData())
|
||||
return rule.getSem().getFilteredDerivations(derivations1, derivations2);
|
||||
return Collections.singleton(new DerivationGroup(derivations1, derivations2));
|
||||
return Collections.singleton(new ChildDerivationsGroup(derivations1, derivations2));
|
||||
}
|
||||
|
||||
private Collection<DerivationGroup> getFilteredDerivations(Rule rule, Object cell) {
|
||||
private Collection<ChildDerivationsGroup> getFilteredDerivations(Rule rule, Object cell) {
|
||||
return getFilteredDerivations(rule, cell, null);
|
||||
}
|
||||
|
||||
|
|
@ -386,7 +386,7 @@ class FloatingParserState extends ParserState {
|
|||
derivLoop:
|
||||
for (int depth1 = 0; depth1 < depth; depth1++) { // sizes must add up to depth-1 (actually size-1)
|
||||
int depth2 = depth - 1 - depth1;
|
||||
for (DerivationGroup group : getFilteredDerivations(rule, floatingCell(rhs1, depth1), floatingCell(rhs2, depth2)))
|
||||
for (ChildDerivationsGroup group : getFilteredDerivations(rule, floatingCell(rhs1, depth1), floatingCell(rhs2, depth2)))
|
||||
for (Derivation deriv1 : group.derivations1)
|
||||
for (Derivation deriv2 : group.derivations2)
|
||||
if (!applyFloatingRule(rule, depth, deriv1, deriv2, deriv1.canonicalUtterance + " " + deriv2.canonicalUtterance))
|
||||
|
|
@ -396,7 +396,7 @@ class FloatingParserState extends ParserState {
|
|||
{
|
||||
derivLoop:
|
||||
for (int subDepth = 0; subDepth < depth; subDepth++) { // depth-1 <=depth-1
|
||||
for (DerivationGroup group : getFilteredDerivations(rule, floatingCell(rhs1, depth - 1), floatingCell(rhs2, subDepth)))
|
||||
for (ChildDerivationsGroup group : getFilteredDerivations(rule, floatingCell(rhs1, depth - 1), floatingCell(rhs2, subDepth)))
|
||||
for (Derivation deriv1 : group.derivations1)
|
||||
for (Derivation deriv2 : group.derivations2)
|
||||
if (!applyFloatingRule(rule, depth, deriv1, deriv2, deriv1.canonicalUtterance + " " + deriv2.canonicalUtterance))
|
||||
|
|
@ -406,7 +406,7 @@ class FloatingParserState extends ParserState {
|
|||
{
|
||||
derivLoop:
|
||||
for (int subDepth = 0; subDepth < depth - 1; subDepth++) { // <depth-1 depth-1
|
||||
for (DerivationGroup group : getFilteredDerivations(rule, floatingCell(rhs1, subDepth), floatingCell(rhs2, depth - 1)))
|
||||
for (ChildDerivationsGroup group : getFilteredDerivations(rule, floatingCell(rhs1, subDepth), floatingCell(rhs2, depth - 1)))
|
||||
for (Derivation deriv1 : group.derivations1)
|
||||
for (Derivation deriv2 : group.derivations2)
|
||||
if (!applyFloatingRule(rule, depth, deriv1, deriv2, deriv1.canonicalUtterance + " " + deriv2.canonicalUtterance))
|
||||
|
|
@ -424,7 +424,7 @@ class FloatingParserState extends ParserState {
|
|||
if (catSizeBound.getBound(rule.lhs) < depth) continue;
|
||||
StopWatch stopWatch = new StopWatch().start();
|
||||
derivLoop:
|
||||
for (DerivationGroup group : getFilteredDerivations(rule, floatingCell(rule.rhs.get(0), depth - 1)))
|
||||
for (ChildDerivationsGroup group : getFilteredDerivations(rule, floatingCell(rule.rhs.get(0), depth - 1)))
|
||||
for (Derivation deriv : group.derivations1)
|
||||
if (!applyFloatingRule(rule, depth, deriv, null, deriv.canonicalUtterance))
|
||||
break derivLoop;
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@ public abstract class SemanticFn {
|
|||
* See an example in tables.grow.ApplyFn
|
||||
*/
|
||||
public boolean supportFilteringOnTypeData() { return false; }
|
||||
public Collection<DerivationGroup> getFilteredDerivations(
|
||||
public Collection<ChildDerivationsGroup> getFilteredDerivations(
|
||||
List<Derivation> derivations1, List<Derivation> derivations2) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue