stanfordnlp/CoreNLP · error · RuntimeException

Error running testGibbs inference!

Error message

Error running testGibbs inference!

What it means

classify() supports Gibbs-sampling inference when flags.doGibbs is true; any exception thrown by classifyGibbs (e.g. from the transducer model, factor graphs, or class factory configuration) is wrapped in a RuntimeException with this message and the original cause attached.

Solutions

  1. Inspect the cause chain (e.getCause()) — the real failure is inside classifyGibbs; fix that underlying error.
  2. If Gibbs inference is not required, set flags.doGibbs=false to use the default maxent/Viterbi path.
  3. Verify flags.sequenceModelClass (and related factory classes) name existing, loadable classes compatible with your CoreNLP version.

Example fix

// before
props.setProperty("doGibbs", "true"); // missing sequenceModelClass
// after
props.setProperty("doGibbs", "true");
props.setProperty("sequenceModelClass", "edu.stanford.nlp.sequences.FactoredSequenceModel");
Defensive patterns

Strategy: try-catch

Validate before calling

if (flags.doGibbs) {
  Class.forName(flags.sequenceModelClass, true, getClass().getClassLoader());
}

Try / catch

try {
  return classifier.classify(document);
} catch (RuntimeException e) {
  if (e.getMessage() != null && e.getMessage().contains("testGibbs")) {
    e.getCause().printStackTrace(); // real failure inside classifyGibbs
    return classifier.classifyMaxEnt(document); // fallback
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling classify(document) with flags.doGibbs=true when classifyGibbs throws — commonly a ClassCastException/InstantiationException creating the SeqClassifierFlags.sequenceModelClass or documentWriterClass, or a bad factorFactory.

Common situations: Setting doGibbs in properties without specifying a valid sequenceModelClass; class names that don't exist on the classpath; incompatible custom sequence model implementations after a CoreNLP upgrade.

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/ie/crf/CRFClassifier.java:1065

  @Override
  public void dumpFeatures(Collection<List<IN>> docs) {
    if (flags.exportFeatures != null) {
      Timing timer = new Timing();
      CRFFeatureExporter<IN> featureExporter = new CRFFeatureExporter<>(this);
      featureExporter.printFeatures(flags.exportFeatures, docs);
      long elapsedMs = timer.stop();
      log.info("Time to export features: " + Timing.toSecondsString(elapsedMs) + " seconds");
    }
  }

  @Override
  public List<IN> classify(List<IN> document) {
    if (flags.doGibbs) {
      try {
        return classifyGibbs(document);
      } catch (Exception e) {
        throw new RuntimeException("Error running testGibbs inference!", e);
      }
    } else if (flags.crfType.equalsIgnoreCase("maxent")) {
      return classifyMaxEnt(document);
    } else {
      throw new RuntimeException("Unsupported inference type: " + flags.crfType);
    }
  }

  private List<IN> classify(List<IN> document, Triple<int[][][], int[], double[][][]> documentDataAndLabels) {
    if (flags.doGibbs) {
      try {
        return classifyGibbs(document, documentDataAndLabels);
      } catch (Exception e) {
        throw new RuntimeException("Error running testGibbs inference!", e);
      }
    } else if (flags.crfType.equalsIgnoreCase("maxent")) {
      return classifyMaxEnt(document, documentDataAndLabels);
    } else {

View on GitHub (pinned to 1b7edd19c4)