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(), 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.

Solutions

  1. Compare the two numbers in the message to see how many parameters are missing or extra, then identify which init branch did not run.
  2. Use a standard, tested flag combination for the non-linear CRF (defaults for useOutputLayer, inputLayerSize).
  3. Ensure domainDimension() and the initialization loops are derived from the same constants (edgeParamCount, beforeOutputWeights).
  4. Rebuild against unmodified library sources to rule out local patches causing the mismatch.
  5. If reproducible with stock flags, file a bug with the full flag set to Stanford NLP.

Example fix

// before
flags.useOutputLayer = true;
flags.inputLayerSize = 0; // inconsistent with domainDimension()
// after
flags.useOutputLayer = true;
flags.inputLayerSize = numClasses; // consistent layer sizing
Defensive patterns

Strategy: validation

Validate before calling

double[] x = null;
// pre-check dimension consistency before training
crf.calculate(new double[crf.domainDimension()], batch, new double[crf.domainDimension()] == null ? null : null); // or simply verify domainDimension() matches expected param count for your flags

Type guard

static boolean paramVectorFits(double[] x, CRFNonLinearLogConditionalObjectiveFunction crf) { return x != null && x.length == crf.domainDimension(); }

Try / catch

try {
  double[] x = crf.initial();
} catch (RuntimeException e) {
  if (e.getMessage().contains("not equal to domainDimension")) {
    log.error("param layout mismatch: " + e.getMessage() + " — reset flags to defaults");
  } else throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

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/f7dfb9b91bf58932. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/ie/crf/CRFNonLinearLogConditionalObjectiveFunction.java:249

            val = 1.0 / numHiddenUnits;
          else {
            val = random.nextDouble() * total;
            total -= val;
          }
          initial[count++] = val;
        }
        if (flags.hardcodeSoftmaxOutputWeights)
          initial[count++] = 1.0 / numHiddenUnits;
        else
          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 void empiricalCounts() {
    Ehat = empty2D();

    for (int m = 0; m < data.length; m++) {
      int[][][] docData = data[m];
      int[] docLabels = labels[m];
      int[] windowLabels = new int[window];
      Arrays.fill(windowLabels, classIndex.indexOf(backgroundSymbol));

      if (docLabels.length>docData.length) { // only true for self-training
        // fill the windowLabel array with the extra docLabels
        System.arraycopy(docLabels, 0, windowLabels, 0, windowLabels.length);
        // shift the docLabels array left

View on GitHub (pinned to 1b7edd19c4)