stanfordnlp/CoreNLP · error · RuntimeException

Incompatible CRFClassifier: windowSize does not match

Error message

Incompatible CRFClassifier: windowSize does not match

What it means

combine() requires the two CRF classifiers to use the same window size, since feature weight matrices and labelIndices are dimensioned by the window. A differing windowSize means the models' labelIndices (one per position in the window) cannot correspond, so the merge throws a RuntimeException.

Solutions

  1. Retrain both classifiers with the same window settings (matching leftWindow/rightWindow / useBefore/useAfter flags).
  2. Verify flags of both training runs before combining models.
  3. If models must differ, keep them separate and combine outputs at the prediction level instead of merging weights.

Example fix

// before
props.setProperty("leftWindow", "2"); // modelA
props.setProperty("leftWindow", "1"); // modelB
// after
props.setProperty("leftWindow", "1"); // identical in both runs
Defensive patterns

Strategy: validation

Validate before calling

if (modelA.windowSize != modelB.windowSize)
  throw new IllegalStateException("windowSize differs: " + modelA.windowSize + " vs " + modelB.windowSize);

Prevention

When it happens

Trigger: classifierA.combine(classifierB) where this.windowSize != crf.windowSize — one model was trained with a different flags.useSeq / left-right context width than the other.

Common situations: Combining a leftWindow/rightWindow=1 model with a wider-window model; mixing models trained with different 'useBefore'/'useAfter' flag settings.

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


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

Appendix: source

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

      }
    }
  }

  /**
   * 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);

View on GitHub (pinned to 1b7edd19c4)