stanfordnlp/CoreNLP · error · IllegalArgumentException

Cannot run Natural Logic forward entailment without…

Error message

Cannot run Natural Logic forward entailment without polarity annotations set. See " + NaturalLogicAnnotator.class.getSimpleName()

What it means

ForwardEntailer.apply() requires every token in the parse tree to carry the NaturalLogicAnnotations.PolarityAnnotation, which is produced upstream by the NaturalLogicAnnotator. If any token lacks the annotation, the premise cannot be projected through natural logic, so apply() throws an IllegalArgumentException before creating the search problem.

Solutions

  1. Add "natlog" to the StanfordCoreNLP pipeline properties after lemma/depparse: e.g. new StanfordCoreNLP(PropertiesUtils.asProperties("annotators", "tokenize,ssplit,pos,lemma,depparse,natlog")).
  2. Verify tokens contain PolarityAnnotation before calling apply(): check token.containsKey(NaturalLogicAnnotations.PolarityAnnotation.class).
  3. If building CoreMaps manually, run NaturalLogicAnnotator over the document first, or populate polarity annotations yourself.

Example fix

// before
Properties props = new Properties();
props.setProperty("annotators", "tokenize,ssplit,pos,lemma,parse");
// after
props.setProperty("annotators", "tokenize,ssplit,pos,lemma,parse,natlog");
Defensive patterns

Strategy: validation

Validate before calling

boolean hasPolarity = parseTree.vertexSet().stream()
    .allMatch(v -> v.backingLabel() == null || v.backingLabel().containsKey(NaturalLogicAnnotations.PolarityAnnotation.class));
if (!hasPolarity) throw new IllegalArgumentException("Run NaturalLogicAnnotator (natlog) first");

Try / catch

try {
  entailer.apply(parseTree, true);
} catch (IllegalArgumentException e) {
  throw new IllegalStateException("Pipeline missing natlog annotator: " + e.getMessage(), e);
}

Prevention

When it happens

Trigger: Calling ForwardEntailer.apply(parseTree, truth) on a SemanticGraph from a pipeline that did not run NaturalLogicAnnotator (polarity annotation missing on at least one token).

Common situations: See trigger scenarios.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10). Data as JSON: /api/errors/80ec6db9b2db34a5. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/naturalli/ForwardEntailer.java:76

  public ForwardEntailer(NaturalLogicWeights weights) {
    this(Integer.MAX_VALUE, Integer.MAX_VALUE, weights);
  }

  /**
   * Create a new search problem instance, given a sentence (possibly fragment), and the corresponding
   * parse tree.
   *
   * @param parseTree The original tree of the sentence we are beginning with
   * @param truthOfPremise The truth of the premise. In most applications, this will just be true.
   *
   * @return A new search problem instance.
   */
  @Override
  public ForwardEntailerSearchProblem apply(SemanticGraph parseTree, Boolean truthOfPremise) {
    for (IndexedWord vertex : parseTree.vertexSet()) {
      CoreLabel token = vertex.backingLabel();
      if (token != null && !token.containsKey(NaturalLogicAnnotations.PolarityAnnotation.class)) {
        throw new IllegalArgumentException("Cannot run Natural Logic forward entailment without polarity annotations set. See " + NaturalLogicAnnotator.class.getSimpleName());
      }
    }
    return new ForwardEntailerSearchProblem(parseTree, truthOfPremise, maxResults, maxTicks, weights);
  }
}

View on GitHub (pinned to 1b7edd19c4)