{"record":{"id":"4b3439de81adbb57","repo":"stanfordnlp/CoreNLP","slug":"incompatible-crfclassifier-pad-does-not-match","errorCode":null,"errorMessage":"Incompatible CRFClassifier: pad does not match","messagePattern":"Incompatible CRFClassifier: pad does not match","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/ie/crf/CRFClassifier.java","lineNumber":355,"sourceCode":"        CRFLabel newLabels = crfLabelMap.get(labels);\n        int k = this.labelIndices.get(featureTypeIndex).indexOf(newLabels);\n        weights[newIndex][k] += crf.weights[i][j] * weight;\n      }\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());","sourceCodeStart":337,"sourceCodeEnd":373,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/ie/crf/CRFClassifier.java#L337-L373","documentation":"combine() first checks the two CRFClassifiers are compatible; the 'pad' string (used to pad out-of-range context in windowed features) must be identical. Different pad values would make feature names from the two models inconsistent, so the merge is refused with a RuntimeException.","triggerScenarios":"classifierA.combine(classifierB) where this.pad != crf.pad — the models were trained with different SeqClassifierFlags.pad values (or one was trained with the default and the other with a custom pad).","commonSituations":"Merging models trained under different flag configurations; copying flags incompletely between training runs; mixing serialized models from different projects.","solutions":["Retrain the models with the same pad setting (flags.pad) before combining.","Check and align SeqClassifierFlags between the two training runs.","If pads only differ cosmetically and feature suffixes are unaffected, consider editing flags rather than code — but the safe fix is retraining with matching flags."],"exampleFix":"// before: train modelB with -pad \"##\"\n// after: train both models with identical flags, e.g.\nprops.setProperty(\"pad\", \"-LRB-\"); // same value for both training runs","handlingStrategy":"validation","validationCode":"if (!modelA.pad.equals(modelB.pad))\n  throw new IllegalStateException(\"pad differs: \" + modelA.pad + \" vs \" + modelB.pad);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep a single shared properties file for all training runs of models you will combine.","Record flags (pad, windowSize) in model metadata at training time.","Diff SeqClassifierFlags of both models before merging."],"tags":["java","crf","model-combine","config-mismatch"],"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"}