stanfordnlp/CoreNLP · error · IllegalArgumentException
conditionalLogProbGivenFirst requires of one less than…
Error message
conditionalLogProbGivenFirst requires of one less than clique size ( ) but was
What it means
conditionalLogProbGivenFirst computes the log probability of the label at the FIRST position given a following sequence `of`; it requires `of` to contain exactly windowSize-1 labels so that `of` plus the first label fills the whole clique. A differently sized `of` cannot be combined with the fixed first position, so it throws.
Solutions
- Build `of` with exactly windowSize-1 labels (all clique positions except the first).
- Read windowSize from the FactorTable rather than assuming an order.
- If you meant to condition on a preceding context instead, use conditionalLogProbGivenPrevious, which validates `given` rather than `of`.
Example fix
// before (windowSize=3, needs 2)
ft.conditionalLogProbGivenFirst(0, new int[]{1});
// after
ft.conditionalLogProbGivenFirst(0, new int[]{1, 2}); Defensive patterns
Strategy: validation
Validate before calling
// Java
if (of.length != ft.windowSize - 1)
throw new IllegalArgumentException("'of' must have " + (ft.windowSize-1) + " labels");
double lp = ft.conditionalLogProbGivenFirst(given, of); Try / catch
// Java
try {
lp = ft.conditionalLogProbGivenFirst(first, of);
} catch (IllegalArgumentException e) {
System.err.println("Bad 'of' length " + of.length + " for window " + ft.windowSize);
// rebuild `of` before retrying
} Prevention
- Remember the asymmetry: GivenFirst/GivenNext validate different args than GivenPrevious — check each method's contract.
- Fill `of` with all clique positions except the first.
- Derive sizes from ft.windowSize, not from the previous model's order.
When it happens
Trigger: Calling conditionalLogProbGivenFirst(int given, int[] of) where of.length != windowSize-1 — e.g. passing a single label where the table window is 3 (needs 2), or an array sized for a different window.
Common situations: Reusing query code written for order-1 CRFs on order-2+ tables; hardcoding `of` arrays in tests/demo main methods; confusing this method with the *GivenPrevious variants which validate the other argument.
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…
- 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/7915bf7add06245b.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/ie/crf/FactorTable.java:311
}
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) {
if (of.length != windowSize - 1) {
throw new IllegalArgumentException("conditionalLogProbGivenFirst requires of one less than clique size (" +
windowSize + ") but was " + Arrays.toString(of));
}
// compute P(given, of)
// double probAll = logProb(labels);
double probAll = unnormalizedLogProb(given, of, windowSize - 1);
// compute P(given)
// double probGiven = logProbFront(given);
double probGiven = unnormalizedLogProbFront(given);
// compute P(given, of) / P(given)
return probAll - probGiven;
}
/**
* 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.View on GitHub (pinned to 1b7edd19c4)