stanfordnlp/CoreNLP · error · RuntimeException
format error
Error message
format error
What it means
loadTextClassifier parses a text-serialized CRF line by line and requires a strict header line "labelIndices.length=\t<size>". If the first tab-separated token doesn't equal "labelIndices.length=", it throws this RuntimeException, meaning the stream is not in the expected text format (wrong loader, wrong file, or version mismatch).
Solutions
- Use the matching loader: binary files go through the binary load path (getClassifier/serializeTo); loadTextClassifier only reads files written by serializeTextClassifier.
- Verify the file's first line is exactly "labelIndices.length=\t<N>" (key, TAB, integer).
- Re-serialize the classifier with the same library version that reads it.
- Confirm the path points at the intended file and that it isn't truncated.
Example fix
// before
// file saved with serializeTo (binary) but read as text -> "format error"
classifier.loadTextClassifier(new BufferedReader(new FileReader("/models/ner.ser.gz")));
// after
// save text: classifier.serializeTextClassifier("/models/ner.txt");
classifier.loadTextClassifier(new BufferedReader(new FileReader("/models/ner.txt"))); Defensive patterns
Strategy: validation
Validate before calling
try (BufferedReader br = new BufferedReader(new FileReader(modelFile))) {
String first = br.readLine();
if (first == null || !first.split("\t")[0].equals("labelIndices.length=")) {
throw new IllegalArgumentException(modelFile + " is not a text-serialized CRF; use the binary loader");
}
} Try / catch
try {
classifier.loadTextClassifier(br);
} catch (Exception e) {
if (String.valueOf(e.getMessage()).contains("format error")) {
// wrong loader or corrupt file: fall back to the binary loader
classifier = CRFClassifier.getClassifier(modelFile);
} else throw e;
} Prevention
- Match loader to writer: loadTextClassifier only for serializeTextClassifier output.
- Peek at the first line (labelIndices.length=\tN) before parsing.
- Keep trainer and loader on the same Stanford NLP version.
When it happens
Trigger: Calling loadTextClassifier on a binary serialized classifier, an empty/truncated/corrupt file, a manually edited file, or a model saved by a different Stanford NLP version with a changed text format.
Common situations: Mixing serializeTo (binary) output with the text loader; passing the wrong file path; loading models across incompatible library versions.
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
- weights format error
- invalid format: ||
- is not a legal LogPrior.
- Bad data format:
- RuntimeIOException wrapping IOException
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/08659063ceadb653.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/ie/crf/CRFClassifier.java:2105
protected static List<List<CRFDatum<Collection<String>, String>>> loadProcessedData(String filename) {
List<List<CRFDatum<Collection<String>, String>>> result;
try {
result = IOUtils.readObjectFromURLOrClasspathOrFileSystem(filename);
} catch (Exception e) {
log.warn(e);
result = Collections.emptyList();
}
log.info("Loading processed data from serialized file ... done. Got " + result.size() + " datums.");
return result;
}
protected void loadTextClassifier(BufferedReader br) throws Exception {
String line = br.readLine();
// first line should be this format:
// labelIndices.size()=\t%d
String[] toks = line.split("\\t");
if (!toks[0].equals("labelIndices.length=")) {
throw new RuntimeException("format error");
}
int size = Integer.parseInt(toks[1]);
labelIndices = new ArrayList<>(size);
for (int labelIndicesIdx = 0; labelIndicesIdx < size; labelIndicesIdx++) {
line = br.readLine();
// first line should be this format:
// labelIndices.length=\t%d
// labelIndices[0].size()=\t%d
toks = line.split("\\t");
if (!(toks[0].startsWith("labelIndices[") && toks[0].endsWith("].size()="))) {
throw new RuntimeException("format error");
}
int labelIndexSize = Integer.parseInt(toks[1]);
labelIndices.add(new HashIndex<>());
int count = 0;
while (count < labelIndexSize) {
line = br.readLine();
toks = line.split("\\t");View on GitHub (pinned to 1b7edd19c4)