stanfordnlp/CoreNLP · error · IllegalArgumentException

Expected a binarized tree

Error message

Expected a binarized tree

What it means

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.

Solutions

  1. Binarize each training tree with TreeBinarizer (e.g. TreeBinarizer.buildTreeBinarizer) before generating transition sequences
  2. Ensure the binarizer's horizontal/vertical marking options match the parser's training options (e.g. binarization label @)
  3. Do not debinarize trees before passing them to training; keep the binarized copies separate from evaluation trees

Example fix

// before
List<Tree> trees = readTrees(); // raw k-ary trees
List<List<Transition>> seqs = CreateTransitionSequence.createTransitionSequences(trees, op);

// after
TreeBinarizer binarizer = TreeBinarizer.buildTreeBinarizer(headFinder, op.trainOptions().pairwiseScore ... );
List<Tree> binarized = trees.stream().map(t -> binarizer.transformTree(t)).collect(Collectors.toList());
List<List<Transition>> seqs = CreateTransitionSequence.createTransitionSequences(binarized, op);
Defensive patterns

Strategy: validation

Validate before calling

if (!isBinarized(tree)) { // check binary branching / binarization labels
  tree = binarizer.transformTree(tree);
}

Type guard

boolean isBinarized(Tree t) {
  return t.isLeaf() || (t.children().length == 2 || (t.children().length == 1 && !t.label().value().startsWith("@")));
}

Try / catch

try {
  transitions = CreateTransitionSequence.createTransitionSequence(tree, op);
} catch (IllegalArgumentException e) {
  transitions = CreateTransitionSequence.createTransitionSequence(binarizer.transformTree(tree), op);
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/parser/shiftreduce/CreateTransitionSequence.java:95

      CoreLabel label = (CoreLabel) tree.label();
      CoreLabel leftLabel = (CoreLabel) tree.children()[0].label();
      CoreLabel rightLabel = (CoreLabel) tree.children()[1].label();
      CoreLabel head = label.get(TreeCoreAnnotations.HeadWordLabelAnnotation.class);
      CoreLabel leftHead = leftLabel.get(TreeCoreAnnotations.HeadWordLabelAnnotation.class);
      CoreLabel rightHead = rightLabel.get(TreeCoreAnnotations.HeadWordLabelAnnotation.class);
      if (head == null || leftHead == null || rightHead == null) {
        throw new IllegalArgumentException("Expected tree labels to have their heads assigned.  Failed at: " + tree);
      }
      boolean isRoot = rootOnlyStates.contains(tree.label().value());
      if (head == leftHead) {
        transitions.add(new BinaryTransition(tree.label().value(), BinaryTransition.Side.LEFT, isRoot));
      } else if (head == rightHead) {
        transitions.add(new BinaryTransition(tree.label().value(), BinaryTransition.Side.RIGHT, isRoot));
      } else {
        throw new IllegalArgumentException("Heads were incorrectly assigned: tree's head is not matched to either the right or left head");
      }
    } else {
      throw new IllegalArgumentException("Expected a binarized tree");
    }
  }
}

View on GitHub (pinned to 1b7edd19c4)