stanfordnlp/CoreNLP · error · IllegalArgumentException
For now, only linear classifiers are supported
Error message
For now, only linear classifiers are supported
What it means
The search() method only supports ClauseSearcher implementations backed by a LinearClassifier. If an Optional-wrapped clause classifier was supplied whose runtime type is not LinearClassifier, an IllegalArgumentException is thrown. This is a deliberate capability restriction of the naturalli search implementation.
Solutions
- Pass a LinearClassifier instance (as produced by ClauseSplitter.train / ClauseSplitter.load) instead of a custom ClauseSearcher.
- If a custom classifier is required, extend or adapt the search() method to support its type, or wrap its scoring in a LinearClassifier-compatible interface.
- Check the classifier type before constructing the search problem and fail early with a clearer message.
Example fix
// before searchProblem.search(fragments, Optional.of(myCustomSearcher)); // after LinearClassifierWrapper lc = new LinearClassifierWrapper(...); // train or load a linear classifier searchProblem.search(fragments, Optional.of(lc));
Defensive patterns
Strategy: type-guard
Validate before calling
if (classifierOpt.isPresent() && !(classifierOpt.get() instanceof LinearClassifier)) {
throw new IllegalArgumentException("search requires a LinearClassifier");
} Type guard
boolean isLinear(ClauseSearcher c) { return c instanceof LinearClassifier; } Try / catch
try {
problem.search(fragments, classifierOpt);
} catch (IllegalArgumentException e) {
log.error("Non-linear clause classifier supplied", e);
} Prevention
- Only pass classifiers created by ClauseSplitter.train or ClauseSplitter.load
- Avoid custom ClauseSearcher subclasses unless you also patch search()
- Check the classifier type at configuration time, before search
When it happens
Trigger: Calling search() (directly or via topClauses/clauses/train) with an Optional<ClauseSearcher> containing a non-LinearClassifier, e.g. a custom ClauseSearcher subclass passed to ClauseSplitterSearchProblem.
Common situations: Plugging a custom classifier into ClauseSplitterSearchProblem; using an API that accepts any ClauseSearcher but whose search path only handles linear models.
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
- Invalid classifier label for isDone: " + argmax
- Attempting to remove features based on weight from a…
- Cannot run Natural Logic forward entailment without…
- Could not load clause splitter model at " + splitterModel
- Couldn't load classifier!
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/3dd2164e18993bdd.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/naturalli/ClauseSplitterSearchProblem.java:544
}
/**
* Search, using the default weights / featurizer. This is the most common entry method for the raw search,
* though {@link ClauseSplitterSearchProblem#topClauses(double, int)} may be a more convenient method for
* an end user.
*
* @param candidateFragments The callback function for results. The return value defines whether to continue searching.
*/
public void search(final Predicate<Triple<Double, List<Counter<String>>, Supplier<SentenceFragment>>> candidateFragments) {
if (!isClauseClassifier.isPresent()) {
search(candidateFragments,
new LinearClassifier<>(new ClassicCounter<>()),
HARD_SPLITS,
this.featurizer.orElse(DEFAULT_FEATURIZER),
1000);
} else {
if (!(isClauseClassifier.get() instanceof LinearClassifier)) {
throw new IllegalArgumentException("For now, only linear classifiers are supported");
}
search(candidateFragments,
isClauseClassifier.get(),
HARD_SPLITS,
this.featurizer.get(),
1000);
}
}
/**
* Search from the root of the tree.
* This function also defines the default action space to use during search.
* This is NOT recommended to be used at test time.
*
* @see edu.stanford.nlp.naturalli.ClauseSplitterSearchProblem#search(Predicate)
*
* @param candidateFragments The callback function.
* @param classifier The classifier for whether an arc should be on the path to a clause split, a clause split itself, or neither.View on GitHub (pinned to 1b7edd19c4)