stanfordnlp/CoreNLP · error · Exception
Number of thresholds and number of labels do not match.
Error message
Number of thresholds and number of labels do not match.
What it means
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.
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
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at src/edu/stanford/nlp/classify/LinearClassifier.java:1255 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/8b2d26ac53026379.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/classify/LinearClassifier.java:1255
* @param featureIndex An index from F to integers used to index the features in the weights array
* @param labelIndex An index from L to integers used to index the labels in the weights array
*/
public LinearClassifier(double[][] weights, Index<F> featureIndex, Index<L> labelIndex) {
this.featureIndex = featureIndex;
this.labelIndex = labelIndex;
this.weights = weights;
thresholds = new double[labelIndex.size()];
// Arrays.fill(thresholds, 0.0); // not needed; Java arrays zero initialized
}
// todo: This is unused and seems broken (ignores passed in thresholds)
public LinearClassifier(double[][] weights, Index<F> featureIndex, Index<L> labelIndex,
double[] thresholds) throws Exception {
this.featureIndex = featureIndex;
this.labelIndex = labelIndex;
this.weights = weights;
if (thresholds.length != labelIndex.size())
throw new Exception("Number of thresholds and number of labels do not match.");
thresholds = new double[thresholds.length];
int curr = 0;
for (double tval : thresholds) {
thresholds[curr++] = tval;
}
Arrays.fill(thresholds, 0.0);
}
private static <F, L> Counter<Pair<F, L>> makeWeightCounter(double[] weights, Index<Pair<F, L>> weightIndex) {
Counter<Pair<F,L>> weightCounter = new ClassicCounter<>();
for (int i = 0; i < weightIndex.size(); i++) {
if (weights[i] == 0) {
continue; // no need to save 0 weights
}
weightCounter.setCount(weightIndex.get(i), weights[i]);
}
return weightCounter;
}View on GitHub (pinned to 1b7edd19c4)