stanfordnlp/CoreNLP · error · IOException
Couldn't load classifier!
Error message
Couldn't load classifier!
What it means
ClassifierCombiner's ObjectInputStream-based constructor loads a sequence of base classifiers (CRF/CMM) from a stream. If deserializing a CMM classifier fails for any reason, the underlying exception is wrapped and rethrown as an IOException with this message.
Solutions
- Re-serialize the classifier files with the same Stanford CoreNLP version you use at load time
- Verify the InputStream actually points at the correct classifier resource (check path/order of classifiers in the properties)
- Inspect the wrapped cause 'ex' to see the true deserialization failure
- Confirm all Stanford NLP jars on the classpath are the same version
Example fix
// before: mismatched versions ClassifierCombiner c = new ClassifierCombiner(ois, props); // IOException: Couldn't load classifier! // after: rebuild classifiers with matching jar version // mvn dependency: on edu.stanford.nlp:stanford-corenlp:3.9.2 everywhere, then ClassifierCombiner c = new ClassifierCombiner(ois, props);
Defensive patterns
Strategy: try-catch
Validate before calling
// verify resource exists and stream is non-empty before loading
try (InputStream in = new FileInputStream(classifierFile)) {
if (in.read() == -1) throw new IllegalStateException("empty classifier file");
} Try / catch
try {
ClassifierCombiner c = new ClassifierCombiner(ois, props);
} catch (IOException e) {
log.error("classifier load failed; check version match and stream integrity", e.getCause());
throw new UncheckedIOException(e);
} Prevention
- Pin all Stanford CoreNLP jars to one version
- Re-serialize classifiers with the same library version you load with
- Verify classifier files are on the classpath / deployed
When it happens
Trigger: ClassifierCombiner.getClassifier(ObjectInputStream, Properties) is called with a stream that does not contain the expected serialized classifier, the stream is truncated/corrupt, or the classpath lacks classifier classes so deserialization throws.
Common situations: See trigger scenarios.
Related errors
- Error initializing FeatureExtractorRunner
- RuntimeException wrapping Exception (dataset read failure)
- Couldn't load
- Couldn't load classifier from
- ERROR: Serialized data does not contain an Annotation!
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/159ef92e292bac96.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/ie/ClassifierCombiner.java:228
// read in the base classifiers
int numClassifiers = ois.readInt();
// set up the list of base classifiers
this.baseClassifiers = new ArrayList<>();
int i = 0;
while (i < numClassifiers) {
try {
log.info("loading CRF...");
CRFClassifier<IN> newCRF = ErasureUtils.uncheckedCast(CRFClassifier.getClassifier(ois, props));
baseClassifiers.add(newCRF);
i++;
} catch (Exception e) {
try {
log.info("loading CMM...");
CMMClassifier newCMM = ErasureUtils.uncheckedCast(CMMClassifier.getClassifier(ois, props));
baseClassifiers.add(newCMM);
i++;
} catch (Exception ex) {
throw new IOException("Couldn't load classifier!", ex);
}
}
}
}
/**
* Either finds COMBINATION_MODE_PROPERTY or returns a default value.
*/
public static CombinationMode extractCombinationMode(Properties p) {
String mode = p.getProperty(COMBINATION_MODE_PROPERTY);
if (mode == null) {
return DEFAULT_COMBINATION_MODE;
} else {
return CombinationMode.valueOf(mode.toUpperCase(Locale.ROOT));
}
}
/**View on GitHub (pinned to 1b7edd19c4)