{"record":{"id":"1b324c40ee1bc91a","repo":"stanfordnlp/CoreNLP","slug":"treebank-bad-tree-in-treebank","errorCode":null,"errorMessage":"Treebank: Bad tree in treebank!: ","messagePattern":"Treebank: Bad tree in treebank!: ","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/trees/Treebank.java","lineNumber":410,"sourceCode":"          if (tlp != null && tlp.isPunctuationTag(subtree.value())) {\n            puncts.incrementCount(subtree.firstChild().value());\n          }\n        } else if (subtree.isPhrasal()) {\n          boolean hasLeafChild = false;\n          for (Tree kt : subtree.children()) {\n            if (kt.isLeaf()) {\n              hasLeafChild = true;\n            }\n          }\n          if (hasLeafChild) {\n            numPreTerminalWithMultipleChildren++;\n            if (preTerminalMultipleChildrenEg == null) {\n              preTerminalMultipleChildrenEg = subtree;\n            }\n          }\n          cats.incrementCount(subtree.value());\n        } else {\n          throw new IllegalStateException(\"Treebank: Bad tree in treebank!: \" + subtree);\n        }\n      }\n    }\n    StringWriter sw = new StringWriter(2000);\n    PrintWriter pw = new PrintWriter(sw);\n    NumberFormat nf = NumberFormat.getNumberInstance();\n    nf.setMaximumFractionDigits(0);\n    pw.println(\"Treebank has \" + numTrees + \" trees (\" + numTreesLE40 + \" of length <= 40) and \" + numWords + \" words (tokens)\");\n    if (numTrees > 0) {\n      if (numTags != numWords) {\n        pw.println(\"  Warning! numTags differs and is \" + numTags);\n      }\n      if (roots.size() == 1) {\n        String root = (String) roots.keySet().toArray()[0];\n        pw.println(\"  The root category is: \" + root);\n      } else {\n        pw.println(\"  Warning! \" + roots.size() + \" different roots in treebank: \" + Counters.toString(roots, nf));\n        pw.println(\"  Examples:\");","sourceCodeStart":392,"sourceCodeEnd":428,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/trees/Treebank.java#L392-L428","documentation":"During textualSummary statistics collection, Treebank validates tree structure: a subtree must be either a preterminal (single child) or a normal internal node; anything else (e.g. a non-preterminal leaf or a malformed structure) is reported as a bad tree via IllegalStateException.","triggerScenarios":"Calling treebank.textualSummary() (as done after training/eval setup) when the loaded treebank contains malformed trees — typically trees where a nonterminal node has zero children or leaves appear at non-preterminal positions.","commonSituations":"Corrupted or non-penn-treebank-conformant corpus files; trees produced by buggy external tools; empty/whitespace-damaged files read into the Treebank.","solutions":["Locate the offending tree (it is printed in the message) and fix or remove it from the corpus.","Pre-validate the treebank by reading and traversing all trees before summary/training.","Re-export the data from the original source in correct PTB bracketed format."],"exampleFix":"// before\ntreebank.textualSummary(); // throws on bad tree\n// after\nfor (Tree t : treebank) { validateTree(t); } // fix data first\ntreebank.textualSummary();","handlingStrategy":"validation","validationCode":"for (Tree t : treebank) { for (Tree sub : t) { if (sub.isLeaf() && !sub.parent(t).isPreTerminal()) { log.warn(\"bad tree: \" + sub); } } }","typeGuard":null,"tryCatchPattern":"try { summary = treebank.textualSummary(); } catch (IllegalStateException e) { /* quarantine the reported tree and retry */ }","preventionTips":["Validate corpus files conform to PTB bracketed format before loading.","Regenerate trees from trusted parsers/tools, not hand-edited files.","Check one offending tree at a time using the message's subtree dump."],"tags":["nlp","treebank","data-validation"],"backgroundTag":"schema-validation-failed","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"}