stanfordnlp/CoreNLP · error · RuntimeException
CoNLL-U file and tree file are not aligned.
Error message
CoNLL-U file and tree file are not aligned.
What it means
UniversalDependenciesFeatureAnnotator throws this when the CoNLL-U sentence graph and the corresponding tree from the parallel tree file cannot be aligned — typically the number of tokens in the semantic graph does not match the leaves of the tree. It includes the raw sentence text from the graph and the Penn string of the tree to help diagnose the mismatch.
Solutions
- Compare the printed sentence and tree in the message: count tokens vs tree leaves and find where they diverge.
- Regenerate both files from the same corpus version so tokenization matches.
- Check for blank-line misalignment near the failing sentence (message prints the offending sentence, so check surrounding blocks).
- Verify the tree file actually contains a tree for every CoNLL-U sentence (no truncation causing null t).
Example fix
// before
throw new RuntimeException("CoNLL-U file and tree file are not aligned. \n" ...);
// after (caller-side guard)
if (t == null || t.getLeaves().length != sg.vertexListSorted().size()) {
throw new IOException("Misalignment at sent_id=" + sg graphIdx + ": check blank lines in CoNLL-U/tree files");
} Defensive patterns
Strategy: validation
Validate before calling
int graphTokens = sg.vertexListSorted().size();
int treeLeaves = (t == null) ? -1 : t.getLeaves().length;
if (graphTokens != treeLeaves) throw new IllegalStateException("Token/leaf mismatch: " + graphTokens + " vs " + treeLeaves + " — check file alignment"); Try / catch
try { annotator.process(sg, t); } catch (RuntimeException e) { if (e.getMessage().startsWith("CoNLL-U file and tree file are not aligned")) { logAlignmentDiagnostic(e.getMessage()); } else { throw e; } } Prevention
- Regenerate tree and CoNLL-U files together so tokenization matches.
- Watch for multi-word token splits that change token counts.
- Diff the failing sentence (printed in the message) against the corpus source.
When it happens
Trigger: During main(), after reading an sg and a tree t from two parallel files, a length/content check on sg.vertexListSorted() vs t's leaves fails (including t == null), so the RuntimeException with both renderings is thrown.
Common situations: Tree file and CoNLL-U file from different versions of a corpus; tokenization differences (hyphens, multi-word tokens split differently); blank-line misalignment shifting all subsequent sentences; a null tree because the tree reader hit EOF or a parse error earlier in the file.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- Processed trees, but there are more trees and text is empty
- RuntimeIOException wrapping IOException
- RuntimeIOException wrapping IOException
- Cannot find matching labelled span for
- ArabicLexer: the invertible option requires a…
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/30e585150dd4bf02.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/trees/ud/UniversalDependenciesFeatureAnnotator.java:491
CoNLLUDocumentReader depReader = new CoNLLUDocumentReader();
CoNLLUDocumentWriter depWriter = new CoNLLUDocumentWriter();
Iterator<Pair<SemanticGraph, SemanticGraph>> it = depReader.getIterator(r);
Iterator<Tree> treeIt = treebankIterator(treeFile);
while (it.hasNext()) {
SemanticGraph sg = it.next().first();
Tree t = treeIt.next();
if (t == null || t.yield().size() != sg.size()) {
StringBuilder sentenceSb = new StringBuilder();
for (IndexedWord word : sg.vertexListSorted()) {
sentenceSb.append(word.get(CoreAnnotations.TextAnnotation.class));
sentenceSb.append(' ');
}
throw new RuntimeException("CoNLL-U file and tree file are not aligned. \n"
+ "Sentence: " + sentenceSb + '\n'
+ "Tree: " + ((t == null) ? "null" : t.pennString()));
}
featureAnnotator.addFeatures(sg, t, true, addUPOS);
System.out.print(depWriter.printSemanticGraph(sg, null, !escapeParens));
}
}
}
View on GitHub (pinned to 1b7edd19c4)