{"record":{"id":"8b2d26ac53026379","repo":"stanfordnlp/CoreNLP","slug":"number-of-thresholds-and-number-of-labels-do-not-m","errorCode":null,"errorMessage":"Number of thresholds and number of labels do not match.","messagePattern":"Number of thresholds and number of labels do not match\\.","errorType":"validation","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/classify/LinearClassifier.java","lineNumber":1255,"sourceCode":"   *  @param featureIndex An index from F to integers used to index the features in the weights array\n   *  @param labelIndex An index from L to integers used to index the labels in the weights array\n   */\n  public LinearClassifier(double[][] weights, Index<F> featureIndex, Index<L> labelIndex) {\n    this.featureIndex = featureIndex;\n    this.labelIndex = labelIndex;\n    this.weights = weights;\n    thresholds = new double[labelIndex.size()];\n    // Arrays.fill(thresholds, 0.0); // not needed; Java arrays zero initialized\n  }\n\n  // todo: This is unused and seems broken (ignores passed in thresholds)\n  public LinearClassifier(double[][] weights, Index<F> featureIndex, Index<L> labelIndex,\n      double[] thresholds) throws Exception {\n    this.featureIndex = featureIndex;\n    this.labelIndex = labelIndex;\n    this.weights = weights;\n    if (thresholds.length != labelIndex.size())\n      throw new Exception(\"Number of thresholds and number of labels do not match.\");\n    thresholds = new double[thresholds.length];\n    int curr = 0;\n    for (double tval : thresholds) {\n      thresholds[curr++] = tval;\n    }\n    Arrays.fill(thresholds, 0.0);\n  }\n\n  private static <F, L> Counter<Pair<F, L>> makeWeightCounter(double[] weights, Index<Pair<F, L>> weightIndex) {\n    Counter<Pair<F,L>> weightCounter = new ClassicCounter<>();\n    for (int i = 0; i < weightIndex.size(); i++) {\n      if (weights[i] == 0) {\n        continue; // no need to save 0 weights\n      }\n      weightCounter.setCount(weightIndex.get(i), weights[i]);\n    }\n    return weightCounter;\n  }","sourceCodeStart":1237,"sourceCodeEnd":1273,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/classify/LinearClassifier.java#L1237-L1273","documentation":"A guard IllegalArgumentException thrown when caller-supplied thresholds array length differs from the number of labels in the labelIndex while loading weights into a LinearClassifier; thresholds are indexed per label, so a mismatch means the weights/threshold array was built for a different label set.","triggerScenarios":"Thrown at src/edu/stanford/nlp/classify/LinearClassifier.java:1255 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Provide one threshold per label (thresholds.length == labelIndex.size())","Rebuild the thresholds array from the label index","Pass a null/empty thresholds if defaults are desired where supported"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}