stanfordnlp/CoreNLP · error · UnsupportedOperationException
Predict not implemented for max margin
Error message
Predict not implemented for max margin
What it means
The maxMargin loss function intentionally has no predict() implementation; calling predict on a Loss returned by SimpleLinearClassifier.maxMargin(h) throws UnsupportedOperationException. Max-margin losses only define the hinge derivative for training, not a scoring function.
Solutions
- Do not call predict with a maxMargin loss; use a differentiable/scoreable loss such as logistic for inference
- Rebuild the classifier with logistic loss before scoring
- Use the raw weights dot-product yourself instead of Loss.predict if you need margin scores
Example fix
// before SimpleLinearClassifier clf = new SimpleLinearClassifier(SimpleLinearClassifier.maxMargin(1.0), modelFile); double score = clf.predict(example, features, compressor); // throws // after SimpleLinearClassifier clf = new SimpleLinearClassifier(Loss.logistic, modelFile); double score = clf.predict(example, features, compressor);
Defensive patterns
Strategy: validation
Validate before calling
if (loss instanceof SimpleLinearClassifier.Loss) {
// ensure loss is not maxMargin before calling predict
assert !isMaxMargin(loss) : "maxMargin loss does not support predict";
} Try / catch
try {
double score = classifier.predict(example, feats, compressor);
} catch (UnsupportedOperationException e) {
throw new IllegalStateException("use a scoreable loss (e.g. logistic) for predict", e);
} Prevention
- Use maxMargin only for training loops that call derivative()
- Switch to logistic loss before any inference/scoring
- Document which loss the classifier was built with
When it happens
Trigger: Calling classifier.predict(example, ...) (SimpleLinearClassifier.predict at line 184) when the classifier was constructed with the Loss returned by maxMargin(h).
Common situations: Training a coref classifier with max-margin loss, then reusing it for inference/scoring instead of switching to a loss that supports prediction (e.g. logistic).
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
- LogPrior.getSigmaSquaredM is undefined for any prior but…
- If you want to ask for the probability, you must train a…
- Not implemented for this class.
- Error running testGibbs inference!
- Index out of bounds:
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/4b73387f2c1bb8f9.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/coref/statistical/SimpleLinearClassifier.java:184
(mistake - 1) * label / gamma : -label);
}
@Override
public String toString() {
return String.format("quadraticallySmoothed(%s)", gamma);
}
};
}
public static Loss hinge() {
return quadraticallySmoothedSVM(0);
}
public static Loss maxMargin(final double h) {
return new Loss() {
@Override
public double predict(double product) {
throw new UnsupportedOperationException("Predict not implemented for max margin");
}
@Override
public double derivative(double label, double product) {
return product < -h ? 0 : 1;
}
@Override
public String toString() {
return String.format("max-margin(%s)", h);
}
};
}
public static Loss risk() {
return new Loss() {
@Override
public double predict(double product) {View on GitHub (pinned to 1b7edd19c4)