stanfordnlp/CoreNLP · error · RuntimeException
Quotes size and gold size don't match!
Error message
Quotes size and gold size don't match!
What it means
XMLToAnnotation.readXMLFormat parses a quote-attribution XML corpus into quotes and a gold author list, then verifies counts match. If document.get(CoreAnnotations.QuotationsAnnotation.class).size() != goldList.size() it throws RuntimeException("Quotes size and gold size don't match!") at src/edu/stanford/nlp/quoteattribution/XMLToAnnotation.java:307. The check exists because gold entries must map 1:1 onto extracted quotes for training/evaluation Data.
Solutions
- Validate the XML quote markup (properly nested, well-formed <quote> elements) and re-run.
- Log both sizes and diff which quote index diverged; fix the offending paragraph.
- Regenerate the gold list from the same XML file version used for parsing.
- Escape/normalize special characters and whitespace so the quote tokenizer sees the same quotes as the annotator.
Example fix
// before
Data d = new XMLToAnnotation(pipeline).readXMLFormat("book.xml"); // mismatch
// after (pre-validate)
Document dom = ...; int goldCount = dom.getElementsByTagName("author").getLength();
int quoteCount = dom.getElementsByTagName("quote").getLength();
if (goldCount != quoteCount) throw new IllegalArgumentException("fix XML: quotes=" + quoteCount + " gold=" + goldCount);
Data d = new XMLToAnnotation(pipeline).readXMLFormat("book.xml"); Defensive patterns
Strategy: validation
Validate before calling
Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(xml);
int q = dom.getElementsByTagName("quote").getLength();
int g = dom.getElementsByTagName("author").getLength();
if (q != g) throw new IllegalArgumentException("XML quotes/gold mismatch: " + q + " vs " + g); Try / catch
try {
Data d = reader.readXMLFormat(file);
} catch (RuntimeException e) {
if (e.getMessage().contains("don't match")) log.severe("Fix XML quote markup in " + file);
throw e;
} Prevention
- Validate XML against the expected quote schema before ingestion
- Avoid hand-editing annotated corpora; regenerate gold after edits
- Escape special characters so quote detection matches annotation
When it happens
Trigger: Calling readXMLFormat on an XML file where the number of quote elements successfully parsed into the document differs from the number of gold author entries — e.g. nested/malformed quote tags, a quote element missing required attributes, or gold entries added for text that was not recognized as a quote.
Common situations: Hand-edited or third-party XML corpora with inconsistent quote markup; XML entities or line breaks breaking quote detection; gold annotation files not regenerated after editing the text.
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
- LogisticClassifier is only for binary classification!
- We need at least 2 extractors for ExtractorMerger to make se
- Too many columns: <columnI>/<numColumns> (offset: <offset>)
- Too few columns: <columnI>/<numColumns> (offset: <offset>)
- Sentence.toSentence: lengths differ
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/7963847612e18d95.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/quoteattribution/XMLToAnnotation.java:307
}
tokenIndex = getEndIndex(tokenIndex, tokens, nodeText) + 1;
}
}
}
}
for(Pair<Integer, String> item : mentionIdToSpeakerList) {
Mention mention = idToMention.get(item.first);
if(mention == null) {
goldList.add(new GoldQuoteInfo(-1, -1, item.second, null));
} else {
goldList.add(new GoldQuoteInfo(mention.begin, mention.end, item.second, mention.text));
}
}
//verify
if(document.get(CoreAnnotations.QuotationsAnnotation.class).size() != goldList.size()) {
throw new RuntimeException("Quotes size and gold size don't match!");
}
return new Data(goldList, personList, document);
}
}
View on GitHub (pinned to 1b7edd19c4)