stanfordnlp/CoreNLP · error · IllegalArgumentException
Initial weights are invalid!
Error message
Initial weights are invalid!
What it means
A sanity-check failure in LinearClassifierFactory: the user-supplied initial weight vector does not match the dimensions of the training dataset's feature/label index (e.g. wrong length or NaN entries), so optimization cannot start from it.
Solutions
- Pass an initial weights array of finite doubles with the correct dimension
- Initialize weights to zeros if unsure
- Validate upstream computations that produced the initial weights
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at src/edu/stanford/nlp/classify/LinearClassifierFactory.java:924 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/5411ad26054a5e9d.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/classify/LinearClassifierFactory.java:924
LinearClassifier<L, F> classifier = new LinearClassifier<>(objective.to2D(weights), dataset.featureIndex(), dataset.labelIndex());
return classifier;
}
@Override
public LinearClassifier<L, F> trainClassifier(GeneralDataset<L, F> dataset) {
return trainClassifier(dataset, null);
}
public LinearClassifier<L, F> trainClassifier(GeneralDataset<L, F> dataset, double[] initial) {
// Sanity check
if (dataset instanceof RVFDataset) {
((RVFDataset<L, F>) dataset).ensureRealValues();
}
if (initial != null) {
for (double weight : initial) {
if (Double.isNaN(weight) || Double.isInfinite(weight)) {
throw new IllegalArgumentException("Initial weights are invalid!");
}
}
}
// Train classifier
double[][] weights = trainWeights(dataset, initial, false);
LinearClassifier<L, F> classifier = new LinearClassifier<>(weights, dataset.featureIndex(), dataset.labelIndex());
return classifier;
}
public LinearClassifier<L, F> trainClassifierWithInitialWeights(GeneralDataset<L, F> dataset, double[][] initialWeights2D) {
double[] initialWeights = (initialWeights2D != null)? ArrayUtils.flatten(initialWeights2D):null;
return trainClassifier(dataset, initialWeights);
}
public LinearClassifier<L, F> trainClassifierWithInitialWeights(GeneralDataset<L, F> dataset, LinearClassifier<L,F> initialClassifier) {
double[][] initialWeights2D = (initialClassifier != null)? initialClassifier.weights():null;
return trainClassifierWithInitialWeights(dataset, initialWeights2D);
}View on GitHub (pinned to 1b7edd19c4)