stanfordnlp/CoreNLP · error · RuntimeException

format error

Error message

format error

What it means

While parsing the nodeFeatureIndicesMap section of a text-serialized CRFClassifierNonlinear model, each entry line must be "<index>\t<value>" where the index exactly equals the running count. If the parsed line index does not match the expected sequential position, this RuntimeException is thrown. It indicates entries are missing, duplicated, reordered, or the file is misaligned.

Solutions

  1. Regenerate the model file with serializeTextClassifier instead of editing it manually.
  2. Verify each entry line is "i\tvalue" with strictly sequential indices starting at 0.
  3. Check the declared size header matches the actual number of entry lines.
  4. Re-transfer the file if it was truncated or corrupted in transit.
  5. If programmatic merging is needed, rewrite indices sequentially rather than splicing files.

Example fix

// before
0	5
2	7   // index 1 missing -> format error
// after
0	5
1	7
Defensive patterns

Strategy: validation

Validate before calling

// Validate the nodeFeatureIndicesMap section is sequential before loading:
// Expected format after the header: lines "i\tvalue" with i = 0..size-1
// e.g. grep -n "^[0-9]*\\t" model.txt | awk -F'\\t' '$1 != NR-2 {print "bad index at line", NR}'

Try / catch

try {
  crf = CRFClassifier.getClassifier(modelPath);
} catch (Exception e) {
  if (String.valueOf(e.getMessage()).equals("format error")) {
    throw new IOException("Non-sequential or missing entry in model index section: " + modelPath, e);
  }
  throw e;
}

Prevention

When it happens

Trigger: loadTextClassifier reads lines after the nodeFeatureIndicesMap.size() header and encounters an entry whose leading index is not equal to the loop counter count, e.g. a deleted/duplicated line, an out-of-order edit, or misaligned lines after a malformed header elsewhere in the file.

Common situations: Hand-edited or diff-merged model files; truncated downloads cutting lines; concatenating model files; a size header that disagrees with the actual number of entries.

Related errors


AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10). Data as JSON: /api/errors/6a9c77773d87517c. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/ie/crf/CRFClassifierNonlinear.java:258

  @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()=")) {
      throw new RuntimeException("format error");
    }
    int edgeFeatureIndicesMapSize = Integer.parseInt(toks[1]);
    edgeFeatureIndicesMap = new HashIndex<>();
    count = 0;
    while (count < edgeFeatureIndicesMapSize) {
      line = br.readLine();
      toks = line.split("\\t");
      int idx = Integer.parseInt(toks[0]);
      if (count != idx) {

View on GitHub (pinned to 1b7edd19c4)