stanfordnlp/CoreNLP · error · IllegalArgumentException
Unknown prior type:
Error message
Unknown prior type:
What it means
CRFNonLinearLogConditionalObjectiveFunction.getPriorType converts a prior-name string (from flags.priorType) into the internal integer constant. If the string matches none of the recognized names (L1/L2, lasso, ridge, ae-lasso, g-lasso, sg-lasso, NONE, etc.), it throws an IllegalArgumentException naming the unrecognized value. It fails fast so an unsupported regularizer is never silently ignored.
Solutions
- Set flags.priorType to one of the supported strings exactly as listed in the source (e.g. "L2", "L1", "lasso", "ridge", "ae-lasso", "g-lasso", "sg-lasso", "NONE").
- Check for typos or stray whitespace in the properties file value (e.g. "l2 " with a trailing space).
- Consult SeqClassifierFlags javadoc for the exact prior names supported by your library version.
- If a prior you need is unsupported, implement a custom prior or fall back to L2 regularization.
Example fix
// before
properties.setProperty("priorType", "elastic-net");
// after
properties.setProperty("priorType", "L2"); Defensive patterns
Strategy: validation
Validate before calling
java.util.Set<String> ok = new java.util.HashSet<>(java.util.Arrays.asList("l1","l2","gaussianPrior","laplacianPrior","quadraticPrior","lasso","ridge","ae-lasso","g-lasso","sg-lasso","none"));
if (!ok.contains(flags.priorType.toLowerCase().trim())) throw new IllegalArgumentException("unknown priorType: " + flags.priorType); Type guard
static boolean isValidPriorType(String s) { return s != null && java.util.Arrays.stream(new String[]{"l1","l2","gaussianprior","laplacianprior","quadraticprior","lasso","ridge","ae-lasso","g-lasso","sg-lasso","none"}).anyMatch(s.trim().toLowerCase()::equals); } Try / catch
try {
CRFNonLinearLogConditionalObjectiveFunction f = new CRFNonLinearLogConditionalObjectiveFunction(data, labels, window, classIndex, labelIndices, map, flags);
} catch (IllegalArgumentException e) {
if (e.getMessage().startsWith("Unknown prior type")) {
log.error("Fix flags.priorType; got: " + e.getMessage());
flags.priorType = "L2";
} else throw e;
} Prevention
- Copy prior names exactly from the SeqClassifierFlags documentation for your version.
- Trim and normalize prior strings read from properties files.
- Add a startup validation of all flag values before constructing the objective.
- Watch for prior-name changes when upgrading Stanford NLP versions.
When it happens
Trigger: Constructing the non-linear CRF objective (directly or via SeqClassifierFlags.priorType) with a priorTypeStr that is misspelled, wrong-cased beyond equalsIgnoreCase support, or entirely unsupported (e.g. "elastic-net" or a typo like "l2regularization").
Common situations: Hand-editing a training properties file and typo-ing the prior name; copying a prior value from another library (e.g. sklearn "l1") that Stanford NLP does not recognize; upgrading/downgrading versions where a prior name was removed.
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
- Unsupported inference type: " + flags.crfType
- Unknown inference type: " + flags.inferenceType + ". Your op
- no prior specified
- No annealing type specified
- No minimizer assigned!
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/7df75fb0f2a17f42.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/ie/crf/CRFNonLinearLogConditionalObjectiveFunction.java:95
{
if (priorTypeStr == null) return QUADRATIC_PRIOR; // default
if ("QUADRATIC".equalsIgnoreCase(priorTypeStr)) {
return QUADRATIC_PRIOR;
} else if ("L1".equalsIgnoreCase(priorTypeStr)) {
return L1_PRIOR;
} else if ("HUBER".equalsIgnoreCase(priorTypeStr)) {
return HUBER_PRIOR;
} else if ("QUARTIC".equalsIgnoreCase(priorTypeStr)) {
return QUARTIC_PRIOR;
} else if (priorTypeStr.equalsIgnoreCase("lasso") ||
priorTypeStr.equalsIgnoreCase("ridge") ||
priorTypeStr.equalsIgnoreCase("ae-lasso") ||
priorTypeStr.equalsIgnoreCase("g-lasso") ||
priorTypeStr.equalsIgnoreCase("sg-lasso") ||
priorTypeStr.equalsIgnoreCase("NONE") ) {
return NO_PRIOR;
} else {
throw new IllegalArgumentException("Unknown prior type: " + priorTypeStr);
}
}
CRFNonLinearLogConditionalObjectiveFunction(int[][][][] data, int[][] labels, int window, Index<String> classIndex, List<Index<CRFLabel>> labelIndices, int[] map, SeqClassifierFlags flags, int numNodeFeatures, int numEdgeFeatures, double[][][][] featureVal) {
this.window = window;
this.classIndex = classIndex;
this.numClasses = classIndex.size();
this.labelIndices = labelIndices;
this.data = data;
this.featureVal = featureVal;
this.flags = flags;
this.map = map;
this.labels = labels;
this.prior = getPriorType(flags.priorType);
this.backgroundSymbol = flags.backgroundSymbol;
this.sigma = flags.sigma;
this.outputLayerSize = numClasses;
this.numHiddenUnits = flags.numHiddenUnits;View on GitHub (pinned to 1b7edd19c4)