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

  1. Set inferenceType to "Viterbi" or "Beam" (case-insensitive).
  2. If using Beam, also set beamSize for BeamBestSequenceFinder.
  3. Remove the property only after confirming the flags default is a supported value.
  4. 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

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


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)