{"record":{"id":"7915bf7add06245b","repo":"stanfordnlp/CoreNLP","slug":"conditionallogprobgivenfirst-requires-of-one-less","errorCode":null,"errorMessage":"conditionalLogProbGivenFirst requires of one less than clique size ( ) but was ","messagePattern":"conditionalLogProbGivenFirst requires of one less than clique size \\( \\) but was ","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/ie/crf/FactorTable.java","lineNumber":311,"sourceCode":"    }\n    double[] result = new double[numClasses];\n    for (int i = 0; i < numClasses; i++) {\n      result[i] = table[indexOf(given, i)];\n    }\n    ArrayMath.logNormalize(result);\n    return result;\n  }\n\n  /**\n   * Computes the probability of the sequence OF being at the end of the table\n   * given that the first tag in table is GIVEN. given is at the beginning, of is\n   * at the end\n   *\n   * @return the probability of the sequence of being at the end of the table\n   */\n  public double conditionalLogProbGivenFirst(int given, int[] of) {\n    if (of.length != windowSize - 1) {\n      throw new IllegalArgumentException(\"conditionalLogProbGivenFirst requires of one less than clique size (\" +\n          windowSize + \") but was \" + Arrays.toString(of));\n    }\n    // compute P(given, of)\n    // double probAll = logProb(labels);\n    double probAll = unnormalizedLogProb(given, of, windowSize - 1);\n\n    // compute P(given)\n    // double probGiven = logProbFront(given);\n    double probGiven = unnormalizedLogProbFront(given);\n\n    // compute P(given, of) / P(given)\n    return probAll - probGiven;\n  }\n\n  /**\n   * Computes the probability of the sequence OF being at the end of the table\n   * given that the first tag in table is GIVEN. given is at the beginning, of is\n   * at the end.","sourceCodeStart":293,"sourceCodeEnd":329,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/ie/crf/FactorTable.java#L293-L329","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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`."],"exampleFix":"// before (windowSize=3, needs 2)\nft.conditionalLogProbGivenFirst(0, new int[]{1});\n\n// after\nft.conditionalLogProbGivenFirst(0, new int[]{1, 2});","handlingStrategy":"validation","validationCode":"// Java\nif (of.length != ft.windowSize - 1)\n  throw new IllegalArgumentException(\"'of' must have \" + (ft.windowSize-1) + \" labels\");\ndouble lp = ft.conditionalLogProbGivenFirst(given, of);","typeGuard":null,"tryCatchPattern":"// Java\ntry {\n  lp = ft.conditionalLogProbGivenFirst(first, of);\n} catch (IllegalArgumentException e) {\n  System.err.println(\"Bad 'of' length \" + of.length + \" for window \" + ft.windowSize);\n  // rebuild `of` before retrying\n}","preventionTips":["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."],"tags":["java","nlp","crf","argument-validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}