stanfordnlp/CoreNLP · error · RuntimeException

error loading

Error message

error loading 

What it means

In the classifier-loading option chain, when flags.loadTextClassifier is set the code calls crf.loadTextClassifier(loadTextPath, props); any Exception thrown there is wrapped in RuntimeException('error loading <path>'). It is a generic wrapper indicating the text classifier file could not be parsed or read (including the inner 'format error' / 'weights format error' cases).

Solutions

  1. Verify the loadTextClassifier path exists and is readable (ls -l, permissions).
  2. Inspect the chained cause (getCause) — the inner message ('format error', 'weights format error', IO error) tells the real problem.
  3. Confirm the file is a text-format classifier whose first line is 'weights.length=<n>'; use loadClassifier for binary models.
  4. Regenerate the text dump from the serialized model using the matching Stanford NLP version.
  5. Test loading in a small program directly calling loadTextClassifier to isolate the failing flag.

Example fix

// before
java -cp stanford-segmenter.jar ... -loadTextClassifier model.ser.gz   // wrong kind of file
// after
java -cp stanford-segmenter.jar ... -loadClassifier model.ser.gz       // binary model
// or regenerate: -loadTextClassifier model.txt with a valid text dump
Defensive patterns

Strategy: validation

Validate before calling

File f = new File(loadTextPath);
if (!f.isFile() || !f.canRead()) throw new IllegalArgumentException("loadTextClassifier path missing/unreadable: " + loadTextPath);
try (BufferedReader br = new BufferedReader(new FileReader(f))) {
  if (!br.readLine().startsWith("weights.length="))
    throw new IllegalArgumentException("Not a text-format classifier: " + loadTextPath);
}

Try / catch

try {
  crf.loadTextClassifier(loadTextPath, props);
} catch (RuntimeException e) {
  Throwable cause = e.getCause(); // 'format error', 'weights format error', or IOException
  throw new IOException("Failed to load text classifier " + loadTextPath + ": " + cause, cause);
}

Prevention

When it happens

Trigger: Setting -loadTextClassifier (or the properties key) to a path that is missing, unreadable, or not in the expected text format; any IOException or RuntimeException inside loadTextClassifier is rethrown with this message.

Common situations: Typo'd or wrong path in loadTextClassifier flag; pointing at a binary .ser.gz model; text file from a different NLP version; permission issues; file truncated in transit.

Understand the failure class

Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/ie/crf/CRFClassifier.java:2987

    if (crf.flags.useEmbedding && crf.flags.embeddingWords != null && crf.flags.embeddingVectors != null) {
      crf.readEmbeddingsData();
    }

    if (crf.flags.loadClassIndexFrom != null) {
      crf.classIndex = loadClassIndexFromFile(crf.flags.loadClassIndexFrom);
    }

    if (loadPath != null) {
      crf.loadClassifierNoExceptions(loadPath, props);
    } else if (loadTextPath != null) {
      log.info("Warning: this is now only tested for Chinese Segmenter");
      log.info("(Sun Dec 23 00:59:39 2007) (pichuan)");
      try {
        crf.loadTextClassifier(loadTextPath, props);
        // log.info("DEBUG: out from crf.loadTextClassifier");
      } catch (Exception e) {
        throw new RuntimeException("error loading " + loadTextPath, e);
      }
    } else if (crf.flags.loadJarClassifier != null) {
      // legacy option support
      crf.loadClassifierNoExceptions(crf.flags.loadJarClassifier, props);
    } else if (crf.flags.trainFile != null || crf.flags.trainFileList != null) {
      Timing timing = new Timing();
      // temporarily unlimited size of knownLCWords
      int knownLCWordsLimit = crf.knownLCWords.getMaxSize();
      crf.knownLCWords.setMaxSize(-1);
      crf.train();
      crf.knownLCWords.setMaxSize(knownLCWordsLimit);
      timing.done(log, "CRFClassifier training");
    } else {
      crf.loadDefaultClassifier();
    }

    crf.loadTagIndex();

View on GitHub (pinned to 1b7edd19c4)