stanfordnlp/CoreNLP · error · IllegalArgumentException
No model specified for Sentiment annotator
Error message
No model specified for Sentiment annotator
What it means
SentimentAnnotator's constructor resolves its model path from property '<name>.model' (e.g. sentiment.model) and falls back to DEFAULT_MODEL; if both are null it throws IllegalArgumentException because the sentiment classifier cannot be loaded without a trained model file.
Solutions
- Set an explicit model path: -Dsentiment.model=edu/stanford/nlp/models/sentiment/sentiment.binary.gz.
- Check for an empty-string override of sentiment.model in your properties or command line.
- Verify the model file exists on the classpath or at the given filesystem path before constructing the pipeline.
Example fix
// before
Properties props = new Properties();
props.setProperty("annotators", "tokenize,ssplit,sentiment");
// after
props.setProperty("annotators", "tokenize,ssplit,sentiment");
props.setProperty("sentiment.model", "edu/stanford/nlp/models/sentiment/sentiment.binary.gz"); Defensive patterns
Strategy: validation
Validate before calling
String model = props.getProperty("sentiment.model");
if (model == null || model.isEmpty()) {
props.setProperty("sentiment.model", "edu/stanford/nlp/models/sentiment/sentiment.binary.gz");
} Try / catch
try {
SentimentAnnotator a = new SentimentAnnotator("sentiment", props);
} catch (IllegalArgumentException e) {
if (e.getMessage().contains("No model specified")) {
props.setProperty("sentiment.model", "edu/stanford/nlp/models/sentiment/sentiment.binary.gz");
a = new SentimentAnnotator("sentiment", props);
} else throw e;
} Prevention
- Explicitly set sentiment.model in pipeline properties rather than relying on defaults.
- Check command-line/properties precedence for empty-string overrides.
- Verify the model resource resolves on the classpath before pipeline startup.
When it happens
Trigger: Adding the 'sentiment' annotator to a pipeline with sentiment.model set to the empty string (getProperty returns "" only if set; null when neither property nor DEFAULT_MODEL exists, e.g. a build where DEFAULT_MODEL is null or the property value resolves to null via provider).
Common situations: Typos like sentiment.model pointing at a removed key, overriding properties through command-line -sentiment.model="", or distributions where the default model path resource is absent.
Understand the failure class
Background: "is required", "must be set", "missing required field": configuration validation errors across open-source libraries — this error's family across 36 libraries.
Related errors
- Invalid metric type for
- Invalid ordering constraint
- Cannot have these two ordering constraints
- Cannot have these two ordering constraints
- No input file specified!
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/80302c664eabd254.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/pipeline/SentimentAnnotator.java:59
private static final String DEFAULT_MODEL = "edu/stanford/nlp/models/sentiment/sentiment.ser.gz";
private final String modelPath;
private final SentimentModel model;
private final CollapseUnaryTransformer transformer = new CollapseUnaryTransformer();
private final int nThreads;
/**
* Stop processing if we exceed this time limit, in milliseconds.
* Use 0 for no limit.
*/
private final long maxTime;
public SentimentAnnotator(String annotatorName, Properties props) {
this.modelPath = props.getProperty(annotatorName + ".model", DEFAULT_MODEL);
if (modelPath == null) {
throw new IllegalArgumentException("No model specified for Sentiment annotator");
}
this.model = SentimentModel.loadSerialized(modelPath);
this.nThreads = PropertiesUtils.getInt(props, annotatorName + ".nthreads", PropertiesUtils.getInt(props, "nthreads", 1));
this.maxTime = PropertiesUtils.getLong(props, annotatorName + ".maxtime", -1);
}
@Override
public Set<Class<? extends CoreAnnotation>> requirementsSatisfied() {
return Collections.emptySet();
}
@Override
public Set<Class<? extends CoreAnnotation>> requires() {
return Collections.unmodifiableSet(new ArraySet<>(Arrays.asList(
CoreAnnotations.PartOfSpeechAnnotation.class,
TreeCoreAnnotations.TreeAnnotation.class,
TreeCoreAnnotations.BinarizedTreeAnnotation.class,
CoreAnnotations.CategoryAnnotation.classView on GitHub (pinned to 1b7edd19c4)