stanfordnlp/CoreNLP · error · RuntimeException

Mismatch between number of lemmas and number of input lines.

Error message

Mismatch between number of lemmas and number of input lines.

What it means

Same loop as error 337: after consuming the morpho analyses, the code verifies a parallel lemma iterator still has an entry for each tree line and throws this RuntimeException when the lemma file has fewer entries than the tree input.

Solutions

  1. Ensure the lemma file has exactly one entry per input tree line
  2. Regenerate both lemma and morpho files from the same treebank version
  3. Verify no preprocessing dropped lines from only the lemma file

Example fix

// before
wc -l lemmas.txt  # 990
wc -l trees.txt   # 1000
// after
wc -l lemmas.txt  # 1000 (regenerate to match)
Defensive patterns

Strategy: validation

Validate before calling

if (nTreeLines != nLemmaLines) throw new IllegalStateException("trees=" + nTreeLines + " lemmas=" + nLemmaLines);

Try / catch

try { process(); } catch (RuntimeException e) { log.error("Lemma/tree count mismatch: " + e.getMessage()); System.exit(2); }

Prevention

When it happens

Trigger: Running AddMorphoAnnotations where the lemma file is shorter than the tree file, so after morphTags are consumed the lemma iterator is exhausted mid-loop.

Common situations: Truncated lemma file, lemma and morpho files generated from different corpus versions, accidental line filtering.

Understand the failure class

Background: EmptyResultError / "no results found": when an API or scraper succeeds but returns zero rows — this error's family across 9 libraries.

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/international/morph/AddMorphoAnnotations.java:176

    YieldIterator morphIter = new YieldIterator(parsedArgs[0], isMorphTreeFile);
    YieldIterator lemmaIter = new YieldIterator(parsedArgs[1], false);
    
    final Pattern pParenStripper = Pattern.compile("[\\(\\)]");
        
    try {
      BufferedReader brIn = new BufferedReader(new InputStreamReader(System.in, encoding));
      TreeReaderFactory trf = new ArabicTreeReaderFactory.ArabicRawTreeReaderFactory(true);

      int nTrees = 0;
      for(String line; (line = brIn.readLine()) != null; ++nTrees) {
        Tree tree = trf.newTreeReader(new StringReader(line)).readTree();
        List<Tree> leaves = tree.getLeaves();
        if(!morphIter.hasNext()) {
          throw new RuntimeException("Mismatch between number of morpho analyses and number of input lines.");
        }
        List<String> morphTags = morphIter.next();
        if (!lemmaIter.hasNext()) {
          throw new RuntimeException("Mismatch between number of lemmas and number of input lines.");
        }
        List<String> lemmas = lemmaIter.next();
         
        // Sanity checks
        assert morphTags.size() == lemmas.size();
        assert lemmas.size() == leaves.size();
        
        for(int i = 0; i < leaves.size(); ++i) {
          String morphTag = morphTags.get(i);
          if (pParenStripper.matcher(morphTag).find()) {
            morphTag = pParenStripper.matcher(morphTag).replaceAll("");
          }
          String newLeaf = String.format("%s%s%s%s%s", leaves.get(i).value(),
              MorphoFeatureSpecification.MORPHO_MARK,
              lemmas.get(i),
              MorphoFeatureSpecification.LEMMA_MARK,
              morphTag);
          leaves.get(i).setValue(newLeaf);

View on GitHub (pinned to 1b7edd19c4)