stanfordnlp/CoreNLP · error · RuntimeException

flags.softmaxOutputLayer == true, but neither…

Error message

flags.softmaxOutputLayer == true, but neither flags.sparseOutputLayer or flags.tieOutputLayer is true

What it means

The non-linear CRF constructor validates the combination of SeqClassifierFlags: if softmaxOutputLayer is enabled, the output layer must be either sparse or tied; otherwise the softmax over the full input layer is undefined. The constructor throws a RuntimeException to reject this contradictory flag combination at setup time.

Solutions

  1. Set flags.sparseOutputLayer = true alongside softmaxOutputLayer = true.
  2. Alternatively set flags.tieOutputLayer = true to satisfy the constraint.
  3. Or disable softmaxOutputLayer if the default output layer behavior is acceptable.
  4. Review SeqClassifierFlags documentation for the valid combinations of non-linear CRF output-layer flags.

Example fix

// before
flags.softmaxOutputLayer = true; // sparseOutputLayer and tieOutputLayer both false
// after
flags.softmaxOutputLayer = true;
flags.sparseOutputLayer = true;
Defensive patterns

Strategy: validation

Validate before calling

if (flags.softmaxOutputLayer && !(flags.sparseOutputLayer || flags.tieOutputLayer))
  throw new IllegalArgumentException("softmaxOutputLayer requires sparseOutputLayer or tieOutputLayer");

Type guard

static boolean flagsConsistent(SeqClassifierFlags f) { return !f.softmaxOutputLayer || f.sparseOutputLayer || f.tieOutputLayer; }

Try / catch

try {
  CRFNonLinearLogConditionalObjectiveFunction f = new CRFNonLinearLogConditionalObjectiveFunction(data, labels, window, classIndex, labelIndices, map, flags);
} catch (RuntimeException e) {
  if (e.getMessage().contains("softmaxOutputLayer")) {
    flags.sparseOutputLayer = true; // repair and retry
  } else throw e;
}

Prevention

When it happens

Trigger: Constructing CRFNonLinearLogConditionalObjectiveFunction with flags.softmaxOutputLayer == true while both flags.sparseOutputLayer and flags.tieOutputLayer are false (or unset).

Common situations: Experimenting with non-linear CRF training options and enabling softmax output without also enabling one of the required layer modes; copying flag sets from tutorials that omit the companion flag.

Understand the failure class

Background: Conflicting config options: "cannot be used together" — configuration validation errors across open-source libraries — this error's family across 162 libraries.

Related errors


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

Appendix: source

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

    this.sigma = flags.sigma;
    this.outputLayerSize = numClasses;
    this.numHiddenUnits = flags.numHiddenUnits;
    if (flags.arbitraryInputLayerSize != -1)
      this.inputLayerSize = flags.arbitraryInputLayerSize;
    else
      this.inputLayerSize = numHiddenUnits * numClasses;
    this.numNodeFeatures = numNodeFeatures;
    this.numEdgeFeatures = numEdgeFeatures;
    log.info("numOfEdgeFeatures: " + numEdgeFeatures);
    this.useOutputLayer = flags.useOutputLayer;
    this.useHiddenLayer = flags.useHiddenLayer;
    this.useSigmoid = flags.useSigmoid;
    this.docWindowLabels = new int[data.length][];
    if (!useOutputLayer) {
      log.info("Output layer not activated, inputLayerSize must be equal to numClasses, setting it to " + numClasses);
      this.inputLayerSize = numClasses;
    } else if (flags.softmaxOutputLayer && !(flags.sparseOutputLayer || flags.tieOutputLayer)) {
      throw new RuntimeException("flags.softmaxOutputLayer == true, but neither flags.sparseOutputLayer or flags.tieOutputLayer is true");
    }
    empiricalCounts();
  }

  @Override
  public int domainDimension() {
    if (domainDimension < 0) {
      domainDimension = 0;
      edgeParamCount = numEdgeFeatures * labelIndices.get(1).size();

      originalFeatureCount = 0;
      for (int aMap : map) {
        int s = labelIndices.get(aMap).size();
        originalFeatureCount += s;
      }

      domainDimension += edgeParamCount;
      domainDimension += inputLayerSize * numNodeFeatures;

View on GitHub (pinned to 1b7edd19c4)