stanfordnlp/CoreNLP · error · IllegalArgumentException

Parser requires words with part-of-speech tag annotations

Error message

Parser requires words with part-of-speech tag annotations

What it means

In the sentence-conversion helper used by predict/predictAnnotation, each input word that is a CoreLabel must carry a POS tag; the nndep model conditions transitions on (word, tag) pairs. If a CoreLabel has a null tag(), IllegalArgumentException is thrown because the parser cannot score transitions without tag annotations.

Solutions

  1. Run the POS tagger first (StanfordCoreNLP pipeline with 'tokenize,ssplit,pos,depparse') or use predictAnnotation on a CoreMap annotated with POS
  2. Set tags on the labels: label.setTag("NN") before calling predict
  3. Pre-tag with an external tagger and ensure each word implements HasTag with a non-null tag

Example fix

// before
CoreLabel w = new CoreLabel();
w.setWord("dog");
parser.predict(sentenceWith(w)); // throws
// after
CoreLabel w = new CoreLabel();
w.setWord("dog");
w.setTag("NN");
parser.predict(sentenceWith(w));
Defensive patterns

Strategy: validation

Validate before calling

for (CoreLabel w : sentence) {
  if (w.tag() == null) throw new IllegalArgumentException("word missing POS: " + w.word());
}
parser.predict(coreMap);

Type guard

boolean hasPos(CoreLabel w) { return w.tag() != null && !w.tag().isEmpty(); }

Try / catch

try {
  parser.predict(sentence);
} catch (IllegalArgumentException e) {
  // run POS tagging then retry, or report under-tagged input
}

Prevention

When it happens

Trigger: Calling predict()/testSet on a sentence where words are CoreLabels created without setTag(); running the parser on tokenized text where the POS annotator never ran and HasTag was not used.

Common situations: Feeding output of a tokenizer without running the POS tagger annotator in the pipeline; building CoreLabels manually in code and forgetting tag(); using a universal-dependency model that was trained with tag features on tag-less input.

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/66caa866bc537195. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/parser/nndep/DependencyParser.java:1064

  }

  /**
   * Convenience method for {@link #predict(edu.stanford.nlp.util.CoreMap)}. The tokens of the provided sentence must
   * also have tag annotations (the parser requires part-of-speech tags).
   *
   * @see #predict(edu.stanford.nlp.util.CoreMap)
   */
  public GrammaticalStructure predict(List<? extends HasWord> sentence) {
    CoreLabel sentenceLabel = new CoreLabel();
    List<CoreLabel> tokens = new ArrayList<>();

    int i = 1;
    for (HasWord wd : sentence) {
      CoreLabel label;
      if (wd instanceof CoreLabel) {
        label = (CoreLabel) wd;
        if (label.tag() == null)
          throw new IllegalArgumentException("Parser requires words " +
              "with part-of-speech tag annotations");
      } else {
        label = new CoreLabel();
        label.setValue(wd.word());
        label.setWord(wd.word());

        if (!(wd instanceof HasTag))
          throw new IllegalArgumentException("Parser requires words " +
              "with part-of-speech tag annotations");

        label.setTag(((HasTag) wd).tag());
      }

      label.setIndex(i);
      i++;

      tokens.add(label);
    }

View on GitHub (pinned to 1b7edd19c4)