stanfordnlp/CoreNLP · error · IllegalStateException

Invalid model at path: " + serializedModel

Error message

Invalid model at path: " + serializedModel

What it means

ClauseSplitter.load deserializes a pretrained clause-splitter model from a URL, classpath, or filesystem path. If deserialization throws ClassNotFoundException — meaning the stream contained classes not present/resolvable in the current classpath — it reports the model as invalid via IllegalStateException.

Solutions

  1. Align the library version with the one that trained/saved the model (check model README/version metadata)
  2. Re-train or re-download a model compatible with your current CoreNLP version
  3. Ensure the full naturalli/classifier classes are on the classpath (fat jar, correct dependencies)

Example fix

// before
ClauseSplitter splitter = ClauseSplitter.load("clauseSplitterModel-3.6.ser.gz"); // with CoreNLP 4.x
// after
// download the model matching your CoreNLP version
ClauseSplitter splitter = ClauseSplitter.load("clauseSplitterModel-4.x.ser.gz");
Defensive patterns

Strategy: fallback

Validate before calling

// Confirm the resource exists and the expected classes are loadable before load()
if (ClauseSplitter.class.getClassLoader().getResource("edu/stanford/nlp/naturalli/ClauseSplitterSearchProblem.class") == null) {
  throw new IllegalStateException("naturalli classes missing from classpath");
}

Try / catch

try { return ClauseSplitter.load(modelPath); } catch (IllegalStateException e) { /* fallback to default/other model or re-download */ }

Prevention

When it happens

Trigger: Loading a model serialized with a different Stanford NLP version whose class names or serialVersionUID changed, or a corrupted/wrong file at serializedModel that still deserializes far enough to reference unknown classes.

Common situations: Upgrading the CoreNLP/naturalli jar while keeping an old clause splitter model; classpath missing the naturalli classes when loading on a slim deployment; renaming/refactoring packages across versions.

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/naturalli/ClauseSplitter.java:289

  }


  /**
   * Load a factory model from a given path. This can be trained with
   * {@link ClauseSplitter#train(Stream, Optional, Optional, Featurizer)}.
   *
   * @return A function taking a dependency tree, and returning a clause searcher.
   */
  static ClauseSplitter load(String serializedModel) throws IOException {
    try {
      long start = System.currentTimeMillis();
      Pair<Classifier<ClauseClassifierLabel,String>, Featurizer> data = IOUtils.readObjectFromURLOrClasspathOrFileSystem(serializedModel);
      ClauseSplitter rtn =  (tree, truth) -> new ClauseSplitterSearchProblem(tree, truth, Optional.of(data.first), Optional.of(data.second));
      log.info("Loading clause splitter from " + serializedModel + " ... done [" +
              Redwood.formatTimeDifference(System.currentTimeMillis() - start) + "]");
      return rtn;
    } catch (ClassNotFoundException e) {
      throw new IllegalStateException("Invalid model at path: " + serializedModel, e);
    }
  }


}

View on GitHub (pinned to 1b7edd19c4)