stanfordnlp/CoreNLP · error · IllegalArgumentException
conditionalLogProbGivenNext requires given one less than…
Error message
conditionalLogProbGivenNext requires given one less than clique size ( ) but was
What it means
conditionalLogProbGivenNext computes the log probability of a label at the END of the window given the NEXT windowSize-1 labels. It validates that `given` has exactly windowSize-1 entries so the given context plus the predicted label fills the clique. Other lengths cannot be mapped onto the table's indices and throw IllegalArgumentException.
Solutions
- Pass exactly windowSize-1 following labels, taking windowSize from the FactorTable.
- When scanning backwards, slice labels from i+1 to i+windowSize (exclusive), yielding windowSize-1 entries.
- Validate lengths defensively before calling FactorTable query methods.
Example fix
// before int[] given = Arrays.copyOfRange(labels, pos+1, labels.length); ft.conditionalLogProbGivenNext(given, labels[pos]); // after int[] given = Arrays.copyOfRange(labels, pos+1, pos+1 + (ft.windowSize - 1)); ft.conditionalLogProbGivenNext(given, labels[pos]);
Defensive patterns
Strategy: validation
Validate before calling
// Java
int end = Math.min(pos + 1 + (ft.windowSize - 1), labels.length);
int[] given = Arrays.copyOfRange(labels, pos + 1, end);
if (given.length != ft.windowSize - 1)
throw new IllegalArgumentException("insufficient following context");
double lp = ft.conditionalLogProbGivenNext(given, label); Try / catch
// Java
try {
lp = ft.conditionalLogProbGivenNext(given, of);
} catch (IllegalArgumentException e) {
// rebuild given with exactly windowSize-1 following labels
} Prevention
- For backward scans, slice exactly windowSize-1 labels after the current position.
- Guard sequence boundaries — near the end of the sequence there may not be enough following context.
- Reuse a shared context-building helper across all FactorTable query methods.
When it happens
Trigger: Calling conditionalLogProbGivenNext(int[] given, int of) with given.length != windowSize-1 — e.g. passing the whole following sequence instead of the next windowSize-1 labels, or reusing an array sized for another order.
Common situations: Bidirectional/backward scanning code over a label sequence that slices the wrong window length; demos/tests (this method is only reached via main per the call graph) with hardcoded label arrays; mixing order-1 and order-2 assumptions.
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…
- conditionalLogProbsGivenPrevious requires given one less…
- conditionalLogProbGivenFirst requires of one less than…
- unnormalizedConditionalLogProbGivenFirst requires of one…
- Unknown inference type: " + flags.inferenceType + ". Your…
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/6a04c6805e0d6187.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/ie/crf/FactorTable.java:360
// compute P(given)
// double probGiven = logProbFront(given);
// double probGiven = unnormalizedLogProbFront(given);
// compute P(given, of) / P(given)
// return probAll - probGiven;
return probAll;
}
/**
* Computes the probability of the tag OF being at the beginning of the table
* given that the tag sequence GIVEN is at the end of the table. given is at
* the end, of is at the beginning
*
* @return the probability of the tag of being at the beginning of the table
*/
public double conditionalLogProbGivenNext(int[] given, int of) {
if (given.length != windowSize - 1) {
throw new IllegalArgumentException("conditionalLogProbGivenNext requires given one less than clique size (" +
windowSize + ") but was " + Arrays.toString(given));
}
int[] label = indicesEnd(given);
double[] masses = new double[label.length];
for (int i = 0; i < masses.length; i++) {
masses[i] = table[label[i]];
}
return table[indexOf(of, given)] - ArrayMath.logSum(masses);
}
public double unnormalizedLogProbFront(int[] labels) {
int startIndex = indicesFront(labels);
int numCellsToSum = SloppyMath.intPow(numClasses, windowSize - labels.length);
// double[] masses = new double[labels.length];
// for (int i = 0; i < masses.length; i++) {
// masses[i] = table[labels[i]];
// }
return ArrayMath.logSum(table, startIndex, startIndex + numCellsToSum);View on GitHub (pinned to 1b7edd19c4)