{"record":{"id":"436098a8a759fff8","repo":"stanfordnlp/CoreNLP","slug":"lattice-too-big","errorCode":null,"errorMessage":"Lattice too big: ","messagePattern":"Lattice too big: ","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/parser/lexparser/LexicalizedParserQuery.java","lineNumber":348,"sourceCode":"  /**\n   * Parse a (speech) lattice with the PCFG parser.\n   *\n   * @param lr a lattice to parse\n   * @return Whether the lattice could be parsed by the grammar\n   */\n  boolean parse(HTKLatticeReader lr) {\n    TreePrint treePrint = getTreePrint();\n    PrintWriter pwOut = op.tlpParams.pw();\n    parseSucceeded = false;\n    parseNoMemory = false;\n    parseUnparsable = false;\n    parseSkipped = false;\n    parseFallback = false;\n    whatFailed = null;\n    originalSentence = null;\n    if (lr.getNumStates() > op.testOptions.maxLength + 1) {  // + 1 for boundary symbol\n      parseSkipped = true;\n      throw new UnsupportedOperationException(\"Lattice too big: \" + lr.getNumStates());\n    }\n    if (op.doPCFG) {\n      if (!pparser.parse(lr)) {\n        return parseSucceeded;\n      }\n      if (op.testOptions.verbose) {\n        pwOut.println(\"PParser output\");\n        treePrint.printTree(getBestPCFGParse(false), pwOut);\n      }\n    }\n    parseSucceeded = true;\n    return true;\n  }\n\n  /**\n   * Return the best parse of the sentence most recently parsed.\n   * This will be from the factored parser, if it was used and it succeeded\n   * else from the PCFG if it was used and succeed, else from the dependency","sourceCodeStart":330,"sourceCodeEnd":366,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/parser/lexparser/LexicalizedParserQuery.java#L330-L366","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Increase op.testOptions.maxLength to comfortably exceed lr.getNumStates() - 1 before parsing","Prune the lattice: lower weights/beam so fewer states survive (e.g. lattice pruning or k-best pruning on the ASR side)","Split a large lattice into sentence-sized sub-lattices and parse each","Check lr.getNumStates() before calling parse and fall back to n-best list parsing when too large"],"exampleFix":"// before\nparserQuery.parse(lattice, true, true); // states 200 > maxLength 40 + 1\n// after\nif (lattice.getNumStates() <= op.testOptions.maxLength + 1) {\n  parserQuery.parse(lattice, true, true);\n}","handlingStrategy":"validation","validationCode":"// Verify lattice size against the configured cap before parsing\nif (lattice.getNumStates() > op.testOptions.maxLength + 1) {\n  lattice = pruneLattice(lattice); // or raise maxLength / split the lattice\n}","typeGuard":null,"tryCatchPattern":"try {\n  parserQuery.parse(lattice, true, true);\n} catch (UnsupportedOperationException e) {\n  if (e.getMessage().startsWith(\"Lattice too big\")) return parseFromNBest(nBestList);\n  throw e;\n}","preventionTips":["Set maxLength above your lattice's expected state count","Prune ASR/OCR lattices before parsing (beam or posterior pruning)","Segment long lattices into sentence-sized chunks"],"tags":["parser","lattice","limits","java"],"backgroundTag":"value-out-of-range","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}