stanfordnlp/CoreNLP · error · UnsupportedOperationException

Training is not supported!

Error message

Training is not supported!

What it means

ArabicSegmenter is an annotation-based segmenter that cannot be trained as a parser/treebank component. initializeTraining is overridden to always throw UnsupportedOperationException with this message.

Solutions

  1. Do not call initializeTraining on ArabicSegmenter; use testToSegment or load a serialized model instead
  2. Train an external CRF segmenter separately and load it via loadSegmenter/serialization
  3. Branch your pipeline code to skip training for segmentation annotators

Example fix

// before
segmenter.initializeTraining(numTrees);
// after
if (!(segmenter instanceof ArabicSegmenter)) segmenter.initializeTraining(numTrees);
Defensive patterns

Strategy: try-catch

Validate before calling

if (annotator instanceof ArabicSegmenter) {
  throw new IllegalStateException("ArabicSegmenter does not support training");
}

Type guard

boolean supportsTraining(Annotator a) { return !(a instanceof ArabicSegmenter); }

Try / catch

try {
  segmenter.initializeTraining(numTrees);
} catch (UnsupportedOperationException e) {
  // load serialized model instead
  segmenter.loadSegmenter(modelPath, props);
}

Prevention

When it happens

Trigger: Invoking initializeTraining(double numTrees) on an ArabicSegmenter instance, typically through generic training driver code (e.g. a TreebankLanguagePack-driven training loop).

Common situations: Plugging ArabicSegmenter into a pipeline that trains all annotators uniformly, or calling the training API out of habit from ArabicParser usage.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


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

Appendix: source

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

      if (tokenizerOptions == null) {
        tokFactory = ArabicTokenizer.atbFactory();
        String atbVocOptions = "removeProMarker,removeMorphMarker,removeLengthening";
        tokFactory.setOptions(atbVocOptions);
      } else {
        if (tokenizerOptions.contains("removeSegMarker")) {
          throw new RuntimeException("Option 'removeSegMarker' cannot be used with ArabicSegmenter");
        }
        tokFactory = ArabicTokenizer.factory();
        tokFactory.setOptions(tokenizerOptions);
      }
      log.info("Loaded ArabicTokenizer with options: " + tokenizerOptions);
    }
    return tokFactory;
  }

  @Override
  public void initializeTraining(double numTrees) {
    throw new UnsupportedOperationException("Training is not supported!");
  }

  @Override
  public void train(Collection<Tree> trees) {
    throw new UnsupportedOperationException("Training is not supported!");
  }

  @Override
  public void train(Tree tree) {
    throw new UnsupportedOperationException("Training is not supported!");
  }

  @Override
  public void train(List<TaggedWord> sentence) {
    throw new UnsupportedOperationException("Training is not supported!");
  }

  @Override

View on GitHub (pinned to 1b7edd19c4)