stanfordnlp/CoreNLP · error · RuntimeException
Unknown inference type: " + flags.inferenceType + ". Your…
Error message
Unknown inference type: " + flags.inferenceType + ". Your options are Viterbi|Beam.
What it means
During CRF document inference, CRFClassifier selects a BestSequenceFinder from flags.inferenceType: "Viterbi" maps to ExactBestSequenceFinder and "Beam" to BeamBestSequenceFinder(flags.beamSize), both matched case-insensitively. Any other value throws this RuntimeException rather than silently defaulting, since the wrong inference algorithm would silently change labeling behavior.
Solutions
- Set inferenceType to "Viterbi" or "Beam" (case-insensitive).
- If using Beam, also set beamSize for BeamBestSequenceFinder.
- Remove the property only after confirming the flags default is a supported value.
- For Gibbs sampling use the dedicated sampler flags (useUniformPrior, annealingType), not inferenceType.
Example fix
// before
props.setProperty("inferenceType", "viterbi-search");
// after
props.setProperty("inferenceType", "Viterbi"); Defensive patterns
Strategy: validation
Validate before calling
Set<String> allowed = new HashSet<>(Arrays.asList("viterbi", "beam"));
String t = props.getProperty("inferenceType", "Viterbi");
if (!allowed.contains(t.toLowerCase(Locale.ROOT))) {
throw new IllegalArgumentException("inferenceType must be Viterbi or Beam, got: " + t);
} Try / catch
try {
classifier.train(files);
} catch (RuntimeException e) {
if (String.valueOf(e.getMessage()).contains("Unknown inference type")) {
props.setProperty("inferenceType", "Viterbi");
// rebuild classifier and retry
} else throw e;
} Prevention
- Only use the documented inferenceType values Viterbi and Beam.
- Validate the properties file against SeqModelFlags defaults before long runs.
- Spelling must be exact; case is ignored.
When it happens
Trigger: Setting the inferenceType property to anything besides Viterbi or Beam (e.g. "vit", "exact", "gibbs", "viterbi-search") on a run that goes through this CRF inference path.
Common situations: Typos; copying inference options from other NLP toolkits; confusing these flags with the Gibbs sampling options, which are configured separately.
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
- no prior specified
- No annealing type specified
- No minimizer assigned!
- after W derivative, index() != x.length()
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/aec65a7c0fafcc56.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/ie/crf/CRFClassifier.java:1185
return classifyMaxEnt(document, model);
}
private List<IN> classifyMaxEnt(List<IN> document, SequenceModel model) {
if (document.isEmpty()) {
return document;
}
if (flags.inferenceType == null) {
flags.inferenceType = "Viterbi";
}
BestSequenceFinder tagInference;
if (flags.inferenceType.equalsIgnoreCase("Viterbi")) {
tagInference = new ExactBestSequenceFinder();
} else if (flags.inferenceType.equalsIgnoreCase("Beam")) {
tagInference = new BeamBestSequenceFinder(flags.beamSize);
} else {
throw new RuntimeException("Unknown inference type: " + flags.inferenceType + ". Your options are Viterbi|Beam.");
}
int[] bestSequence = tagInference.bestSequence(model);
if (flags.useReverse) {
Collections.reverse(document);
}
for (int j = 0, docSize = document.size(); j < docSize; j++) {
IN wi = document.get(j);
String guess = classIndex.get(bestSequence[j + windowSize - 1]);
wi.set(CoreAnnotations.AnswerAnnotation.class, guess);
int index = classIndex.indexOf(guess);
double guessProb = ((TestSequenceModel) model).labelProb(j, index);
wi.set(CoreAnnotations.AnswerProbAnnotation.class, guessProb);
}
if (flags.useReverse) {
Collections.reverse(document);
}View on GitHub (pinned to 1b7edd19c4)