{"record":{"id":"f7dfb9b91bf58932","repo":"stanfordnlp/CoreNLP","slug":"after-param-initialization-param-index-not-eq","errorCode":null,"errorMessage":"after param initialization, param Index ( ) not equal to domainDimension ( )","messagePattern":"after param initialization, param Index \\( \\) not equal to domainDimension \\( \\)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/ie/crf/CRFNonLinearLogConditionalObjectiveFunction.java","lineNumber":249,"sourceCode":"            val = 1.0 / numHiddenUnits;\n          else {\n            val = random.nextDouble() * total;\n            total -= val;\n          }\n          initial[count++] = val;\n        }\n        if (flags.hardcodeSoftmaxOutputWeights)\n          initial[count++] = 1.0 / numHiddenUnits;\n        else\n          initial[count++] = total;\n      } else {\n        for (int i = beforeOutputWeights; i < domainDimension(); i++) {\n          val = random.nextDouble() * twoEpsilon - epsilon;\n          initial[count++] = val;\n        }\n      }\n      if (count != domainDimension()) {\n        throw new RuntimeException(\"after param initialization, param Index (\" + count + \") not equal to domainDimension (\" + domainDimension() + \")\");\n      }\n    }\n    return initial;\n  }\n\n  private void empiricalCounts() {\n    Ehat = empty2D();\n\n    for (int m = 0; m < data.length; m++) {\n      int[][][] docData = data[m];\n      int[] docLabels = labels[m];\n      int[] windowLabels = new int[window];\n      Arrays.fill(windowLabels, classIndex.indexOf(backgroundSymbol));\n\n      if (docLabels.length>docData.length) { // only true for self-training\n        // fill the windowLabel array with the extra docLabels\n        System.arraycopy(docLabels, 0, windowLabels, 0, windowLabels.length);\n        // shift the docLabels array left","sourceCodeStart":231,"sourceCodeEnd":267,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/ie/crf/CRFNonLinearLogConditionalObjectiveFunction.java#L231-L267","documentation":"At the end of initial(), after all parameter blocks (edge params, node params, output weights) are randomly initialized, the method asserts that the total number of entries written equals domainDimension(). A mismatch means the computed parameter layout disagrees with domainDimension(), so this RuntimeException is thrown with both numbers to expose the inconsistency.","triggerScenarios":"Calling initial() when the incremental count in the initialization loops does not sum to domainDimension() — caused by inconsistent flag/dimension combinations (inputLayerSize, numClasses, output layer modes) or a bug in one of the initialization branches.","commonSituations":"Non-linear CRF training with unusual layer-size configurations where one init branch was skipped; stale/custom builds where domainDimension() was changed without updating the initialization loops.","solutions":["Compare the two numbers in the message to see how many parameters are missing or extra, then identify which init branch did not run.","Use a standard, tested flag combination for the non-linear CRF (defaults for useOutputLayer, inputLayerSize).","Ensure domainDimension() and the initialization loops are derived from the same constants (edgeParamCount, beforeOutputWeights).","Rebuild against unmodified library sources to rule out local patches causing the mismatch.","If reproducible with stock flags, file a bug with the full flag set to Stanford NLP."],"exampleFix":"// before\nflags.useOutputLayer = true;\nflags.inputLayerSize = 0; // inconsistent with domainDimension()\n// after\nflags.useOutputLayer = true;\nflags.inputLayerSize = numClasses; // consistent layer sizing","handlingStrategy":"validation","validationCode":"double[] x = null;\n// pre-check dimension consistency before training\ncrf.calculate(new double[crf.domainDimension()], batch, new double[crf.domainDimension()] == null ? null : null); // or simply verify domainDimension() matches expected param count for your flags","typeGuard":"static boolean paramVectorFits(double[] x, CRFNonLinearLogConditionalObjectiveFunction crf) { return x != null && x.length == crf.domainDimension(); }","tryCatchPattern":"try {\n  double[] x = crf.initial();\n} catch (RuntimeException e) {\n  if (e.getMessage().contains(\"not equal to domainDimension\")) {\n    log.error(\"param layout mismatch: \" + e.getMessage() + \" — reset flags to defaults\");\n  } else throw e;\n}","preventionTips":["Verify that domainDimension() matches your expected parameter count for your flag combination before training.","Use default layer sizes unless you have verified the init layout handles them.","Rebuild from unmodified sources if you patched the objective function.","Add a fast smoke test: call initial() and assert length == domainDimension()."],"tags":["crf","initialization","invariant","dimension-mismatch"],"backgroundTag":"internal-invariant-violation","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"}