stanfordnlp/CoreNLP · error · RuntimeException

Could not read from double initial weight file

Error message

Could not read from double initial weight file 

What it means

CRFClassifierNonlinear.trainWeightsUsingNonLinearCRF loads initial weights from flags.initialWeights as a gzip-compressed double array. Any IOException while opening or decoding is rethrown as RuntimeException('Could not read from double initial weight file <path>') with the cause discarded, so only the path is reported.

Solutions

  1. Verify flags.initialWeights exists, is readable, and is valid gzip ('file init.gz').
  2. Confirm the file contains a double array written via ConvertByteArray.writeDoubleArr; regenerate it if it was written as float[].
  3. Convert float initial weights to double[] and rewrite with writeDoubleArr before nonlinear training.
  4. Fix file permissions / re-download if truncated.
  5. Catch and log e.getCause() locally (or patch to chain the exception) to see the underlying IOException.

Example fix

// before
props.setProperty("initialWeights", "init.f32.gz"); // float array -> readDoubleArr fails
// after
// rewrite as double array: ConvertByteArray.writeDoubleArr(new GZIPOutputStream(new FileOutputStream("init.f64.gz")), doubleWeights);
props.setProperty("initialWeights", "init.f64.gz");
Defensive patterns

Strategy: validation

Validate before calling

File f = new File(flags.initialWeights);
if (!f.isFile() || !f.canRead()) throw new IllegalArgumentException("initialWeights missing/unreadable: " + flags.initialWeights);
try (InputStream in = new GZIPInputStream(new FileInputStream(f))) {
  in.read(); // fails fast if not gzip
}

Try / catch

try {
  initialWeights = ConvertByteArray.readDoubleArr(
      new DataInputStream(new BufferedInputStream(new GZIPInputStream(new FileInputStream(flags.initialWeights)))));
} catch (IOException e) {
  throw new RuntimeException("Could not read double initial weights from " + flags.initialWeights, e); // chain the cause!
}

Prevention

When it happens

Trigger: Training a nonlinear CRF with flags.initialWeights set to a missing/unreadable file, a non-gzip file, or a file holding a float array instead of the required double array (ConvertByteArray.readDoubleArr).

Common situations: Wrong path/typo in initialWeights; file produced by the float pipeline (float array) and fed to the nonlinear/double trainer; different compression (plain or zip instead of gzip); permissions; file truncated by a failed transfer.

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/07e9bc5a8031c518. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/ie/crf/CRFClassifierNonlinear.java:155

      this.outputLayerWeights = params.third();
    }

    return null;
  }

  private double[] trainWeightsUsingNonLinearCRF(AbstractCachingDiffFunction func, Evaluator[] evaluators) {
    Minimizer<DiffFunction> minimizer = getMinimizer(0, evaluators);

    double[] initialWeights;
    if (flags.initialWeights == null) {
      initialWeights = func.initial();
    } else {
      log.info("Reading initial weights from file " + flags.initialWeights);
      try (DataInputStream dis = new DataInputStream(new BufferedInputStream(new GZIPInputStream(new FileInputStream(
            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("Testing complete... exiting");
        System.exit(1);
      } else {
        log.info("Testing failed....exiting");
        System.exit(1);
      }

    }
    //check gradient
    if (flags.checkGradient) {
      if (func.gradientCheck()) {

View on GitHub (pinned to 1b7edd19c4)