{"record":{"id":"2f91cdb2550663ec","repo":"stanfordnlp/CoreNLP","slug":"incompatible-crfclassifier-labelindices-length-do","errorCode":null,"errorMessage":"Incompatible CRFClassifier: labelIndices length does not match","messagePattern":"Incompatible CRFClassifier: labelIndices length does not match","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/ie/crf/CRFClassifier.java","lineNumber":362,"sourceCode":"  /**\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\n    // Combine weights of this classifier with other classifier\n    for (int i = 0; i < labelIndices.size(); i++) {\n      this.labelIndices.get(i).addAll(crf.labelIndices.get(i).objectsList());\n    }","sourceCodeStart":344,"sourceCodeEnd":380,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/ie/crf/CRFClassifier.java#L344-L380","documentation":"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.","triggerScenarios":"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.","commonSituations":"Merging models from different Stanford NLP versions; models trained with incompatible flags; corrupted or partially loaded serialized classifiers.","solutions":["Retrain both models with the same CoreNLP version and identical flags so labelIndices match.","Confirm windowSize matches first (the earlier check) — fixing the window flags usually fixes labelIndices too.","Serialize and reload both models in the same library version before combining."],"exampleFix":"// before\nCRFClassifier m2015 = CRFClassifier.getClassifier(\"old-model.gz\"); // trained with old NLP version\n// after: retrain old-model with current CoreNLP, then combine\ncurrentModel.combine(retrainedModel);","handlingStrategy":"validation","validationCode":"if (modelA.labelIndices.size() != modelB.labelIndices.size())\n  throw new IllegalStateException(\"labelIndices sizes differ: \" + modelA.labelIndices.size() + \" vs \" + modelB.labelIndices.size());","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Serialize, load, and combine models under one CoreNLP version.","Check labelIndices equality before merging.","Pin the Stanford NLP version across training and merging pipelines."],"tags":["java","crf","model-combine","label-indices"],"backgroundTag":"schema-validation-failed","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"}