stanfordnlp/CoreNLP · critical · RuntimeIOException

Failed to load segmenter

Error message

Failed to load segmenter 

What it means

loadSegmenter wraps failures from CRFClassifier.getClassifier (ClassCastException, IOException, ClassNotFoundException) in a RuntimeIOException prefixed 'Failed to load segmenter '. It means the serialized segmenter model file could not be read or deserialized as a CRFClassifier.

Solutions

  1. Verify the model file path exists and is readable before calling loadSegmenter
  2. Load the model with the same (or compatible) Stanford CoreNLP version it was serialized with
  3. Confirm the file actually is an ArabicSegmenter/CRFClassifier serialized model, not another artifact
  4. Check the cause exception (getCause) to distinguish file-not-found vs class-not-found vs cast failure

Example fix

// before
segmenter.loadSegmenter("arabic-segmenter.model"); // file missing
// after
java.io.File f = new java.io.File("arabic-segmenter.model");
if (!f.isFile()) throw new IllegalStateException("Model file missing: " + f);
segmenter.loadSegmenter(f.getPath());
Defensive patterns

Strategy: validation

Validate before calling

java.io.File f = new java.io.File(modelPath);
if (!f.isFile() || !f.canRead()) throw new IllegalStateException("Segmenter model missing: " + modelPath);

Try / catch

try { segmenter.loadSegmenter(modelPath, props); } catch (RuntimeIOException e) { e.getCause().printStackTrace(); /* file vs class problem */ }

Prevention

When it happens

Trigger: Calling loadSegmenter(filename[, properties]) or getSegmenter with a path that does not exist, is not readable, or contains a serialized object that is not a compatible CRFClassifier (wrong class or incompatible classpath/serialVersionUID).

Common situations: Wrong model file path or missing model on the classpath; loading a model serialized by a different Stanford CoreNLP version ( serialVersionUID / class change); passing a non-model file; ClassCastException when the file holds a different classifier type.

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/2461cdd2b6499441. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/international/arabic/process/ArabicSegmenter.java:466

   */
  private static void evaluateRawText(PrintWriter pwOut) {
    // TODO(spenceg): Evaluate raw input w.r.t. a reference that might have different numbers
    // of characters per sentence. Need to implement a monotonic sequence alignment algorithm
    // to align the two character strings.
    //    String gold = flags.answerFile;
    //    String rawFile = flags.testFile;
    throw new RuntimeException("Not yet implemented!");
  }

  public void serializeSegmenter(String filename) {
    classifier.serializeClassifier(filename);
  }

  public void loadSegmenter(String filename, Properties p) {
    try {
      classifier = CRFClassifier.getClassifier(filename, p);
    } catch (ClassCastException | IOException | ClassNotFoundException e) {
      throw new RuntimeIOException("Failed to load segmenter " + filename, e);
    }
  }

  @Override
  public void loadSegmenter(String filename) {
    loadSegmenter(filename, new Properties());
  }


  private static String usage() {
    String nl = System.lineSeparator();
    StringBuilder sb = new StringBuilder();
    sb.append("Usage: java ").append(ArabicSegmenter.class.getName()).append(" OPTS < file_to_segment").append(nl);
    sb.append(nl).append(" Options:").append(nl);
    sb.append("  -help                : Print this message.").append(nl);
    sb.append("  -orthoOptions str    : Comma-separated list of orthographic normalization options to pass to ArabicTokenizer.").append(nl);
    sb.append("  -tokenized           : Text is already tokenized. Do not run internal tokenizer.").append(nl);
    sb.append("  -trainFile file      : Gold segmented IOB training file.").append(nl);

View on GitHub (pinned to 1b7edd19c4)