stanfordnlp/CoreNLP · error · IllegalArgumentException
conditionalLogProbGivenPrevious requires given one less…
Error message
conditionalLogProbGivenPrevious requires given one less than clique size ( ) but was
What it means
FactorTable models a clique of `windowSize` labels. conditionalLogProbGivenPrevious computes the log probability of the last label given the previous `windowSize-1` labels, and it validates that the `given` array is exactly windowSize-1 long before indexing. Passing any other length means the caller has built the conditioning context for the wrong clique size.
Solutions
- Build `given` with exactly windowSize-1 labels: new int[table.windowSize()-1].
- If the code supports multiple window sizes, derive the length from the FactorTable (windowSize) instead of hardcoding.
- If you have the full clique, drop the last (or the position you're predicting) element before calling.
Example fix
// before
int[] given = {0, 1, 2}; // 3 labels for a window of 3
ft.conditionalLogProbGivenPrevious(given, 4);
// after
int[] given = {1, 2}; // windowSize-1 = 2 labels
ft.conditionalLogProbGivenPrevious(given, 4); Defensive patterns
Strategy: validation
Validate before calling
// Java: check before calling
if (given.length != ft.windowSize - 1)
throw new IllegalArgumentException("need " + (ft.windowSize-1) + " labels, got " + given.length);
double lp = ft.conditionalLogProbGivenPrevious(given, of); Try / catch
// Java
try {
double lp = ft.conditionalLogProbGivenPrevious(given, of);
} catch (IllegalArgumentException e) {
// rebuild context with windowSize-1 labels and retry
int[] fixed = Arrays.copyOf(given, ft.windowSize - 1);
double lp = ft.conditionalLogProbGivenPrevious(fixed, of);
} Prevention
- Always derive context length from the FactorTable's windowSize, never hardcode.
- Slice label histories with Arrays.copyOfRange(seq, pos-(windowSize-1), pos).
- Write a helper method that builds clique contexts for all FactorTable queries.
When it happens
Trigger: Calling conditionalLogProbGivenPrevious(int[] given, int of) with given.length != windowSize-1 — e.g. passing a full clique of labels, an empty array, or a context built for a different window size.
Common situations: Copy-pasting example code written for a different CRF window size (e.g. order-1 vs order-2 CRFs); constructing the `given` array manually with off-by-one length; calling it in unit tests or `main` with hardcoded label arrays.
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
- conditionalLogProbsGivenPrevious requires given one less…
- conditionalLogProbGivenFirst requires of one less than…
- unnormalizedConditionalLogProbGivenFirst requires of one…
- conditionalLogProbGivenNext requires given one less than…
- Unknown inference type: " + flags.inferenceType + ". Your…
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/4e4c94781d44809c.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/ie/crf/FactorTable.java:242
public double logProb(int[] label) {
return unnormalizedLogProb(label) - totalMass();
}
public double prob(int[] label) {
return Math.exp(unnormalizedLogProb(label) - totalMass());
}
/**
* Computes the probability of the tag OF being at the end of the table given
* that the previous tag sequence in table is GIVEN. given is at the beginning,
* of is at the end.
*
* @return the probability of the tag OF being at the end of the table
*/
public double conditionalLogProbGivenPrevious(int[] given, int of) {
if (given.length != windowSize - 1) {
throw new IllegalArgumentException("conditionalLogProbGivenPrevious requires given one less than clique size (" +
windowSize + ") but was " + Arrays.toString(given));
}
// Note: other similar methods could be optimized like this one, but this is the one the CRF uses....
/*
int startIndex = indicesFront(given);
int numCellsToSum = SloppyMath.intPow(numClasses, windowSize - given.length);
double z = ArrayMath.logSum(table, startIndex, startIndex + numCellsToSum);
int i = indexOf(given, of);
System.err.printf("startIndex is %d, numCellsToSum is %d, i is %d (of is %d)%n", startIndex, numCellsToSum, i, of);
*/
int startIndex = indicesFront(given);
double z = ArrayMath.logSum(table, startIndex, startIndex + numClasses);
int i = startIndex + of;
// System.err.printf("startIndex is %d, numCellsToSum is %d, i is %d (of is %d)%n", startIndex, numClasses, i, of);
return table[i] - z;
}
View on GitHub (pinned to 1b7edd19c4)