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

  1. Restore the 'embeddings.size()=<int>' section after the <flags> block, matching useEmbedding=true
  2. Either supply a complete model with embeddings or re-serialize with useEmbedding=false if embeddings are not needed
  3. Re-export the model from the training run rather than editing it
  4. 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

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


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)