{"record":{"id":"66caa866bc537195","repo":"stanfordnlp/CoreNLP","slug":"parser-requires-words-with-part-of-speech-tag-anno","errorCode":null,"errorMessage":"Parser requires words with part-of-speech tag annotations","messagePattern":"Parser requires words with part-of-speech tag annotations","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/parser/nndep/DependencyParser.java","lineNumber":1064,"sourceCode":"  }\n\n  /**\n   * Convenience method for {@link #predict(edu.stanford.nlp.util.CoreMap)}. The tokens of the provided sentence must\n   * also have tag annotations (the parser requires part-of-speech tags).\n   *\n   * @see #predict(edu.stanford.nlp.util.CoreMap)\n   */\n  public GrammaticalStructure predict(List<? extends HasWord> sentence) {\n    CoreLabel sentenceLabel = new CoreLabel();\n    List<CoreLabel> tokens = new ArrayList<>();\n\n    int i = 1;\n    for (HasWord wd : sentence) {\n      CoreLabel label;\n      if (wd instanceof CoreLabel) {\n        label = (CoreLabel) wd;\n        if (label.tag() == null)\n          throw new IllegalArgumentException(\"Parser requires words \" +\n              \"with part-of-speech tag annotations\");\n      } else {\n        label = new CoreLabel();\n        label.setValue(wd.word());\n        label.setWord(wd.word());\n\n        if (!(wd instanceof HasTag))\n          throw new IllegalArgumentException(\"Parser requires words \" +\n              \"with part-of-speech tag annotations\");\n\n        label.setTag(((HasTag) wd).tag());\n      }\n\n      label.setIndex(i);\n      i++;\n\n      tokens.add(label);\n    }","sourceCodeStart":1046,"sourceCodeEnd":1082,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/parser/nndep/DependencyParser.java#L1046-L1082","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Run the POS tagger first (StanfordCoreNLP pipeline with 'tokenize,ssplit,pos,depparse') or use predictAnnotation on a CoreMap annotated with POS","Set tags on the labels: label.setTag(\"NN\") before calling predict","Pre-tag with an external tagger and ensure each word implements HasTag with a non-null tag"],"exampleFix":"// before\nCoreLabel w = new CoreLabel();\nw.setWord(\"dog\");\nparser.predict(sentenceWith(w)); // throws\n// after\nCoreLabel w = new CoreLabel();\nw.setWord(\"dog\");\nw.setTag(\"NN\");\nparser.predict(sentenceWith(w));","handlingStrategy":"validation","validationCode":"for (CoreLabel w : sentence) {\n  if (w.tag() == null) throw new IllegalArgumentException(\"word missing POS: \" + w.word());\n}\nparser.predict(coreMap);","typeGuard":"boolean hasPos(CoreLabel w) { return w.tag() != null && !w.tag().isEmpty(); }","tryCatchPattern":"try {\n  parser.predict(sentence);\n} catch (IllegalArgumentException e) {\n  // run POS tagging then retry, or report under-tagged input\n}","preventionTips":["Use the full CoreNLP pipeline: tokenize,ssplit,pos,depparse","Set tags manually on CoreLabels when constructing sentences in code","Validate POS tags before handing sentences to the parser"],"tags":["java","illegal-argument","nndep","pos-tags"],"backgroundTag":"missing-required-argument","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}