{"record":{"id":"a9847ef1fdf9235d","repo":"stanfordnlp/CoreNLP","slug":"error-while-loading-a-tagger-model-probably-missi","errorCode":null,"errorMessage":"Error while loading a tagger model (probably missing model file)","messagePattern":"Error while loading a tagger model \\(probably missing model file\\)","errorType":"exception","errorClass":"RuntimeIOException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/tagger/maxent/MaxentTagger.java","lineNumber":799,"sourceCode":"   *  or as a resource in a jar file, and initializes the tagger using a\n   *  combination of the properties passed in and parameters from the file.\n   *  <br>\n   *  <i>Note for the future:</i> This assumes that the TaggerConfig in the file\n   *  has already been read and used.  This work is done inside the\n   *  constructor of TaggerConfig.  It might be better to refactor\n   *  things so that is all done inside this method, but for the moment\n   *  it seemed better to leave working code alone [cdm 2008].\n   *\n   *  @param config The tagger config\n   *  @param modelFileOrUrl The name of the model file. This routine opens and closes it.\n   *  @param printLoading Whether to print a message saying what model file is being loaded and how long it took when finished.\n   *  @throws RuntimeIOException if I/O errors or serialization errors\n   */\n  protected void readModelAndInit(Properties config, String modelFileOrUrl, boolean printLoading) {\n    try (InputStream is = IOUtils.getInputStreamFromURLOrClasspathOrFileSystem(modelFileOrUrl)) {\n      readModelAndInit(config, is, printLoading);\n    } catch (IOException e) {\n      throw new RuntimeIOException(\"Error while loading a tagger model (probably missing model file)\", e);\n    }\n  }\n\n  /** This reads the complete tagger from a single model provided as an InputStream,\n   *  and initializes the tagger using a\n   *  combination of the properties passed in and parameters from the file.\n   *  <br>\n   *  <i>Note for the future:</i> This assumes that the TaggerConfig in the file\n   *  has already been read and used.  This work is done inside the\n   *  constructor of TaggerConfig.  It might be better to refactor\n   *  things so that is all done inside this method, but for the moment\n   *  it seemed better to leave working code alone [cdm 2008].\n   *\n   *  @param config The tagger config\n   *  @param modelStream The model provided as an InputStream\n   *  @param printLoading Whether to print a message saying what model file is being loaded and how long it took when finished.\n   *  @throws RuntimeIOException if I/O errors or serialization errors\n   */","sourceCodeStart":781,"sourceCodeEnd":817,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/tagger/maxent/MaxentTagger.java#L781-L817","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Verify the model file exists at the exact path and is readable (ls -l / Files.exists).","Use an absolute path or a URL: new MaxentTagger(\"models/english-left3words-distsim.tagger\") with the working directory checked.","If using a classpath resource, confirm the model is inside a jar on the classpath and reference it correctly.","Re-download matching models for your Stanford POS Tagger/Stanford CoreNLP version.","If only the message matters, unwrap getCause() to see the real IOException."],"exampleFix":"// before\nMaxentTagger tagger = new MaxentTagger(\"english-left3words.tagger\");\n// after\nString model = \"/opt/models/english-left3words-distsim.tagger\";\nif (!new File(model).exists()) throw new IllegalStateException(\"Tagger model missing: \" + model);\nMaxentTagger tagger = new MaxentTagger(model);","handlingStrategy":"try-catch","validationCode":"java.io.File model = new java.io.File(modelPath);\nif (!model.isFile() || !model.canRead()) throw new IllegalStateException(\"Tagger model not readable: \" + modelPath);","typeGuard":"boolean modelReadable(String p) { java.io.File f = new java.io.File(p); return f.isFile() && f.canRead(); }","tryCatchPattern":"try {\n  MaxentTagger tagger = new MaxentTagger(modelPath);\n} catch (RuntimeIOException e) {\n  log.error(\"Tagger model load failed: {}\", e.getCause());\n  throw new ConfigurationException(\"Check model path/version: \" + modelPath, e);\n}","preventionTips":["Verify model file existence and readability before constructing MaxentTagger","Ship models with your app or download them at deploy time with a size check","Use absolute paths or classpath resources explicitly","Keep model files and CoreNLP versions in sync"],"tags":["java","io","model-loading","stanford-nlp"],"backgroundTag":"file-not-found","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}