stanfordnlp/CoreNLP · error · IllegalArgumentException

Unknown prior type:

Error message

Unknown prior type: 

What it means

getPriorType maps a string prior name (e.g. 'l2'/'gaussian', 'ae-lasso', 'sg-lasso', 'g-lasso', etc.) to the library's numeric prior constants. An unrecognized string is rejected with this IllegalArgumentException at objective-function construction time.

Solutions

  1. Use a supported prior name exactly, e.g. priorType=L2 (or gaussian / ae-lasso / sg-lasso / g-lasso as listed in getPriorType).
  2. Trim whitespace from the property value: priorType=L2 (no trailing spaces).
  3. Check the source of getPriorType in your library version for the exact accepted strings.
  4. If the intended prior is not supported, implement a custom objective function or use the closest supported prior.

Example fix

// before (train.prop)
priorType=L1
// after
priorType=L2
// (or another name accepted by getPriorType, e.g. gaussian)
Defensive patterns

Strategy: validation

Validate before calling

static final Set<String> ALLOWED = Set.of("l2","l1","gaussian","ae-lasso","sg-lasso","g-lasso");
String p = flags.priorType == null ? "" : flags.priorType.trim();
if (!ALLOWED.contains(p.toLowerCase(Locale.ROOT)))
  throw new IllegalArgumentException("Unknown prior type: " + flags.priorType);

Type guard

static boolean isValidPrior(String s) {
  return s != null && (s.equalsIgnoreCase("l2") || s.equalsIgnoreCase("l1") ||
    s.equalsIgnoreCase("gaussian") || s.equalsIgnoreCase("ae-lasso") ||
    s.equalsIgnoreCase("sg-lasso") || s.equalsIgnoreCase("g-lasso"));
}

Try / catch

try {
  func = new CRFLogConditionalObjectiveFunction(data, labels, window, classIndex, labelIndices, map, priorType, backgroundSymbol, sigma, featureVal, threads);
} catch (IllegalArgumentException e) {
  if (e.getMessage().startsWith("Unknown prior type")) {
    log.warn("Falling back to L2 prior (was: {})", priorType);
    func = new CRFLogConditionalObjectiveFunction(data, labels, window, classIndex, labelIndices, map, "L2", backgroundSymbol, sigma, featureVal, threads);
  } else throw e;
}

Prevention

When it happens

Trigger: Constructing CRFLogConditionalObjectiveFunction (or training a CRFClassifier) with a prior/regularization string that is not one of the recognized names — typos like 'L1 ' with whitespace, 'huber' misspelled, or a prior type not supported by this CRF variant.

Common situations: Training-property typo (priorType=lasso instead of the supported name), case/whitespace issues (though equalsIgnoreCase is used, stray spaces fail), copying prior names from non-CRF estimators that support a different set.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/ie/crf/CRFLogConditionalObjectiveFunction.java:119

    if ("QUADRATIC".equalsIgnoreCase(priorTypeStr)) {
      return QUADRATIC_PRIOR;
    } else if ("HUBER".equalsIgnoreCase(priorTypeStr)) {
      return HUBER_PRIOR;
    } else if ("QUARTIC".equalsIgnoreCase(priorTypeStr)) {
      return QUARTIC_PRIOR;
    } else if ("DROPOUT".equalsIgnoreCase(priorTypeStr)) {
      return DROPOUT_PRIOR;
    } else if ("NONE".equalsIgnoreCase(priorTypeStr)) {
      return NO_PRIOR;
    } else if (priorTypeStr.equalsIgnoreCase("lasso") ||
               priorTypeStr.equalsIgnoreCase("ridge") ||
               priorTypeStr.equalsIgnoreCase("gaussian") ||
               priorTypeStr.equalsIgnoreCase("ae-lasso") ||
               priorTypeStr.equalsIgnoreCase("sg-lasso") ||
               priorTypeStr.equalsIgnoreCase("g-lasso") ) {
      return NO_PRIOR;
    } else {
      throw new IllegalArgumentException("Unknown prior type: " + priorTypeStr);
    }
  }

  CRFLogConditionalObjectiveFunction(int[][][][] data, int[][] labels, int window, Index<String> classIndex, List<Index<CRFLabel>> labelIndices, int[] map, String priorType, String backgroundSymbol, double sigma, double[][][][] featureVal, int multiThreadGrad) {
    this(data, labels, window, classIndex, labelIndices, map, priorType, backgroundSymbol, sigma, featureVal, multiThreadGrad, true);
  }

  CRFLogConditionalObjectiveFunction(int[][][][] data, int[][] labels, int window, Index<String> classIndex, List<Index<CRFLabel>> labelIndices, int[] map, String priorType, String backgroundSymbol, double sigma, double[][][][] featureVal, int multiThreadGrad, boolean calcEmpirical) {
    this.window = window;
    this.classIndex = classIndex;
    this.numClasses = classIndex.size();
    this.labelIndices = labelIndices;
    this.map = map;
    this.data = data;
    this.featureVal = featureVal;
    this.labels = labels;
    this.prior = getPriorType(priorType);
    this.backgroundSymbol = backgroundSymbol;

View on GitHub (pinned to 1b7edd19c4)