stanfordnlp/CoreNLP · error · RuntimeIOException
Error loading classifier from
Error message
Error loading classifier from
What it means
MultinomialLogisticClassifier.loadSelfSupervised/load deserializes a classifier (weights array, feature index, label index) from a file via ObjectInputStream. If the stream is corrupt, truncated, or not a saved classifier, an IOException or ClassNotFoundException is wrapped in this RuntimeIOException carrying the path. It is a deserialization failure, not a modeling error.
Solutions
- Verify the path points to a file previously written by MultinomialLogisticClassifier.save with the same library version
- Catch RuntimeIOException and check the cause (IOException vs ClassNotFoundException) to distinguish corrupt file from version mismatch
- Re-save the classifier with the current library version and retry
- Check file existence/readability before load
Example fix
// before
MultinomialLogisticClassifier c = MultinomialLogisticClassifier.load(cfgPath);
// after
File f = new File(modelPath);
if (!f.isFile()) throw new IllegalArgumentException("model missing: " + modelPath);
try {
MultinomialLogisticClassifier c = MultinomialLogisticClassifier.load(modelPath);
} catch (RuntimeIOException e) {
throw new IllegalStateException("Incompatible/corrupt model at " + modelPath, e);
} Defensive patterns
Strategy: try-catch
Validate before calling
File f = new File(path);
if (!f.exists() || !f.canRead() || f.length() < 8)
throw new IllegalArgumentException("Classifier file missing or empty: " + path); Try / catch
try {
MultinomialLogisticClassifier<LL,FF> c = MultinomialLogisticClassifier.load(path);
} catch (RuntimeIOException e) {
if (e.getCause() instanceof ClassNotFoundException)
throw new IllegalStateException("Model serialized with a different library version: " + path, e);
throw new IllegalStateException("Corrupt or missing model file: " + path, e);
} Prevention
- Save and load models with the exact same library version; record the version alongside the model
- Validate file existence and non-zero size before load
- Catch RuntimeIOException (not IOException) since load wraps it
- Never hand-edit or truncate serialized classifier files
When it happens
Trigger: Calling MultinomialLogisticClassifier.load(path) on a missing, corrupt, or wrong-format file; loading a classifier serialized by an incompatible library version (class shape changed → ClassNotFoundException); reading a text file or classifier of a different type.
Common situations: Pointing to the wrong path or a file moved/truncated; version mismatch after upgrading CoreNLP so the serialized class descriptor differs; attempting to load a LinearClassifier's dump as a MultinomialLogisticClassifier.
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
- Error leading weights from
- Couldn't load
- IO problem reading classifier.
- Failed to load segmenter
- Failed to read lambdas from given input stream
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/a188eb5a674ce207.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/classify/MultinomialLogisticClassifier.java:126
}
@Override
public Counter<L> logProbabilityOf(Datum<L, F> example) {
Counter<L> result = probabilityOf(example);
Counters.logInPlace(result);
return result;
}
private static <LL,FF> MultinomialLogisticClassifier<LL,FF> load(String path) {
Timing t = new Timing();
try (ObjectInputStream in = IOUtils.readStreamFromString(path)) {
double[][] myWeights = ErasureUtils.uncheckedCast(in.readObject());
Index<FF> myFeatureIndex = ErasureUtils.uncheckedCast(in.readObject());
Index<LL> myLabelIndex = ErasureUtils.uncheckedCast(in.readObject());
t.done(logger, "Loading classifier from " + path);
return new MultinomialLogisticClassifier<>(myWeights, myFeatureIndex, myLabelIndex);
} catch (IOException | ClassNotFoundException e) {
throw new RuntimeIOException("Error loading classifier from " + path, e);
}
}
private void save(String path) throws IOException {
System.out.print("Saving classifier to " + path + "... ");
// make sure the directory specified by path exists
int lastSlash = path.lastIndexOf(File.separator);
if (lastSlash > 0) {
File dir = new File(path.substring(0, lastSlash));
if (! dir.exists())
dir.mkdirs();
}
ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(path));
out.writeObject(weights);
out.writeObject(featureIndex);
out.writeObject(labelIndex);View on GitHub (pinned to 1b7edd19c4)