stanfordnlp/CoreNLP · error · RuntimeException
weights format error
Error message
weights format error
What it means
Each inputLayerWeights4Edge row in a text-serialized CRFClassifierNonlinear model is written as "<rowLength>\t<w1 w2 w3 ...>". After parsing the row length, the loader splits the second token on spaces and requires the number of values to equal the declared row length; otherwise this RuntimeException is thrown. It means a weight row's declared length does not match the values actually present on that line.
Solutions
- Regenerate the model with serializeTextClassifier instead of editing weights manually.
- Verify each row line's leading count equals the number of space-separated weight values after the tab.
- Check the file was not truncated (last rows often lose values).
- Re-transfer or re-serialize if the file was corrupted.
- Use the same library version for saving and loading.
Example fix
// before 3 0.5 0.25 // declares 3 weights but only 2 present // after 3 0.5 0.25 0.75
Defensive patterns
Strategy: validation
Validate before calling
// Verify each inputLayerWeights4Edge row: leading count must equal the number of space-separated values.
// e.g. for line "3\t0.5 0.25 0.75": toks[0]=3, toks[1].split(" ").length must be 3. Try / catch
try {
crf = CRFClassifier.getClassifier(modelPath);
} catch (Exception e) {
if (String.valueOf(e.getMessage()).equals("weights format error")) {
throw new IOException("Weight row length mismatch in inputLayerWeights4Edge; regenerate the model file: " + modelPath, e);
}
throw e;
} Prevention
- Do not edit weight values in text model files manually.
- Verify checksums after transferring models to catch truncation.
- Avoid text editors that reflow or normalize whitespace on model files.
- Serialize and load with the same Stanford NLP release.
When it happens
Trigger: loadTextClassifier parses a row line where toks[1] contains fewer/more space-separated numbers than toks[0] declares: manual edits, truncation cutting off trailing values, tabs/spaces corruption, or files written by a different version with a different row encoding.
Common situations: Hand-edited weight files; truncated downloads; editors normalizing whitespace; mixing models between Stanford NLP versions; double-precision values pasted incompletely.
Related errors
- format error in nodeFeatureIndicesMap
- format error
- Could not read from double initial weight file " + flags.ini
- format error
- weights format error
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/8eb1e198eb7f933f.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/ie/crf/CRFClassifierNonlinear.java:301
int weightsLength = -1;
if (flags.secondOrderNonLinear) {
line = br.readLine();
toks = line.split("\\t");
if (!toks[0].equals("inputLayerWeights4Edge.length=")) {
throw new RuntimeException("format error");
}
weightsLength = Integer.parseInt(toks[1]);
inputLayerWeights4Edge = new double[weightsLength][];
count = 0;
while (count < weightsLength) {
line = br.readLine();
toks = line.split("\\t");
int weights2Length = Integer.parseInt(toks[0]);
inputLayerWeights4Edge[count] = new double[weights2Length];
String[] weightsValue = toks[1].split(" ");
if (weights2Length != weightsValue.length) {
throw new RuntimeException("weights format error");
}
for (int i2 = 0; i2 < weights2Length; i2++) {
inputLayerWeights4Edge[count][i2] = Double.parseDouble(weightsValue[i2]);
}
count++;
}
line = br.readLine();
toks = line.split("\\t");
if (!toks[0].equals("outputLayerWeights4Edge.length=")) {
throw new RuntimeException("format error");
}
weightsLength = Integer.parseInt(toks[1]);
outputLayerWeights4Edge = new double[weightsLength][];
count = 0;
while (count < weightsLength) {
line = br.readLine();View on GitHub (pinned to 1b7edd19c4)