stanfordnlp/CoreNLP · critical · RuntimeException

Error leading weights from

Error message

Error leading weights from {modelFile}

What it means

SimpleLinearClassifier wraps any exception raised while deserializing the coref model weights into a RuntimeException with this message. It indicates the serialized model file could not be read or unmarshalled (missing file, corrupt data, incompatible serialization version).

Solutions

  1. Verify the modelFile path/URL exists and is readable, and that the model resource is on the classpath
  2. Re-download the Stanford CoreNLP coref model matching your library version
  3. Check for ClassNotFoundException/InvalidClassException in the cause chain and align CoreNLP code and model versions
  4. Pass a valid modelFile, or construct the classifier in learning mode so it starts with empty weights

Example fix

// before
new SimpleLinearClassifier(Loss.logistic, "coref/model.ser");
// after
File f = new File("coref/model.ser");
if (!f.isFile()) throw new IllegalStateException("model missing: " + f);
new SimpleLinearClassifier(Loss.logistic, f.getPath());
Defensive patterns

Strategy: validation

Validate before calling

File f = new File(modelFile);
if (!f.isFile() || !f.canRead()) throw new IllegalStateException("model not readable: " + modelFile);

Try / catch

try {
  new SimpleLinearClassifier(loss, modelFile);
} catch (RuntimeException e) {
  logger.severe("model load failed: " + e.getCause());
  throw e;
}

Prevention

When it happens

Trigger: Constructing SimpleLinearClassifier with a modelFile path/URL when IOUtils.readObjectAnnouncingTimingFromURLOrClasspathOrFileSystem throws: file absent, unreadable, corrupted, or serialized by an incompatible Java/class version.

Common situations: Model file path typo in coref properties, model not on classpath, Stanford CoreNLP model jar version mismatch with code (serialization serialVersionUID changes), truncated download of the classifier model.

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/3014a682209213e9. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/coref/statistical/SimpleLinearClassifier.java:48

  public SimpleLinearClassifier(Loss loss, LearningRateSchedule learningRateSchedule,
      double regularizationStrength) {
    this(loss, learningRateSchedule, regularizationStrength, null);
  }

  public SimpleLinearClassifier(Loss loss,LearningRateSchedule learningRateSchedule,
      double regularizationStrength, String modelFile) {
    if (modelFile != null) {
      try {
        if (modelFile.endsWith(".tab.gz")) {
          Timing.startDoing("Reading " + modelFile);
          this.weights = Counters.deserializeStringCounter(modelFile);
          Timing.endDoing("Reading " + modelFile);
        } else {
          this.weights = IOUtils.readObjectAnnouncingTimingFromURLOrClasspathOrFileSystem(
              log, "Loading coref model", modelFile);
        }
      } catch (Exception e) {
        throw new RuntimeException("Error leading weights from " + modelFile, e);
      }
    } else {
      this.weights = new ClassicCounter<>();
    }

    this.defaultLoss = loss;
    this.regularizationStrength = regularizationStrength;
    this.learningRateSchedule = learningRateSchedule;
    accessTimes = new ClassicCounter<>();
    examplesSeen = 0;
  }

  public void learn(Counter<String> features, double label, double weight) {
    learn(features, label, weight, defaultLoss);
  }

  public void learn(Counter<String> features, double label, double weight, Loss loss) {
    examplesSeen++;

View on GitHub (pinned to 1b7edd19c4)