stanfordnlp/CoreNLP · error · IllegalStateException

allSentences != allWords

Error message

allSentences != allWords

What it means

MUCMentionExtractor.nextDoc() runs the Stanford coreference pipeline on a document: it tokenizes the raw text into allWords while gold annotations provide allSentences, then calls stanfordProcessor.annotate and requires that sentence splitting produced exactly one sentence per pre-split input sentence. When the sentence counts diverge the internal invariant is broken and an IllegalStateException is thrown, since the following loop zips the two lists index by index.

Solutions

  1. Align the pipeline properties (tokenize.whitespace, ssplit.eolonly, etc.) with the configuration used to produce the gold allWords split
  2. Verify input documents are not corrupted (missing sentence delimiters, truncated lines) in the MUC/ACE key files
  3. Catch IllegalStateException and skip/flag the offending document, logging its ID for inspection
  4. Ensure allSentences is populated only from the annotated document's SentencesAnnotation consistently with how allWords was built

Example fix

// before
Properties props = new Properties();
props.setProperty("annotators", "tokenize,ssplit,pos,lemma,ner,parse");
// after: force the splitter to respect the original line-per-sentence split
props.setProperty("annotators", "tokenize,ssplit,pos,lemma,ner,parse");
props.setProperty("ssplit.eolonly", "true");
Defensive patterns

Strategy: validation

Validate before calling

// before calling nextDoc, sanity-check document structure
List<CoreLabel> words = /* allWords built from the document */;
if (words == null || words.isEmpty()) throw new IllegalArgumentException("empty doc");
// keep the pipeline ssplit settings consistent with how allWords was split
props.setProperty("ssplit.eolonly", "true");

Try / catch

try {
  Document doc = mentionExtractor.nextDoc();
} catch (IllegalStateException e) {
  logger.warning("Skipping document with sentence-count mismatch: " + e.getMessage());
  // advance to next document
}

Prevention

When it happens

Trigger: Calling nextDoc() on a document where the annotator's sentence splitter produces a different number of sentences than the pre-split allWords list — e.g. MUC/ACE input files whose gold sentence boundaries disagree with what the tokenizer/sentence annotator derives after annotation, or a pipeline configuration that re-splits sentences.

Common situations: Running MUC/ACE coreference experiments with gold mentions but a pipeline whose ssplit settings differ from the ones used to build the gold data; documents with unusual formatting (empty lines, quote handling) that cause ssplit to merge or split sentences; version changes where the default sentence splitter behavior changed.

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


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

Appendix: source

Thrown at src/edu/stanford/nlp/dcoref/MUCMentionExtractor.java:269

                m.goldCorefClusterID = m2.goldCorefClusterID;
                break;
              } else if (m2.originalRef == -1) {
                m2.goldCorefClusterID = m2.mentionID;
                m.goldCorefClusterID = m2.goldCorefClusterID;
                break;
              } else {
                ref = m2.originalRef;
              }
            }
          }
        }
      }
    }

    docAnno.set(CoreAnnotations.SentencesAnnotation.class, allSentences);
    stanfordProcessor.annotate(docAnno);

    if(allSentences.size()!=allWords.size()) throw new IllegalStateException("allSentences != allWords");
    for(int i = 0 ; i< allSentences.size(); i++){
      List<CoreLabel> annotatedSent = allSentences.get(i).get(CoreAnnotations.TokensAnnotation.class);
      List<CoreLabel> unannotatedSent = allWords.get(i);
      List<Mention> mentionInSent = allGoldMentions.get(i);
      for (Mention m : mentionInSent){
        m.dependency = allSentences.get(i).get(SemanticGraphCoreAnnotations.EnhancedDependenciesAnnotation.class);
      }
      if(annotatedSent.size() != unannotatedSent.size()){
        throw new IllegalStateException("annotatedSent != unannotatedSent");
      }
      for (int j = 0, sz = annotatedSent.size(); j < sz; j++){
        CoreLabel annotatedWord = annotatedSent.get(j);
        CoreLabel unannotatedWord = unannotatedSent.get(j);
        if ( ! annotatedWord.get(CoreAnnotations.TextAnnotation.class).equals(unannotatedWord.get(CoreAnnotations.TextAnnotation.class))) {
          throw new IllegalStateException("annotatedWord != unannotatedWord");
        }
      }
      allWords.set(i, annotatedSent);

View on GitHub (pinned to 1b7edd19c4)