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

  1. Re-serialize the classifier files with the same Stanford CoreNLP version you use at load time
  2. Verify the InputStream actually points at the correct classifier resource (check path/order of classifiers in the properties)
  3. Inspect the wrapped cause 'ex' to see the true deserialization failure
  4. 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

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


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)