stanfordnlp/CoreNLP · error · RuntimeException
Could not read from float initial weight file
Error message
Could not read from float initial weight file
What it means
CRFClassifierFloat.trainWeights loads initial weights from flags.initialWeights as a gzip-compressed float array. If opening/reading the stream or decoding the array throws IOException, it throws RuntimeException('Could not read from float initial weight file <path>') — notably WITHOUT the cause chained, so the original IOException detail is lost.
Solutions
- Check that flags.initialWeights points to an existing, readable gzip-compressed float-array file.
- Verify the file is valid gzip ('file initialweights.gz') and was written with ConvertByteArray.writeFloatArr.
- Regenerate the initial weights file as a float array with the matching utility/serialization.
- If you only have a double array, convert it to float[] before writing/using it for the float trainer.
- Wrap the call yourself or patch to chain the cause (new RuntimeException(msg, e)) to see the true IOException.
Example fix
// before
props.setProperty("initialWeights", "init.txt"); // plain text, not gzip float array
// after
// write with ConvertByteArray.writeFloatArr(new GZIPOutputStream(new FileOutputStream("init.f32.gz")), floatWeights);
props.setProperty("initialWeights", "init.f32.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(); // throws IOException('Not in GZIP format') if not gzip
} Try / catch
try {
initialWeights = ConvertByteArray.readFloatArr(
new DataInputStream(new BufferedInputStream(new GZIPInputStream(new FileInputStream(flags.initialWeights)))));
} catch (IOException e) {
throw new RuntimeException("Could not read float initial weights from " + flags.initialWeights, e); // chain the cause!
} Prevention
- Verify the initialWeights file exists and is gzip before training.
- Ensure it was written with ConvertByteArray.writeFloatArr (float, not double).
- When reproducing this code, always chain the IOException as the cause.
- Validate gzip integrity ('gzip -t file.gz') beforehand.
When it happens
Trigger: Setting flags.initialWeights to a nonexistent file, unreadable file, or a file that is not a gzip stream of a float array (wrong format, plain text, double array) during training with float weights.
Common situations: Typo in initialWeights path; file compressed differently (plain vs gzip); passing a double-array dump instead of a float dump; permissions; file created by another tool with a different binary layout.
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
- Could not read from double initial weight file
- Could not read from double initial LOP scales file
- edu.stanford.nlp.io.RuntimeIOException
- Error reading saved links
- Error setting up training
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/81b3a001dda02b20.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/ie/crf/CRFClassifierFloat.java:92
if (pruneFeatureItr == 0) {
minimizer.setM(flags.QNsize);
} else {
minimizer.setM(flags.QNsize2);
}
float[] initialWeights;
if (flags.initialWeights == null) {
initialWeights = func.initial();
} else {
try {
log.info("Reading initial weights from file " + flags.initialWeights);
try (DataInputStream dis = new DataInputStream(new BufferedInputStream(new GZIPInputStream(new FileInputStream(
flags.initialWeights))))) {
initialWeights = ConvertByteArray.readFloatArr(dis);
}
} catch (IOException e) {
throw new RuntimeException("Could not read from float initial weight file " + flags.initialWeights);
}
}
log.info("numWeights: " + initialWeights.length);
float[] weightsArray = minimizer.minimize(func, (float) flags.tolerance, initialWeights);
return ArrayMath.floatArrayToDoubleArray(weightsArray);
}
} // end class CRFClassifierFloat
View on GitHub (pinned to 1b7edd19c4)