stanfordnlp/CoreNLP · error · RuntimeException
after blockInitialize, param Index ( ) not equal to…
Error message
after blockInitialize, param Index ( ) not equal to beforeOutputWeights ( )
What it means
During initial() parameter initialization, the blockInitialize path fills the first beforeOutputWeights parameters; the count afterwards must exactly equal beforeOutputWeights. A mismatch means the block initialization loops wrote a different number of values than the output-layer offset, desynchronizing the initialization vector layout.
Solutions
- Verify the flags (sparseOutputLayer, tieOutputLayer, softmaxOutputLayer) match the weight-array shapes implied by inputLayerSize and numClasses.
- Check blockInitialize loops iterate the full U matrix so exactly beforeOutputWeights values are written.
- Keep constructor arguments consistent with the training data's label indices and feature map.
- Fall back to the non-block branch (flags disabling block init) to see if dimensions line up without custom initialization.
Example fix
// before (block loop truncated by an early break) for (int i = 0; i < U.length - 1; i++) initial[count++] = ...; // after for (int i = 0; i < U.length; i++) initial[count++] = ...;
Defensive patterns
Strategy: validation
Validate before calling
// after building the objective function
if (fn.domainDimension() <= 0)
throw new IllegalStateException("degenerate parameter space; check dimension arguments"); Try / catch
try {
minimizer.minimize(fn, tol, fn.initial());
} catch (RuntimeException e) {
if (e.getMessage().contains("not equal to beforeOutputWeights")) {
// retry with default (non-block) initialization flags
} else throw e;
} Prevention
- Avoid patching blockInitialize without updating its count assertion targets
- Keep sparse/tied layer flags consistent across construction and initialization
- Unit-test initialization length on small synthetic data
When it happens
Trigger: initial() invoked (first call by the optimizer, e.g. QNMinimizer) with sparseOutputLayer / tieOutputLayer / softmaxOutputLayer block initialization active while array dimensions (inputLayerSize, numClasses, eU shapes) do not match the beforeOutputWeights computation.
Common situations: Custom hidden-layer sizes or modified blockInitialize code during non-linear second-order CRF experiments; inconsistent constructor arguments (numNodeFeatures, numEdgeFeatures, window).
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
- after blockInitialize, param Index ( ) not equal to…
- after param initialization, param Index ( ) not equal to…
- after edge derivative, index() != edgeParamCount()
- after W derivative, index() != beforeOutputWeights()
- after W derivative, index() != x.length()
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/a94208359a8e2155.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/ie/crf/CRFNonLinearSecondOrderLogConditionalObjectiveFunction.java:202
int interval = numNodeFeatures / numHiddenUnits;
for (int i = 0; i < numHiddenUnits; i++) {
int lower = i * interval;
int upper = (i + 1) * interval;
if (i == numHiddenUnits - 1)
upper = numNodeFeatures;
for (int j = 0; j < outputLayerSize; j++) {
for (int k = 0; k < numNodeFeatures; k++) {
val = 0;
if (k >= lower && k < upper) {
val = random.nextDouble() * twoEpsilon - epsilon;
}
initial[count++] = val;
}
}
}
if (count != beforeOutputWeights) {
throw new RuntimeException("after blockInitialize, param Index (" + count + ") not equal to beforeOutputWeights (" + beforeOutputWeights + ")");
}
} else {
for (int i = 0; i < beforeOutputWeights; i++) {
val = random.nextDouble() * twoEpsilon - epsilon;
initial[count++] = val;
}
}
if (flags.sparseOutputLayer) {
for (int i = 0; i < outputLayerSize4Edge; i++) {
double total = 1;
for (int j = 0; j < numHiddenUnits-1; j++) {
val = random.nextDouble() * total;
initial[count++] = val;
total -= val;
}
initial[count++] = total;
}View on GitHub (pinned to 1b7edd19c4)