stanfordnlp/CoreNLP · error · RuntimeException

Incompatible CRFClassifier: labelIndices length does not…

Error message

Incompatible CRFClassifier: labelIndices length does not match

What it means

combine() checks that both classifiers' labelIndices lists have the same size; since labelIndices should have one entry per window position (i.e. size == windowSize), a mismatch indicates structurally incompatible models that cannot share weight matrices.

Solutions

  1. Retrain both models with the same CoreNLP version and identical flags so labelIndices match.
  2. Confirm windowSize matches first (the earlier check) — fixing the window flags usually fixes labelIndices too.
  3. Serialize and reload both models in the same library version before combining.

Example fix

// before
CRFClassifier m2015 = CRFClassifier.getClassifier("old-model.gz"); // trained with old NLP version
// after: retrain old-model with current CoreNLP, then combine
currentModel.combine(retrainedModel);
Defensive patterns

Strategy: validation

Validate before calling

if (modelA.labelIndices.size() != modelB.labelIndices.size())
  throw new IllegalStateException("labelIndices sizes differ: " + modelA.labelIndices.size() + " vs " + modelB.labelIndices.size());

Prevention

When it happens

Trigger: classifierA.combine(classifierB) where this.labelIndices.size() != crf.labelIndices.size() — typically a consequence of different window sizes or models trained/serialized by different CoreNLP versions with different label indexing.

Common situations: Merging models from different Stanford NLP versions; models trained with incompatible flags; corrupted or partially loaded serialized classifiers.

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/2f91cdb2550663ec. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/ie/crf/CRFClassifier.java:362

  /**
   * Combines weighted crf with this crf.
   *
   * @param crf Other CRF whose weights to combine into this CRF
   * @param weight Amount to scale the other CRF's weights by
   */
  public void combine(CRFClassifier<IN> crf, double weight) {
    Timing timer = new Timing();

    // Check the CRFClassifiers are compatible
    if (!this.pad.equals(crf.pad)) {
      throw new RuntimeException("Incompatible CRFClassifier: pad does not match");
    }
    if (this.windowSize != crf.windowSize) {
      throw new RuntimeException("Incompatible CRFClassifier: windowSize does not match");
    }
    if (this.labelIndices.size() != crf.labelIndices.size()) {
      // Should match since this should be same as the windowSize
      throw new RuntimeException("Incompatible CRFClassifier: labelIndices length does not match");
    }
    this.classIndex.addAll(crf.classIndex.objectsList());

    // Combine weights of the other classifier with this classifier,
    // weighing the other classifier's weights by weight
    // First merge the feature indices
    int oldNumFeatures1 = this.featureIndex.size();
    int oldNumFeatures2 = crf.featureIndex.size();
    int oldNumWeights1 = this.getNumWeights();
    int oldNumWeights2 = crf.getNumWeights();
    this.featureIndex.addAll(crf.featureIndex.objectsList());
    this.knownLCWords.addAll(crf.knownLCWords);
    assert (weights.length == oldNumFeatures1);

    // Combine weights of this classifier with other classifier
    for (int i = 0; i < labelIndices.size(); i++) {
      this.labelIndices.get(i).addAll(crf.labelIndices.get(i).objectsList());
    }

View on GitHub (pinned to 1b7edd19c4)