stanfordnlp/CoreNLP · error · UnsupportedOperationException

Lattice too big:

Error message

Lattice too big: 

What it means

When parsing a word lattice (semiring/constrained parse via parse(WeightedLattice)), the number of lattice states is compared to op.testOptions.maxLength + 1 (one extra for the boundary symbol). If the lattice has more states than that, parsing is skipped and UnsupportedOperationException("Lattice too big: N") is thrown, since the length cap applies to lattice size rather than token count.

Solutions

  1. Increase op.testOptions.maxLength to comfortably exceed lr.getNumStates() - 1 before parsing
  2. Prune the lattice: lower weights/beam so fewer states survive (e.g. lattice pruning or k-best pruning on the ASR side)
  3. Split a large lattice into sentence-sized sub-lattices and parse each
  4. Check lr.getNumStates() before calling parse and fall back to n-best list parsing when too large

Example fix

// before
parserQuery.parse(lattice, true, true); // states 200 > maxLength 40 + 1
// after
if (lattice.getNumStates() <= op.testOptions.maxLength + 1) {
  parserQuery.parse(lattice, true, true);
}
Defensive patterns

Strategy: validation

Validate before calling

// Verify lattice size against the configured cap before parsing
if (lattice.getNumStates() > op.testOptions.maxLength + 1) {
  lattice = pruneLattice(lattice); // or raise maxLength / split the lattice
}

Try / catch

try {
  parserQuery.parse(lattice, true, true);
} catch (UnsupportedOperationException e) {
  if (e.getMessage().startsWith("Lattice too big")) return parseFromNBest(nBestList);
  throw e;
}

Prevention

When it happens

Trigger: Calling LexicalizedParserQuery.parse(WeightedLattice, boolean, ...) with a lattice whose getNumStates() exceeds maxLength + 1 — typically a lattice covering a long utterance or one with many alternative token segmentations.

Common situations: Speech-recognition / OCR output lattices spanning multiple sentences; lattices built with high token ambiguity (segmentation alternatives inflate state count); using default maxLength (40) with dense lattices that look small token-wise but are large state-wise.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/parser/lexparser/LexicalizedParserQuery.java:348

  /**
   * Parse a (speech) lattice with the PCFG parser.
   *
   * @param lr a lattice to parse
   * @return Whether the lattice could be parsed by the grammar
   */
  boolean parse(HTKLatticeReader lr) {
    TreePrint treePrint = getTreePrint();
    PrintWriter pwOut = op.tlpParams.pw();
    parseSucceeded = false;
    parseNoMemory = false;
    parseUnparsable = false;
    parseSkipped = false;
    parseFallback = false;
    whatFailed = null;
    originalSentence = null;
    if (lr.getNumStates() > op.testOptions.maxLength + 1) {  // + 1 for boundary symbol
      parseSkipped = true;
      throw new UnsupportedOperationException("Lattice too big: " + lr.getNumStates());
    }
    if (op.doPCFG) {
      if (!pparser.parse(lr)) {
        return parseSucceeded;
      }
      if (op.testOptions.verbose) {
        pwOut.println("PParser output");
        treePrint.printTree(getBestPCFGParse(false), pwOut);
      }
    }
    parseSucceeded = true;
    return true;
  }

  /**
   * Return the best parse of the sentence most recently parsed.
   * This will be from the factored parser, if it was used and it succeeded
   * else from the PCFG if it was used and succeed, else from the dependency

View on GitHub (pinned to 1b7edd19c4)