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
- Retrain both classifiers with the same window settings (matching leftWindow/rightWindow / useBefore/useAfter flags).
- Verify flags of both training runs before combining models.
- 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
- Use identical leftWindow/rightWindow (useBefore/useAfter) flags in all training runs.
- Log windowSize when serializing models.
- Refuse to combine models trained with different context widths at pipeline setup time.
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
- Unknown feature type " + feature
- Incompatible CRFClassifier: weight length mismatch for…
- Incompatible CRFClassifier: pad does not match
- Incompatible CRFClassifier: labelIndices length does not…
- Word " + wordCount + " (\"" +…
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)