stanfordnlp/CoreNLP · error · RuntimeException
format error in embeddings
Error message
format error in embeddings
What it means
Thrown when flags.useEmbedding is true but the line expected after <flags> does not start with 'embeddings.size()='. The embedding section of the text-serialized model is missing or malformed even though the model flags declare embeddings.
Solutions
- Restore the 'embeddings.size()=<int>' section after the <flags> block, matching useEmbedding=true
- Either supply a complete model with embeddings or re-serialize with useEmbedding=false if embeddings are not needed
- Re-export the model from the training run rather than editing it
- Check for end-of-file truncation and compare with the original checksum
Example fix
// before: embeddings stripped from model while flags still say useEmbedding=true
// after: re-serialize the full model (or disable embeddings before training/saving)
flags.useEmbedding = false; // when re-training without embeddings
crf.writeModel(new File("model.txt")); // keeps flags and sections consistent Defensive patterns
Strategy: validation
Validate before calling
// Verify embeddings section presence when the model declares useEmbedding
static boolean embeddingsSectionConsistent(String modelPath) throws IOException {
boolean useEmbedding = false;
try (BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(modelPath), "UTF-8"))) {
String line;
while ((line = br.readLine()) != null) {
if (line.startsWith("useEmbedding=")) useEmbedding = line.endsWith("true");
if (line.startsWith("embeddings.size()=")) return true;
}
}
return !useEmbedding;
} Try / catch
try {
CRFClassifier<CoreLabel> model = CRFClassifier.getClassifier(modelPath);
} catch (RuntimeException e) {
if ("format error in embeddings".equals(e.getMessage())) {
throw new IllegalStateException("Model declares useEmbedding=true but the embeddings section is missing/malformed. Re-export the full model.", e);
}
throw e;
} Prevention
- Do not strip the embedding section from models without changing useEmbedding=false
- Re-export full models rather than editing them to shrink them
- Verify the tail of the file is not truncated (embeddings live near the end)
- Keep training-time flags consistent with the exported model
When it happens
Trigger: CRFClassifier.getClassifier on a model with useEmbedding=true whose embedding section header line is missing, altered, or whose contents were stripped (e.g. embeddings removed to shrink the file without updating flags).
Common situations: Manually deleting the embedding block to reduce file size; converting the model between versions losing the embeddings section; truncation at the end of the file where embeddings are stored.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- format error unexpected featureFactory line:
- Error loading classifier from
- Unexpected number of field , expected >= for line (,):
- First line of input file should be header definition
- weights format error
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/e48236e5dab00805.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/ie/crf/CRFClassifier.java:2212
line = br.readLine();
while (!line.equals("</flags>")) {
// log.info("DEBUG: flags line: "+line);
String[] keyValue = line.split("=");
// System.err.printf("DEBUG: p.setProperty(%s,%s)%n", keyValue[0],
// keyValue[1]);
p.setProperty(keyValue[0], keyValue[1]);
line = br.readLine();
}
// log.info("DEBUG: out from flags");
flags = new SeqClassifierFlags(p);
if (flags.useEmbedding) {
line = br.readLine();
toks = line.split("\\t");
if (!toks[0].equals("embeddings.size()=")) {
throw new RuntimeException("format error in embeddings");
}
int embeddingSize = Integer.parseInt(toks[1]);
embeddings = Generics.newHashMap(embeddingSize);
count = 0;
while (count < embeddingSize) {
line = br.readLine().trim();
toks = line.split("\\t");
String word = toks[0];
double[] arr = ArrayUtils.toDoubleArray(toks[1].split(" "));
embeddings.put(word, arr);
count++;
}
}
// <featureFactory>
// edu.stanford.nlp.wordseg.Gale2007ChineseSegmenterFeatureFactory
// </featureFactory>
line = br.readLine();View on GitHub (pinned to 1b7edd19c4)