{"record":{"id":"731fad26484e2fb6","repo":"stanfordnlp/CoreNLP","slug":"expected-a-binarized-tree","errorCode":null,"errorMessage":"Expected a binarized tree","messagePattern":"Expected a binarized tree","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/parser/shiftreduce/CreateTransitionSequence.java","lineNumber":95,"sourceCode":"      CoreLabel label = (CoreLabel) tree.label();\n      CoreLabel leftLabel = (CoreLabel) tree.children()[0].label();\n      CoreLabel rightLabel = (CoreLabel) tree.children()[1].label();\n      CoreLabel head = label.get(TreeCoreAnnotations.HeadWordLabelAnnotation.class);\n      CoreLabel leftHead = leftLabel.get(TreeCoreAnnotations.HeadWordLabelAnnotation.class);\n      CoreLabel rightHead = rightLabel.get(TreeCoreAnnotations.HeadWordLabelAnnotation.class);\n      if (head == null || leftHead == null || rightHead == null) {\n        throw new IllegalArgumentException(\"Expected tree labels to have their heads assigned.  Failed at: \" + tree);\n      }\n      boolean isRoot = rootOnlyStates.contains(tree.label().value());\n      if (head == leftHead) {\n        transitions.add(new BinaryTransition(tree.label().value(), BinaryTransition.Side.LEFT, isRoot));\n      } else if (head == rightHead) {\n        transitions.add(new BinaryTransition(tree.label().value(), BinaryTransition.Side.RIGHT, isRoot));\n      } else {\n        throw new IllegalArgumentException(\"Heads were incorrectly assigned: tree's head is not matched to either the right or left head\");\n      }\n    } else {\n      throw new IllegalArgumentException(\"Expected a binarized tree\");\n    }\n  }\n}\n","sourceCodeStart":77,"sourceCodeEnd":99,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/parser/shiftreduce/CreateTransitionSequence.java#L77-L99","documentation":"CreateTransitionSequence only knows how to generate transitions from binarized trees. Before processing it checks tree.label() and structure expectations; if the tree does not meet the binarized-tree shape it throws this error, since shift-reduce training transitions (with compound binarization states like @-nodes) cannot be derived from an arbitrary k-ary tree.","triggerScenarios":"Calling createTransitionSequence/createTransitionSequenceHelper with a tree that was not run through TreeBinarizer (or whose binarization symbols/label format don't match the expected binarized shape).","commonSituations":"Training directly on Penn Treebank trees without binarization; using a different label value for binarization nodes than the training options expect; reusing trees that were un-binarized (debinarized) for evaluation then accidentally fed back into training.","solutions":["Binarize each training tree with TreeBinarizer (e.g. TreeBinarizer.buildTreeBinarizer) before generating transition sequences","Ensure the binarizer's horizontal/vertical marking options match the parser's training options (e.g. binarization label @)","Do not debinarize trees before passing them to training; keep the binarized copies separate from evaluation trees"],"exampleFix":"// before\nList<Tree> trees = readTrees(); // raw k-ary trees\nList<List<Transition>> seqs = CreateTransitionSequence.createTransitionSequences(trees, op);\n\n// after\nTreeBinarizer binarizer = TreeBinarizer.buildTreeBinarizer(headFinder, op.trainOptions().pairwiseScore ... );\nList<Tree> binarized = trees.stream().map(t -> binarizer.transformTree(t)).collect(Collectors.toList());\nList<List<Transition>> seqs = CreateTransitionSequence.createTransitionSequences(binarized, op);","handlingStrategy":"validation","validationCode":"if (!isBinarized(tree)) { // check binary branching / binarization labels\n  tree = binarizer.transformTree(tree);\n}","typeGuard":"boolean isBinarized(Tree t) {\n  return t.isLeaf() || (t.children().length == 2 || (t.children().length == 1 && !t.label().value().startsWith(\"@\")));\n}","tryCatchPattern":"try {\n  transitions = CreateTransitionSequence.createTransitionSequence(tree, op);\n} catch (IllegalArgumentException e) {\n  transitions = CreateTransitionSequence.createTransitionSequence(binarizer.transformTree(tree), op);\n}","preventionTips":["Binarize once, centrally, at training-pipeline start","Keep binarized and debinarized tree copies clearly separated","Match binarizer options to parser training options"],"tags":["parser","training","treebinarization","precondition"],"backgroundTag":"invalid-argument-value","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}