stanfordnlp/CoreNLP · error · RuntimeException
weights format error
Error message
weights format error
What it means
Inside loadTextClassifier, each weight row line must be '<rowLength>\t<v1 v2 ...>'. The loader parses the declared row length (weights2Length) and the space-separated values; if the number of parsed float values does not equal the declared length it throws RuntimeException('weights format error'), indicating a malformed or truncated weight row.
Solutions
- Check the offending line: token 0 must equal the number of space-separated floats in token 1; fix or regenerate the file.
- Re-export the text classifier from the original serialized model with the same Stanford NLP version.
- Open the file in an editor that does not wrap lines and ensure no lines were split or trailing values dropped.
- Regenerate the file without any intermediate processing (no sed/Excel/copy-paste) that could drop or alter values.
- If the file is unreliable, retrain or use the binary serialized classifier via loadClassifier instead.
Defensive patterns
Strategy: validation
Validate before calling
try (BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(path), "UTF-8"))) {
String header = br.readLine();
int n = Integer.parseInt(header.split("\t")[1]);
for (int i = 0; i < n; i++) {
String[] toks = br.readLine().split("\t", -1);
if (toks.length < 2 || Integer.parseInt(toks[0]) != toks[1].split(" ").length)
throw new IllegalArgumentException("Malformed weight row " + i + " in " + path);
}
if (br.readLine() != null) throw new IllegalArgumentException("Trailing content in " + path);
} Type guard
static boolean isWellFormedWeightRow(String line) {
String[] toks = line.split("\t", -1);
if (toks.length < 2) return false;
try { return Integer.parseInt(toks[0]) == toks[1].trim().split("\\s+").length; }
catch (NumberFormatException e) { return false; }
} Try / catch
try {
crf.loadTextClassifier(path, props);
} catch (RuntimeException e) {
if ("weights format error".equals(e.getMessage()))
throw new IOException("Corrupt text weight rows in " + path + " — regenerate the text dump", e);
throw e;
} Prevention
- Transfer generated files in binary mode (no line wrapping/translation).
- Validate row structure before loading.
- Regenerate rather than hand-repair weight dumps.
- Keep writer and reader on the same library version.
When it happens
Trigger: Loading a text classifier whose weight-row lines declare a count that does not match the space-separated values present, e.g. values truncated, line-wrapped by an editor, extra spaces, or rows written by a different format version.
Common situations: Text weight file truncated by copy/paste or transfer; line wrapping inserted by editors/mail; float values containing non-numeric tokens causing parse mismatch; mixed-format file assembled by hand; version mismatch between writer and reader.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- format error
- invalid format: ||
- is not a legal LogPrior.
- Bad data format:
- Unexpected number of field , expected >= for line (,):
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/47d39cf5d9310500.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/ie/crf/CRFClassifier.java:2272
// weights.length= 2655170
line = br.readLine();
toks = line.split("\\t");
if (!toks[0].equals("weights.length=")) {
throw new RuntimeException("format error");
}
int weightsLength = Integer.parseInt(toks[1]);
weights = new float[weightsLength][];
count = 0;
while (count < weightsLength) {
line = br.readLine();
toks = line.split("\\t");
int weights2Length = Integer.parseInt(toks[0]);
weights[count] = new float[weights2Length];
String[] weightsValue = toks[1].split(" ");
if (weights2Length != weightsValue.length) {
throw new RuntimeException("weights format error");
}
for (int i2 = 0; i2 < weights2Length; i2++) {
// TODO: check that this doesn't barf... why would it?
weights[count][i2] = Float.parseFloat(weightsValue[i2]);
}
count++;
}
System.err.printf("DEBUG: float[%d][] weights loaded%n", weightsLength);
line = br.readLine();
if (line != null) {
throw new RuntimeException("weights format error");
}
}
public void loadTextClassifier(String text, Properties props) throws ClassCastException, IOException,
ClassNotFoundException, InstantiationException, IllegalAccessException {View on GitHub (pinned to 1b7edd19c4)