stanfordnlp/CoreNLP · error · RuntimeIOException

Error while loading a tagger model (probably missing model f

Error message

Error while loading a tagger model (probably missing model file)

What it means

MaxentTagger wraps any IOException raised while opening the tagger model file/URL into a RuntimeIOException with this message. It is thrown from readModelAndInit(Properties, String, boolean) when IOUtils.getInputStreamFromURLOrClasspathOrFileSystem fails, meaning the model path/URL could not be opened or read. Stanford POS Tagger models are not bundled by default in many distributions, so this typically means the model file is absent or the path is wrong.

Solutions

  1. Verify the model file exists at the exact path and is readable (ls -l / Files.exists).
  2. Use an absolute path or a URL: new MaxentTagger("models/english-left3words-distsim.tagger") with the working directory checked.
  3. If using a classpath resource, confirm the model is inside a jar on the classpath and reference it correctly.
  4. Re-download matching models for your Stanford POS Tagger/Stanford CoreNLP version.
  5. If only the message matters, unwrap getCause() to see the real IOException.

Example fix

// before
MaxentTagger tagger = new MaxentTagger("english-left3words.tagger");
// after
String model = "/opt/models/english-left3words-distsim.tagger";
if (!new File(model).exists()) throw new IllegalStateException("Tagger model missing: " + model);
MaxentTagger tagger = new MaxentTagger(model);
Defensive patterns

Strategy: try-catch

Validate before calling

java.io.File model = new java.io.File(modelPath);
if (!model.isFile() || !model.canRead()) throw new IllegalStateException("Tagger model not readable: " + modelPath);

Type guard

boolean modelReadable(String p) { java.io.File f = new java.io.File(p); return f.isFile() && f.canRead(); }

Try / catch

try {
  MaxentTagger tagger = new MaxentTagger(modelPath);
} catch (RuntimeIOException e) {
  log.error("Tagger model load failed: {}", e.getCause());
  throw new ConfigurationException("Check model path/version: " + modelPath, e);
}

Prevention

When it happens

Trigger: Calling new MaxentTagger(modelPath) or MaxentTagger.readModelAndInit(config, modelFileOrUrl, printLoading) where modelFileOrUrl points to a missing, unreadable, or corrupt file, a bad classpath resource, or an unreachable URL; the stream open/read throws IOException.

Common situations: Wrong -model / modelPath config (typo, relative path resolved against wrong working dir); forgot to download english-left3words-distsim.tagger; model jar not on classpath; model path points to a properties file instead of the serialized model; model from an incompatible library version.

Understand the failure class

Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/tagger/maxent/MaxentTagger.java:799

   *  or as a resource in a jar file, and initializes the tagger using a
   *  combination of the properties passed in and parameters from the file.
   *  <br>
   *  <i>Note for the future:</i> This assumes that the TaggerConfig in the file
   *  has already been read and used.  This work is done inside the
   *  constructor of TaggerConfig.  It might be better to refactor
   *  things so that is all done inside this method, but for the moment
   *  it seemed better to leave working code alone [cdm 2008].
   *
   *  @param config The tagger config
   *  @param modelFileOrUrl The name of the model file. This routine opens and closes it.
   *  @param printLoading Whether to print a message saying what model file is being loaded and how long it took when finished.
   *  @throws RuntimeIOException if I/O errors or serialization errors
   */
  protected void readModelAndInit(Properties config, String modelFileOrUrl, boolean printLoading) {
    try (InputStream is = IOUtils.getInputStreamFromURLOrClasspathOrFileSystem(modelFileOrUrl)) {
      readModelAndInit(config, is, printLoading);
    } catch (IOException e) {
      throw new RuntimeIOException("Error while loading a tagger model (probably missing model file)", e);
    }
  }

  /** This reads the complete tagger from a single model provided as an InputStream,
   *  and initializes the tagger using a
   *  combination of the properties passed in and parameters from the file.
   *  <br>
   *  <i>Note for the future:</i> This assumes that the TaggerConfig in the file
   *  has already been read and used.  This work is done inside the
   *  constructor of TaggerConfig.  It might be better to refactor
   *  things so that is all done inside this method, but for the moment
   *  it seemed better to leave working code alone [cdm 2008].
   *
   *  @param config The tagger config
   *  @param modelStream The model provided as an InputStream
   *  @param printLoading Whether to print a message saying what model file is being loaded and how long it took when finished.
   *  @throws RuntimeIOException if I/O errors or serialization errors
   */

View on GitHub (pinned to 1b7edd19c4)