{"record":{"id":"80302c664eabd254","repo":"stanfordnlp/CoreNLP","slug":"no-model-specified-for-sentiment-annotator","errorCode":null,"errorMessage":"No model specified for Sentiment annotator","messagePattern":"No model specified for Sentiment annotator","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/pipeline/SentimentAnnotator.java","lineNumber":59,"sourceCode":"\n  private static final String DEFAULT_MODEL = \"edu/stanford/nlp/models/sentiment/sentiment.ser.gz\";\n\n  private final String modelPath;\n  private final SentimentModel model;\n  private final CollapseUnaryTransformer transformer = new CollapseUnaryTransformer();\n\n  private final int nThreads;\n\n  /**\n   * Stop processing if we exceed this time limit, in milliseconds.\n   * Use 0 for no limit.\n   */\n  private final long maxTime;\n\n  public SentimentAnnotator(String annotatorName, Properties props) {\n    this.modelPath = props.getProperty(annotatorName + \".model\", DEFAULT_MODEL);\n    if (modelPath == null) {\n      throw new IllegalArgumentException(\"No model specified for Sentiment annotator\");\n    }\n    this.model = SentimentModel.loadSerialized(modelPath);\n    this.nThreads = PropertiesUtils.getInt(props, annotatorName + \".nthreads\", PropertiesUtils.getInt(props, \"nthreads\", 1));\n    this.maxTime = PropertiesUtils.getLong(props, annotatorName + \".maxtime\", -1);\n  }\n\n  @Override\n  public Set<Class<? extends CoreAnnotation>> requirementsSatisfied() {\n    return Collections.emptySet();\n  }\n\n  @Override\n  public Set<Class<? extends CoreAnnotation>> requires() {\n    return Collections.unmodifiableSet(new ArraySet<>(Arrays.asList(\n        CoreAnnotations.PartOfSpeechAnnotation.class,\n        TreeCoreAnnotations.TreeAnnotation.class,\n        TreeCoreAnnotations.BinarizedTreeAnnotation.class,\n        CoreAnnotations.CategoryAnnotation.class","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/pipeline/SentimentAnnotator.java#L41-L77","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":"// before\nProperties props = new Properties();\nprops.setProperty(\"annotators\", \"tokenize,ssplit,sentiment\");\n// after\nprops.setProperty(\"annotators\", \"tokenize,ssplit,sentiment\");\nprops.setProperty(\"sentiment.model\", \"edu/stanford/nlp/models/sentiment/sentiment.binary.gz\");","handlingStrategy":"validation","validationCode":"String model = props.getProperty(\"sentiment.model\");\nif (model == null || model.isEmpty()) {\n  props.setProperty(\"sentiment.model\", \"edu/stanford/nlp/models/sentiment/sentiment.binary.gz\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  SentimentAnnotator a = new SentimentAnnotator(\"sentiment\", props);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().contains(\"No model specified\")) {\n    props.setProperty(\"sentiment.model\", \"edu/stanford/nlp/models/sentiment/sentiment.binary.gz\");\n    a = new SentimentAnnotator(\"sentiment\", props);\n  } else throw e;\n}","preventionTips":["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."],"tags":["corenlp","sentiment","configuration","model"],"backgroundTag":"missing-required-config-field","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}