stanfordnlp/CoreNLP · error · RuntimeException

Could not read from double initial weight file " +…

Error message

Could not read from double initial weight file " + flags.initialWeights

What it means

When flags.initialWeights points to a file, the stochastic training path reads a double array of initial weights via IOUtils.getDataInputStream and ConvertByteArray.readDoubleArr. An IOException (missing file, unreadable, truncated, wrong binary format) is wrapped in this RuntimeException naming the offending path.

Solutions

  1. Verify initialWeights points to an existing readable file produced by the same model configuration and version.
  2. Regenerate the weights file with the current CRF setup.
  3. Remove the initialWeights property to use default initialization.
  4. Inspect the wrapped IOException to distinguish not-found vs. EOF/truncation.

Example fix

// before
props.setProperty("initialWeights", "/models/old-weights.ser"); // file deleted
// after
props.setProperty("initialWeights", "/models/crf-weights-v2.ser");
// or remove the property to start from default initialization
Defensive patterns

Strategy: validation

Validate before calling

String path = props.getProperty("initialWeights");
if (path != null) {
  File f = new File(path);
  if (!f.isFile() || !f.canRead() || f.length() == 0 || f.length() % 8 != 0) {
    throw new IllegalArgumentException("initialWeights missing/unreadable or not a double array: " + path);
  }
}

Try / catch

try {
  classifier.train(files);
} catch (RuntimeException e) {
  if (String.valueOf(e.getMessage()).startsWith("Could not read from double initial weight file")) {
    props.remove("initialWeights"); // fall back to default initialization
    // rebuild and retry
  } else throw e;
}

Prevention

When it happens

Trigger: Setting initialWeights=<path> where the file doesn't exist, lacks read permission, or doesn't contain a valid binary double array of the expected length for the model.

Common situations: Reusing weights saved from a different model size (feature/label mismatch causing truncated or misaligned reads); stale or renamed path; files produced by a different library version.

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/14dec1e57d438213. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/ie/crf/CRFClassifier.java:1857

        for (Integer val : aSet)
          fg[count][i++] = val;
        count++;
      }
      func.setFeatureGrouping(fg);
    }

    Minimizer<DiffFunction> minimizer = getMinimizer(pruneFeatureItr, evaluators);

    double[] initialWeights;
    if (flags.initialWeights == null) {
      initialWeights = func.initial();
    } else {
      try {
        log.info("Reading initial weights from file " + flags.initialWeights);
        DataInputStream dis = IOUtils.getDataInputStream(flags.initialWeights);
        initialWeights = ConvertByteArray.readDoubleArr(dis);
      } catch (IOException e) {
        throw new RuntimeException("Could not read from double initial weight file " + flags.initialWeights);
      }
    }
    log.info("numWeights: " + initialWeights.length);

    if (flags.testObjFunction) {
      StochasticDiffFunctionTester tester = new StochasticDiffFunctionTester(func);
      if (tester.testSumOfBatches(initialWeights, 1e-4)) {
        log.info("Successfully tested stochastic objective function.");
      } else {
        throw new IllegalStateException("Testing of stochastic objective function failed.");
      }

    }
    //check gradient
    if (flags.checkGradient) {
      if (func.gradientCheck()) {
        log.info("gradient check passed");
      } else {

View on GitHub (pinned to 1b7edd19c4)