stanfordnlp/CoreNLP · error · RuntimeException
unable to find sentences in
Error message
unable to find sentences in: ${annotation} What it means
An IllegalStateException precondition check in NumberAnnotator.annotate: the input Annotation lacks the SentencesAnnotation key, meaning sentence splitting must run before the number annotator; the annotation object is at fault.
Solutions
- Include 'tokenize,ssplit' before 'number' in the annotators property
- Ensure TokensAnnotation is populated (run a tokenizer) before invoking the annotator
- Use the full StanfordCoreNLP pipeline rather than instantiating NumberAnnotator directly
Example fix
// before
props.setProperty("annotators", "number");
// after
props.setProperty("annotators", "tokenize,ssplit,number"); Defensive patterns
Strategy: validation
Validate before calling
if (!annotation.containsKey(CoreAnnotations.TokensAnnotation.class) && !annotation.containsKey(CoreAnnotations.SentencesAnnotation.class)) { pipeline.annotate(annotation); } Try / catch
try { numberAnnotator.annotate(annotation); } catch (RuntimeException e) { if (e.getMessage().contains("unable to find sentences")) { tokenizeAndSplit(annotation); numberAnnotator.annotate(annotation); } else throw e; } Prevention
- Run the full pipeline; never instantiate NumberAnnotator standalone on untokenized text
- Check annotation.containsKey(TokensAnnotation.class) before calling specialized annotators
When it happens
Trigger: Invoking NumberAnnotator.annotate() on an Annotation lacking both SentencesAnnotation and TokensAnnotation, i.e. the text was never tokenized or sentence-split.
Common situations: Running the 'number' annotator standalone without prerequisite annotators; manually constructing an Annotation from a String without running tokenize/ssplit first.
Understand the failure class
Background: "is required", "must be set", "missing required field": configuration validation errors across open-source libraries — this error's family across 36 libraries.
Related errors
- Unable to find words/tokens in
- ERROR: Relation extraction requires full syntactic analysis!
- Expected tree labels to have their heads assigned. Failed…
- unable to find words/tokens in
- CoreMap must have either a Calendar or DocDate annotation
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/542710d9b431cf21.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/pipeline/NumberAnnotator.java:86
public void annotate(Annotation annotation) {
if (VERBOSE) {
log.info("Adding number annotation ... ");
}
if (annotation.containsKey(CoreAnnotations.SentencesAnnotation.class)) {
// classify tokens for each sentence
for (CoreMap sentence : annotation.get(CoreAnnotations.SentencesAnnotation.class)) {
List<CoreLabel> tokens = sentence.get(CoreAnnotations.TokensAnnotation.class);
doOneSentenceNew(tokens, annotation, sentence);
}
if (VERBOSE) {
log.info("done. Output: " + annotation.get(CoreAnnotations.SentencesAnnotation.class));
}
} else if (annotation.containsKey(CoreAnnotations.TokensAnnotation.class)) {
List<CoreLabel> tokens = annotation.get(CoreAnnotations.TokensAnnotation.class);
doOneSentenceNew(tokens, annotation, null);
} else {
throw new RuntimeException("unable to find sentences in: " + annotation);
}
}
private void doOneSentenceNew(List<CoreLabel> words, Annotation doc, CoreMap sentence) {
List<CoreLabel> newWords = NumberSequenceClassifier.copyTokens(words, sentence);
nsc.classifyWithGlobalInformation(newWords, doc, sentence);
Iterator<? extends CoreLabel> newFLIter = newWords.iterator();
for (CoreLabel origWord : words) {
CoreLabel newWord = newFLIter.next();
String before = origWord.ner();
String newGuess = newWord.get(CoreAnnotations.AnswerAnnotation.class);
// log.info(origWord.word());
// log.info(origWord.ner());
if (VERBOSE)
log.info(newWord);
// log.info("-------------------------------------");View on GitHub (pinned to 1b7edd19c4)