stanfordnlp/CoreNLP · error · IllegalArgumentException
conditionalLogProbsGivenPrevious requires given one less tha
Error message
conditionalLogProbsGivenPrevious requires given one less than clique size ( ) but was
What it means
Like conditionalLogProbGivenPrevious, conditionalLogProbsGivenPrevious (plural — returns the distribution over all classes) requires the conditioning context to be exactly windowSize-1 labels, since a FactorTable of windowSize needs one slot left for the label being predicted. Any other `given` length would index outside the table's logical layout, so it throws IllegalArgumentException immediately.
Solutions
- Ensure given.length == windowSize-1, taking windowSize from the FactorTable instance.
- When slicing a label sequence for position i, take the windowSize-1 labels immediately preceding i.
- Validate the array length yourself before the call and throw a descriptive error.
Example fix
// before int[] given = labels; // full sequence, wrong length double[] probs = ft.conditionalLogProbsGivenPrevious(given); // after int[] given = Arrays.copyOfRange(labels, pos - (ft.windowSize - 1), pos); double[] probs = ft.conditionalLogProbsGivenPrevious(given);
Defensive patterns
Strategy: validation
Validate before calling
// Java
if (given.length != ft.windowSize - 1) {
given = Arrays.copyOfRange(labels, pos - (ft.windowSize - 1), pos);
}
double[] probs = ft.conditionalLogProbsGivenPrevious(given); Try / catch
// Java
try {
result = ft.conditionalLogProbsGivenPrevious(given);
} catch (IllegalArgumentException e) {
// log window-size mismatch, rebuild `given` with correct length
result = ft.conditionalLogProbsGivenPrevious(
Arrays.copyOf(given, ft.windowSize - 1));
} Prevention
- Centralize context construction in one utility per CRF order.
- Unit-test FactorTable queries with arrays of the exact expected length.
- When switching models with different orders, audit all query call sites.
When it happens
Trigger: Calling conditionalLogProbsGivenPrevious(int[] given) with an array whose length is not windowSize-1: full-size clique arrays, empty arrays, or contexts sized from a different window.
Common situations: Migrating code between CRF models with different markov orders/window sizes; hand-assembling label histories in tests; an off-by-one when slicing a label sequence.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- conditionalLogProbGivenPrevious requires given one less than
- conditionalLogProbGivenFirst requires of one less than cliqu
- unnormalizedConditionalLogProbGivenFirst requires of one les
- conditionalLogProbGivenNext requires given one less than cli
- Unknown inference type: " + flags.inferenceType + ". Your op
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/392ebe3dba444245.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/ie/crf/FactorTable.java:291
// int i = indexOf(given, of);
// // if (SloppyMath.isDangerous(z) || SloppyMath.isDangerous(table[i])) {
// // log.info("z="+z);
// // log.info("t="+table[i]);
// // }
//
// return table[i];
// }
/**
* Computes the probabilities of the tag at the end of the table given that
* the previous tag sequence in table is GIVEN. given is at the beginning,
* position in question is at the end
*
* @return the probabilities of the tag at the end of the table
*/
public double[] conditionalLogProbsGivenPrevious(int[] given) {
if (given.length != windowSize - 1) {
throw new IllegalArgumentException("conditionalLogProbsGivenPrevious requires given one less than clique size (" +
windowSize + ") but was " + Arrays.toString(given));
}
double[] result = new double[numClasses];
for (int i = 0; i < numClasses; i++) {
result[i] = table[indexOf(given, i)];
}
ArrayMath.logNormalize(result);
return result;
}
/**
* Computes the probability of the sequence OF being at the end of the table
* given that the first tag in table is GIVEN. given is at the beginning, of is
* at the end
*
* @return the probability of the sequence of being at the end of the table
*/
public double conditionalLogProbGivenFirst(int given, int[] of) {View on GitHub (pinned to 1b7edd19c4)