{"record":{"id":"07bc866f5ba36d8c","repo":"stanfordnlp/CoreNLP","slug":"unnormalizedconditionallogprobgivenfirst-requires","errorCode":null,"errorMessage":"unnormalizedConditionalLogProbGivenFirst requires of one less than clique size ( ) but was ","messagePattern":"unnormalizedConditionalLogProbGivenFirst 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":335,"sourceCode":"\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.\n   *\n   * @return the probability of the sequence of being at the end of the table\n   */\n  public double unnormalizedConditionalLogProbGivenFirst(int given, int[] of) {\n    if (of.length != windowSize - 1) {\n      throw new IllegalArgumentException(\"unnormalizedConditionalLogProbGivenFirst 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    return probAll;\n  }\n\n  /**\n   * Computes the probability of the tag OF being at the beginning of the table\n   * given that the tag sequence GIVEN is at the end of the table. given is at","sourceCodeStart":317,"sourceCodeEnd":353,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/ie/crf/FactorTable.java#L317-L353","documentation":"unnormalizedConditionalLogProbGivenFirst is like conditionalLogProbGivenFirst but skips normalization by the full-table log probability. It imposes the same constraint: `of` must have exactly windowSize-1 labels, because together with the `given` first label it must fill the entire windowSize clique before the table can be indexed.","triggerScenarios":"Calling unnormalizedConditionalLogProbGivenFirst(int given, int[] of) with of.length != windowSize-1; per the call graph this is reachable from scoresOf and the class main method, so custom scoring code that builds `of` manually is the usual path.","commonSituations":"Custom scorer/rescorer code that builds label windows with the wrong order; switching between FactorTable instances of different window sizes while reusing the same query arrays; test fixtures written against a different clique size.","solutions":["Construct `of` as exactly windowSize-1 label ids derived from the FactorTable's windowSize.","When reusing query arrays across tables, rebuild them per table instead of sharing.","Prefer higher-level scoring APIs (e.g. the CRF's scoresOf) that build windows internally."],"exampleFix":"// before\nint[] of = new int[]{5}; // assumes order-1\nft.unnormalizedConditionalLogProbGivenFirst(2, of);\n\n// after\nint[] of = new int[ft.windowSize - 1];\nof[0] = 3; of[1] = 5; // fill windowSize-1 labels\nft.unnormalizedConditionalLogProbGivenFirst(2, of);","handlingStrategy":"validation","validationCode":"// Java\nint[] of = new int[ft.windowSize - 1]; // correct size by construction\n// ... fill of ...\nif (of.length != ft.windowSize - 1) throw new AssertionError();\ndouble lp = ft.unnormalizedConditionalLogProbGivenFirst(given, of);","typeGuard":null,"tryCatchPattern":"// Java\ntry {\n  lp = ft.unnormalizedConditionalLogProbGivenFirst(given, of);\n} catch (IllegalArgumentException e) {\n  // resize `of` to windowSize-1 and recompute\n  of = Arrays.copyOf(of, ft.windowSize - 1);\n  lp = ft.unnormalizedConditionalLogProbGivenFirst(given, of);\n}","preventionTips":["Allocate query arrays as new int[ft.windowSize - 1] so the size is correct by construction.","Prefer the CRF's scoresOf over manual FactorTable arithmetic when possible.","Don't share window arrays between FactorTables of different window sizes."],"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"}