{"record":{"id":"036ff8924185f0f4","repo":"stanfordnlp/CoreNLP","slug":"flags-softmaxoutputlayer-true-but-neither-flag","errorCode":null,"errorMessage":"flags.softmaxOutputLayer == true, but neither flags.sparseOutputLayer or flags.tieOutputLayer is true","messagePattern":"flags\\.softmaxOutputLayer == true, but neither flags\\.sparseOutputLayer or flags\\.tieOutputLayer is true","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/ie/crf/CRFNonLinearLogConditionalObjectiveFunction.java","lineNumber":129,"sourceCode":"    this.sigma = flags.sigma;\n    this.outputLayerSize = numClasses;\n    this.numHiddenUnits = flags.numHiddenUnits;\n    if (flags.arbitraryInputLayerSize != -1)\n      this.inputLayerSize = flags.arbitraryInputLayerSize;\n    else\n      this.inputLayerSize = numHiddenUnits * numClasses;\n    this.numNodeFeatures = numNodeFeatures;\n    this.numEdgeFeatures = numEdgeFeatures;\n    log.info(\"numOfEdgeFeatures: \" + numEdgeFeatures);\n    this.useOutputLayer = flags.useOutputLayer;\n    this.useHiddenLayer = flags.useHiddenLayer;\n    this.useSigmoid = flags.useSigmoid;\n    this.docWindowLabels = new int[data.length][];\n    if (!useOutputLayer) {\n      log.info(\"Output layer not activated, inputLayerSize must be equal to numClasses, setting it to \" + numClasses);\n      this.inputLayerSize = numClasses;\n    } else if (flags.softmaxOutputLayer && !(flags.sparseOutputLayer || flags.tieOutputLayer)) {\n      throw new RuntimeException(\"flags.softmaxOutputLayer == true, but neither flags.sparseOutputLayer or flags.tieOutputLayer is true\");\n    }\n    empiricalCounts();\n  }\n\n  @Override\n  public int domainDimension() {\n    if (domainDimension < 0) {\n      domainDimension = 0;\n      edgeParamCount = numEdgeFeatures * labelIndices.get(1).size();\n\n      originalFeatureCount = 0;\n      for (int aMap : map) {\n        int s = labelIndices.get(aMap).size();\n        originalFeatureCount += s;\n      }\n\n      domainDimension += edgeParamCount;\n      domainDimension += inputLayerSize * numNodeFeatures;","sourceCodeStart":111,"sourceCodeEnd":147,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/ie/crf/CRFNonLinearLogConditionalObjectiveFunction.java#L111-L147","documentation":"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.","triggerScenarios":"Constructing CRFNonLinearLogConditionalObjectiveFunction with flags.softmaxOutputLayer == true while both flags.sparseOutputLayer and flags.tieOutputLayer are false (or unset).","commonSituations":"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.","solutions":["Set flags.sparseOutputLayer = true alongside softmaxOutputLayer = true.","Alternatively set flags.tieOutputLayer = true to satisfy the constraint.","Or disable softmaxOutputLayer if the default output layer behavior is acceptable.","Review SeqClassifierFlags documentation for the valid combinations of non-linear CRF output-layer flags."],"exampleFix":"// before\nflags.softmaxOutputLayer = true; // sparseOutputLayer and tieOutputLayer both false\n// after\nflags.softmaxOutputLayer = true;\nflags.sparseOutputLayer = true;","handlingStrategy":"validation","validationCode":"if (flags.softmaxOutputLayer && !(flags.sparseOutputLayer || flags.tieOutputLayer))\n  throw new IllegalArgumentException(\"softmaxOutputLayer requires sparseOutputLayer or tieOutputLayer\");","typeGuard":"static boolean flagsConsistent(SeqClassifierFlags f) { return !f.softmaxOutputLayer || f.sparseOutputLayer || f.tieOutputLayer; }","tryCatchPattern":"try {\n  CRFNonLinearLogConditionalObjectiveFunction f = new CRFNonLinearLogConditionalObjectiveFunction(data, labels, window, classIndex, labelIndices, map, flags);\n} catch (RuntimeException e) {\n  if (e.getMessage().contains(\"softmaxOutputLayer\")) {\n    flags.sparseOutputLayer = true; // repair and retry\n  } else throw e;\n}","preventionTips":["Whenever enabling softmaxOutputLayer, also set sparseOutputLayer or tieOutputLayer in the same config.","Keep a single shared flags-setup helper so combinations stay consistent.","Validate flag combinations in a unit test before launching long training runs.","Document which output-layer mode your experiments use."],"tags":["crf","flags","config-conflict","nonlinear"],"backgroundTag":"conflicting-config-options","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"}