stanfordnlp/CoreNLP · error · RuntimeException
Could not find root
Error message
Could not find root
What it means
ParseAndPrintMatrices.findRootTree scans the vector map for a subtree labeled ROOT and throws RuntimeException if none exists. The DV model normally attaches a ROOT vector to every parsed tree, so its absence means the vectors map is malformed or came from an unexpected source.
Solutions
- Ensure the parsed tree's root label is exactly "ROOT" before extracting matrices (relabel TOP to ROOT if needed)
- Check that the vectors map comes from DVModelReranker.Query.getDeepTrees() rather than a hand-built map
- Handle/avoid empty inputs that produce no vectors
Example fix
// before
Tree root = findRootTree(vectors); // throws if label is TOP
// after
for (Tree t : vectors.keySet()) { if (t.label().value().equals("TOP")) t.label().setValue("ROOT"); }
Tree root = findRootTree(vectors); Defensive patterns
Strategy: validation
Validate before calling
Tree findRootTreeSafe(IdentityHashMap<Tree, SimpleMatrix> vectors) {
for (Tree t : vectors.keySet()) {
String v = t.label().value();
if (v.equals("ROOT") || v.equals("TOP")) return t;
}
throw new IllegalArgumentException("No ROOT/TOP node in vector map");
} Type guard
boolean hasRoot(IdentityHashMap<Tree, SimpleMatrix> vectors) {
return vectors.keySet().stream().anyMatch(t -> t.label().value().equals("ROOT"));
} Try / catch
try {
Tree root = findRootTree(vectors);
} catch (RuntimeException e) {
System.err.println("Tree missing ROOT node: " + e.getMessage());
} Prevention
- Normalize tree labels (TOP -> ROOT) before running matrix extraction
- Use vectors from DVModelReranker.Query.getDeepTrees() only
- Check that the tree is non-empty before processing
When it happens
Trigger: Calling findRootTree(vectors) (directly or via rootTree) with an IdentityHashMap built from trees whose top node label is not exactly "ROOT" (e.g. "TOP" or a null/empty label), or an empty map.
Common situations: Trees preprocessed or re-labeled by another tool (some treebanks use TOP instead of ROOT); passing partial vectors from a custom reranker query; empty tree input.
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
- Expected a DVModelReranker
- Expected a LexicalizedParser with a DVModel attached
- Expected a LexicalizedParser with a Reranker attached
- Expected a RerankingParserQuery
- Must supply either a base parser model with -parser or a…
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/4198d8a4488c14de.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/parser/dvparser/ParseAndPrintMatrices.java:62
}
public static void outputTreeMatrices(BufferedWriter bout, Tree tree, IdentityHashMap<Tree, SimpleMatrix> vectors) throws IOException {
if (tree.isPreTerminal() || tree.isLeaf()) {
return;
}
for (int i = tree.children().length - 1; i >= 0; i--) {
outputTreeMatrices(bout, tree.children()[i], vectors);
}
outputMatrix(bout, vectors.get(tree));
}
public static Tree findRootTree(IdentityHashMap<Tree, SimpleMatrix> vectors) {
for (Tree tree : vectors.keySet()) {
if (tree.label().value().equals("ROOT")) {
return tree;
}
}
throw new RuntimeException("Could not find root");
}
public static void main(String[] args) throws IOException {
String modelPath = null;
String outputPath = null;
String inputPath = null;
String testTreebankPath = null;
FileFilter testTreebankFilter = null;
List<String> unusedArgs = Generics.newArrayList();
for (int argIndex = 0; argIndex < args.length; ) {
if (args[argIndex].equalsIgnoreCase("-model")) {
modelPath = args[argIndex + 1];
argIndex += 2;
} else if (args[argIndex].equalsIgnoreCase("-output")) {View on GitHub (pinned to 1b7edd19c4)