stanfordnlp/CoreNLP · error · UnsupportedOperationException

This version of the parser does not support non-tree…

Error message

This version of the parser does not support non-tree training data

What it means

ChineseCharacterBasedLexicon only trains on parse trees; trainUnannotated (used when the parser reads raw, unannotated sentences for semi-supervised/unsupervised training) is explicitly unimplemented and throws UnsupportedOperationException.

Solutions

  1. Train only on treebank trees (train(Collection<Tree>) / train(Tree, weight)) with this lexicon
  2. Use a word-based lexicon (e.g. ChineseLexicon / ChineseTreebankParserParams default) if you need unannotated training
  3. Guard training code: only call trainUnannotated when the lexicon supports it (feature-check by type)
  4. Upgrade/patch the lexicon to implement training from tagged sentences if semi-supervision is required

Example fix

// before
lexicon.trainUnannotated(sentence, 1.0);
// after
if (!(lexicon instanceof ChineseCharacterBasedLexicon)) {
  lexicon.trainUnannotated(sentence, 1.0);
}
Defensive patterns

Strategy: type-guard

Validate before calling

if (lexicon instanceof ChineseCharacterBasedLexicon) {
  // train only on trees
  lexicon.train(trees, 1.0);
}

Type guard

boolean supportsUnannotatedTraining(Lexicon l) {
  return !(l instanceof ChineseCharacterBasedLexicon);
}

Try / catch

try { lexicon.trainUnannotated(sents, 1.0); } catch (UnsupportedOperationException e) { log.warn("Lexicon cannot use unannotated data; ignoring " + sents.size() + " sentences"); }

Prevention

When it happens

Trigger: Training a Chinese character-based lexicon with a training pipeline that feeds unannotated/tagged-only sentences, i.e. any path calling Lexicon.trainUnannotated(sentence, weight).

Common situations: Using -unannotatedSentences style options or semi-supervised training loops with a character-based Chinese model; copying training code from a word-based lexicon setup to the character-based one.

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/73806b816d4d3d2b. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/parser/lexparser/ChineseCharacterBasedLexicon.java:93

  @Override
  public void train(Collection<Tree> trees, double weight) {
    for (Tree tree : trees) {
      train(tree, weight);
    }
  }

  /**
   * TODO: make this method do something with the weight
   */
  @Override
  public void train(Tree tree, double weight) {
    trainingSentences.add(tree.taggedYield());
  }

  @Override
  public void trainUnannotated(List<TaggedWord> sentence, double weight) {
    // TODO: for now we just punt on these
    throw new UnsupportedOperationException("This version of the parser does not support non-tree training data");
  }

  @Override
  public void incrementTreesRead(double weight) {
    throw new UnsupportedOperationException();
  }

  @Override
  public void train(TaggedWord tw, int loc, double weight) {
    throw new UnsupportedOperationException();
  }


  @Override
  public void train(List<TaggedWord> sentence, double weight) {
    trainingSentences.add(sentence);
  }

View on GitHub (pinned to 1b7edd19c4)