stanfordnlp/CoreNLP · error · IllegalStateException
neg log lik smaller than 0: " + s
Error message
neg log lik smaller than 0: " + s
What it means
LambdaSolve's log-likelihood computation (2LogLikelihood / related CG variant) asserts an internal invariant: the negative log likelihood over the model must never be negative. A negative value means the computed conditional probabilities are inconsistent, so it throws IllegalStateException.
Solutions
- Verify the lambdas were produced for the SAME problem instance (same features and data) being evaluated
- Re-train the model instead of loading questionable lambdas
- Sanity-check lambda values (magnitude, NaN) before computing likelihood
Example fix
// before
double ll = problem.twoLogLikelihood(lambdasFromOtherProblem);
// after
if (lambdasFromOtherProblem.length != problem.fValues.length) {
throw new IllegalArgumentException("Lambda vector does not match this problem");
}
double ll = problem.twoLogLikelihood(lambdasFromOtherProblem); Defensive patterns
Strategy: validation
Validate before calling
if (lambdas.length != expectedLambdaCount || Arrays.stream(lambdas).anyMatch(v -> !Double.isFinite(v))) {
throw new IllegalArgumentException("Lambdas invalid or mismatched with problem");
} Try / catch
try { double s = problem.check(lambdas); } catch (IllegalStateException e) { /* reload matching model or retrain */ } Prevention
- Keep lambdas and problem instance paired as one artifact
- Validate lambda finiteness and length before evaluation
- Retrain rather than mixing model files
When it happens
Trigger: Computing log likelihood after IIS/LCG training when lambdas have drifted to values making the sum s negative — e.g. calling p_iCond / 2LogLikelihood with lambdas read from an incompatible or corrupted model file.
Common situations: Loading lambdas trained on a different problem (different features/empirical distributions); numerical precision drift with extreme lambda values; manual lambda edits.
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
- oldTag starts with B, entity at position should not be null
- node cliqueFeatures[n]=
- edge cliqueFeatures[n]=
- : Inconsistent u2b/b2u arrays.
- Suffix pointer moved too far!
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/d60f68f7c07b21c4.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/maxent/iis/LambdaSolve.java:914
} //for
} //for fNo
for (int x = 0; x < probConds.length; x++) {
//again
zlambda[x] = ArrayMath.logSum(probConds[x]); // cpu samples #4,#15: 4.5%
//log.info("zlambda "+x+" "+zlambda[x]);
s += zlambda[x] * p.data.ptildeX(x) * p.data.getNumber();
for (int y = 0; y < probConds[x].length; y++) {
probConds[x][y] = divide(probConds[x][y], zlambda[x]); // cpu samples #13: 1.6%
//log.info("prob "+x+" "+y+" "+probConds[x][y]);
} //y
}//x
if (s < 0) {
throw new IllegalStateException("neg log lik smaller than 0: " + s);
}
return s;
}
// -- stuff for CG version below -------
/**
* calculate the log likelihood from scratch, hashing the conditional
* probabilities in pcond which we will use for the derivative later.
*
* @return The log likelihood of the data
*/
public double logLikelihoodScratch() {
// zero all the variables
double s = 0;
for (int i = 0; i < probConds.length; i++) {
for (int j = 0; j < probConds[i].length; j++) {View on GitHub (pinned to 1b7edd19c4)