stanfordnlp/CoreNLP · error · RuntimeIOException
ERROR: Incorrect format for the serialized coref graph
Error message
ERROR: Incorrect format for the serialized coref graph: ${line} What it means
CustomAnnotationSerializer.read parses the old-format coref graph line as space-separated fields in groups of 4 (source tuple + destination tuple). If the number of fields is not a multiple of 4, the line cannot represent complete (src,dst) pairs and a RuntimeIOException is thrown.
Solutions
- Regenerate the serialized annotation file with the same CoreNLP version used to read it
- Check the coref line's field count is a multiple of 4 (sentIndex-copy pairs for src and dst)
- Ensure the file transferred completely and was not truncated (compare checksums)
- Use a consistent CustomAnnotationSerializer version for both write and read
Example fix
// before: truncated line with 6 fields (not multiple of 4) // 0-1 0-2 1-0 1-1 2-0 2-1 // after: complete 4-field-group line // 0-1 0-2 1-0 1-1
Defensive patterns
Strategy: validation
Validate before calling
String[] bits = corefLine.split(" ");
if (bits.length % 4 != 0) throw new IllegalArgumentException("Coref line not multiple of 4 fields: " + corefLine); Type guard
static boolean hasCompleteCorefGroups(String line) {
return line.trim().split(" ").length % 4 == 0;
} Try / catch
try {
Pair<Annotation, InputStream> p = serializer.read(in);
} catch (RuntimeIOException e) {
if (e.getMessage().startsWith("ERROR: Incorrect format for the serialized coref graph")) {
// re-transfer or regenerate the file
} else throw e;
} Prevention
- Verify file integrity with checksums after transfer
- Use the same CoreNLP version to write and read serialized annotations
- Avoid manual edits to coref graph lines
- Test round-trip write/read when upgrading CoreNLP versions
When it happens
Trigger: Reading a serialized annotation whose coref graph line has a field count not divisible by 4 — a truncated/corrupted file or one written by an incompatible serializer version.
Common situations: Loading annotations serialized with a different CoreNLP version whose coref format changed; incomplete file transfers; hand-edited coref lines dropping a field.
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
- ERROR: Invalid dependency node line
- ERROR: Invalid format for dependency graph
- ERROR: Invalid format token for serialized token
- RuntimeIOException wrapping IOException
- Failed to save classifier
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/9c9a0947098a5415.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/pipeline/CustomAnnotationSerializer.java:426
}
@Override
public Pair<Annotation, InputStream> read(InputStream is) throws IOException {
if(compress && !(is instanceof GZIPInputStream)) is = new GZIPInputStream(is);
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
Annotation doc = new Annotation("");
String line;
// read the coref graph (new format)
Map<Integer, CorefChain> chains = loadCorefChains(reader);
if(chains != null) doc.set(CorefCoreAnnotations.CorefChainAnnotation.class, chains);
// read the coref graph (old format)
line = reader.readLine().trim();
if(line.length() > 0){
String [] bits = line.split(" ");
if(bits.length % 4 != 0){
throw new RuntimeIOException("ERROR: Incorrect format for the serialized coref graph: " + line);
}
List<Pair<IntTuple, IntTuple>> corefGraph = new ArrayList<>();
for(int i = 0; i < bits.length; i += 4){
IntTuple src = new IntTuple(2);
IntTuple dst = new IntTuple(2);
src.set(0, Integer.parseInt(bits[i]));
src.set(1, Integer.parseInt(bits[i + 1]));
dst.set(0, Integer.parseInt(bits[i + 2]));
dst.set(1, Integer.parseInt(bits[i + 3]));
corefGraph.add(new Pair<>(src, dst));
}
doc.set(CorefCoreAnnotations.CorefGraphAnnotation.class, corefGraph);
}
// read individual sentences
List<CoreMap> sentences = new ArrayList<>();
while((line = reader.readLine()) != null){
CoreMap sentence = new Annotation("");View on GitHub (pinned to 1b7edd19c4)