stanfordnlp/CoreNLP · error · RuntimeException

after param initialization, param Index ( ) not equal to…

Error message

after param initialization, param Index ( ) not equal to domainDimension ( )

What it means

At the end of initial(), the total number of initialized parameters (count) must equal domainDimension(). A mismatch means the initialization routine produced an initial vector of the wrong length relative to the function's declared parameter-space size, so the optimizer would receive an incompatible starting point.

Solutions

  1. Ensure every branch of initial() fills exactly domainDimension() entries (compare count increments with domainDimension()).
  2. Keep useOutputLayer and related flags consistent between construction and initialization expectations.
  3. Log count, beforeOutputWeights, and domainDimension() to find which block under-/over-filled.
  4. Use an unmodified CoreNLP build to rule out local edits.

Example fix

// before (tail loop skipped when useOutputLayer true)
if (!useOutputLayer) { for (int i = beforeOutputWeights; i < domainDimension(); i++) initial[count++] = ...; }
// after
for (int i = count; i < domainDimension(); i++) initial[count++] = random.nextDouble() * twoEpsilon - epsilon;
Defensive patterns

Strategy: validation

Validate before calling

// after obtaining initial weights
double[] x0 = fn.initial();
if (x0.length != fn.domainDimension())
  throw new IllegalStateException("initial length " + x0.length + " != domainDimension " + fn.domainDimension());

Try / catch

try {
  minimizer.minimize(fn, tol, fn.initial());
} catch (RuntimeException e) {
  if (e.getMessage().contains("not equal to domainDimension")) {
    // fall back to a freshly constructed function with default flags
  } else throw e;
}

Prevention

When it happens

Trigger: initial() called when the sum of the initialized blocks (edge params, W, optional U/U4Edge, remaining random weights) differs from domainDimension() -- typically after constructor flags or dimensions changed without updating the corresponding loops.

Common situations: Experimenting with useOutputLayer on/off or sparseOutputLayer in the second-order non-linear CRF; patched initialization code; training NER models with modified hidden-layer or edge-feature dimensions.

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


AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10). Data as JSON: /api/errors/cfdcdbee2050ae28. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/ie/crf/CRFNonLinearSecondOrderLogConditionalObjectiveFunction.java:254

          total -= val;
        }
        initial[count++] = total;
        total = 1;
        sum = 0;
        for (int j = 0; j < numHiddenUnits-1; j++) {
          val = random.nextDouble() * total;
          initial[count++] = val;
          total -= val;
        }
        initial[count++] = total;
      } else {
        for (int i = beforeOutputWeights; i < domainDimension(); i++) {
          val = random.nextDouble() * twoEpsilon - epsilon;
          initial[count++] = val;
        }
      }
      if (count != domainDimension()) {
        throw new RuntimeException("after param initialization, param Index (" + count + ") not equal to domainDimension (" + domainDimension() + ")");
      }
    }
    return initial;
  }

  private double[][] emptyU4Edge() {
    int innerSize = inputLayerSize4Edge;
    if (flags.sparseOutputLayer || flags.tieOutputLayer) {
      innerSize = numHiddenUnits;
    }
    int outerSize = outputLayerSize4Edge;
    if (flags.tieOutputLayer) {
      outerSize = 1;
    }

    double[][] temp = new double[outerSize][innerSize];
    for (int i = 0; i < outerSize; i++) {
      temp[i] = new double[innerSize];

View on GitHub (pinned to 1b7edd19c4)