stanfordnlp/CoreNLP · error · RuntimeException
format error in nodeFeatureIndicesMap
Error message
format error in nodeFeatureIndicesMap
What it means
loadTextClassifier reads a text-serialized CRFClassifierNonlinear model line by line and expects the first line after the superclass section to be the header "nodeFeatureIndicesMap.size()=\t<size>". When the tab-split first token does not equal that exact header string, this RuntimeException is thrown. It signals the model file is not in the expected text serialization format produced by serializeTextClassifier.
Solutions
- Regenerate the model file with serializeTextClassifier from the same CRFClassifierNonlinear version.
- Verify you are loading the correct file (text serialization, not .ser binary or gzipped model).
- Check that the expected header line "nodeFeatureIndicesMap.size()=" exists with a literal tab before the size.
- Match the Stanford NLP library version used to write the model with the one doing the loading.
- Write a loader for the actual format of the file if it was produced elsewhere.
Example fix
// before
CRFClassifier<CoreLabel> crf = CRFClassifier.getClassifier("model.ser"); // binary file, header line missing
// after
CRFClassifier<CoreLabel> crf = CRFClassifier.getClassifier("model.txt"); // text-serialized with serializeTextClassifier Defensive patterns
Strategy: validation
Validate before calling
// Verify the model file is text-serialized and starts with the expected section before loading:
try (BufferedReader br = new BufferedReader(new FileReader(modelFile))) {
String firstLine = br.readLine();
boolean hasHeader = false, line;
while ((line = br.readLine()) != null) {
if (line.startsWith("nodeFeatureIndicesMap.size()=")) { hasHeader = true; break; }
}
if (!hasHeader) throw new IOException(modelFile + " is not a text-serialized non-linear CRF model");
} Try / catch
try {
classifier = CRFClassifier.getClassifier(modelPath);
} catch (Exception e) {
if (String.valueOf(e.getMessage()).contains("format error in nodeFeatureIndicesMap")) {
throw new IOException("Model file is not a text-serialized CRFClassifierNonlinear model: " + modelPath, e);
}
throw e;
} Prevention
- Load only models written by serializeTextClassifier of the same classifier type.
- Never hand-edit text model files; regenerate them from training.
- Pin the Stanford NLP version so serializer and deserializer match.
- Check the file is not gzipped/binary before text loading.
When it happens
Trigger: Calling loadTextClassifier (e.g. via loadTextClassifier for a non-linear CRF) on a file whose next line is not the nodeFeatureIndicesMap header: the file was not saved with serializeTextClassifier, was saved by a different classifier type/version, is truncated, or line endings/encoding differ so split("\\t") yields a wrong token.
Common situations: Pointing the loader at a serializedClassifier (gzip/binary) file instead of a text one; hand-editing the model file; loading a model written by a different Stanford NLP version where the text format changed; files corrupted by editors converting tabs to spaces.
Related errors
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/fcfc5d5a521da49b.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/ie/crf/CRFClassifierNonlinear.java:248
}
pw.printf("outputLayerWeights.length=\t%d%n", outputLayerWeights.length);
for (double[] ws : outputLayerWeights) {
ArrayList<Double> list = new ArrayList<>();
for (double w : ws) {
list.add(w);
}
pw.printf("%d\t%s%n", ws.length, StringUtils.join(list, " "));
}
}
@Override
protected void loadTextClassifier(BufferedReader br) throws Exception {
super.loadTextClassifier(br);
String line = br.readLine();
String[] toks = line.split("\\t");
if (!toks[0].equals("nodeFeatureIndicesMap.size()=")) {
throw new RuntimeException("format error in nodeFeatureIndicesMap");
}
int nodeFeatureIndicesMapSize = Integer.parseInt(toks[1]);
nodeFeatureIndicesMap = new HashIndex<>();
int count = 0;
while (count < nodeFeatureIndicesMapSize) {
line = br.readLine();
toks = line.split("\\t");
int idx = Integer.parseInt(toks[0]);
if (count != idx) {
throw new RuntimeException("format error");
}
nodeFeatureIndicesMap.add(Integer.parseInt(toks[1]));
count++;
}
line = br.readLine();
toks = line.split("\\t");
if (!toks[0].equals("edgeFeatureIndicesMap.size()=")) {View on GitHub (pinned to 1b7edd19c4)