{"record":{"id":"a4137aa2477a2c07","repo":"stanfordnlp/CoreNLP","slug":"incompatible-crfclassifier-windowsize-does-not-ma","errorCode":null,"errorMessage":"Incompatible CRFClassifier: windowSize does not match","messagePattern":"Incompatible CRFClassifier: windowSize does not match","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/ie/crf/CRFClassifier.java","lineNumber":358,"sourceCode":"      }\n    }\n  }\n\n  /**\n   * Combines weighted crf with this crf.\n   *\n   * @param crf Other CRF whose weights to combine into this CRF\n   * @param weight Amount to scale the other CRF's weights by\n   */\n  public void combine(CRFClassifier<IN> crf, double weight) {\n    Timing timer = new Timing();\n\n    // Check the CRFClassifiers are compatible\n    if (!this.pad.equals(crf.pad)) {\n      throw new RuntimeException(\"Incompatible CRFClassifier: pad does not match\");\n    }\n    if (this.windowSize != crf.windowSize) {\n      throw new RuntimeException(\"Incompatible CRFClassifier: windowSize does not match\");\n    }\n    if (this.labelIndices.size() != crf.labelIndices.size()) {\n      // Should match since this should be same as the windowSize\n      throw new RuntimeException(\"Incompatible CRFClassifier: labelIndices length does not match\");\n    }\n    this.classIndex.addAll(crf.classIndex.objectsList());\n\n    // Combine weights of the other classifier with this classifier,\n    // weighing the other classifier's weights by weight\n    // First merge the feature indices\n    int oldNumFeatures1 = this.featureIndex.size();\n    int oldNumFeatures2 = crf.featureIndex.size();\n    int oldNumWeights1 = this.getNumWeights();\n    int oldNumWeights2 = crf.getNumWeights();\n    this.featureIndex.addAll(crf.featureIndex.objectsList());\n    this.knownLCWords.addAll(crf.knownLCWords);\n    assert (weights.length == oldNumFeatures1);\n","sourceCodeStart":340,"sourceCodeEnd":376,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/ie/crf/CRFClassifier.java#L340-L376","documentation":"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.","triggerScenarios":"classifierA.combine(classifierB) where this.windowSize != crf.windowSize — one model was trained with a different flags.useSeq / left-right context width than the other.","commonSituations":"Combining a leftWindow/rightWindow=1 model with a wider-window model; mixing models trained with different 'useBefore'/'useAfter' flag settings.","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."],"exampleFix":"// before\nprops.setProperty(\"leftWindow\", \"2\"); // modelA\nprops.setProperty(\"leftWindow\", \"1\"); // modelB\n// after\nprops.setProperty(\"leftWindow\", \"1\"); // identical in both runs","handlingStrategy":"validation","validationCode":"if (modelA.windowSize != modelB.windowSize)\n  throw new IllegalStateException(\"windowSize differs: \" + modelA.windowSize + \" vs \" + modelB.windowSize);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["java","crf","model-combine","window-size"],"backgroundTag":"invalid-config-value","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}