stanfordnlp/CoreNLP · warning

Parsing of sentence ran out of memory (length=

Error message

Parsing of sentence ran out of memory (length=

What it means

ParserAnnotator catches OutOfMemoryError thrown while parsing a single sentence and logs this warning instead of crashing the pipeline. The Stanford parser builds large chart structures, so very long sentences can exhaust the JVM heap. The failed sentence is skipped and the pipeline continues with the next one.

Solutions

  1. Increase JVM heap, e.g. java -Xmx8g, since the parser needs memory proportional to sentence length
  2. Fix sentence splitting so no absurdly long sentences are produced (check ssplit.eolonly or fix input text encoding/newlines)
  3. Cap sentence length by pre-splitting very long sentences before annotation
  4. Inspect the logged words.length value to find and repair the offending document
  5. Use the lighter depparse annotator instead of the PCFG parse for very long text

Example fix

// before
Runtime.getRuntime().exec(new String[]{"java", "-cp", "corenlp.jar", ...});
// after
Runtime.getRuntime().exec(new String[]{"java", "-Xmx8g", "-cp", "corenlp.jar", ...});
Defensive patterns

Strategy: try-catch

Validate before calling

int maxLen = 200;
if (words.size() > maxLen) {
    words = splitLongSentence(words, maxLen); // pre-split before annotation
}

Try / catch

// this error is already caught internally; to detect it downstream, check for empty parse output
// and monitor logs for "ran out of memory (length=" to identify offending documents

Prevention

When it happens

Trigger: Calling StanfordCoreNLP with the 'parse' (or 'depparse'/binarized PCFG) annotator on a document containing an extremely long sentence (hundreds of tokens) when the JVM heap is too small; doOneSentence catches OutOfMemoryError from the parse call.

Common situations: Running corenlp on web text, legal documents, or text without proper sentence segmentation, so a 'sentence' is thousands of words; running with default -Xmx on big batch jobs; sentence splitter failing on a malformed document.

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/pipeline/ParserAnnotator.java:367

        }
      } else {
        List<ScoredObject<Tree>> scoredObjects = pq.getKBestParses(this.kBest);
        if (scoredObjects == null || scoredObjects.size() < 1) {
          log.warn("Parsing of sentence failed.  " +
              "Will ignore and continue: " +
              SentenceUtils.listToString(words));
        } else {
          for (ScoredObject<Tree> so : scoredObjects) {
            // -10000 denotes unknown words
            Tree tree = so.object();
            tree.setScore(so.score() % -10000.0);
            trees.add(tree);
          }
        }
      }
    } catch (OutOfMemoryError e) {
      log.error(e); // Beware that we can now get an OOM in logging, too.
      log.warn("Parsing of sentence ran out of memory (length=" + words.size() + ").  " +
              "Will ignore and try to continue.");
    } catch (NoSuchParseException e) {
      log.warn("Parsing of sentence failed, possibly because of out of memory.  " +
              "Will ignore and continue: " +
              SentenceUtils.listToString(words));
    }
    return trees;
  }

  @Override
  public Set<Class<? extends CoreAnnotation>> requires() {
    if (parser.requiresTags()) {
      return Collections.unmodifiableSet(new ArraySet<>(Arrays.asList(
          CoreAnnotations.TextAnnotation.class,
          CoreAnnotations.TokensAnnotation.class,
          CoreAnnotations.ValueAnnotation.class,
          CoreAnnotations.OriginalTextAnnotation.class,
          CoreAnnotations.CharacterOffsetBeginAnnotation.class,

View on GitHub (pinned to 1b7edd19c4)