26

When building the sample application from the Stanford CoreNLP website, I ran into a curious exception:

Exception in thread "main" java.lang.RuntimeException: edu.stanford.nlp.io.RuntimeIOException: Unrecoverable error while loading a tagger model
at edu.stanford.nlp.pipeline.StanfordCoreNLP$4.create(StanfordCoreNLP.java:493)
…
Caused by: java.io.IOException: Unable to resolve "edu/stanford/nlp/models/pos-tagger/english-left3words/english-left3words-distsim.tagger" as either class path, filename or URL
…

This only happened when the property pos and the ones after it were included in the properties.

Properties props = new Properties();
props.put("annotators", "tokenize, ssplit, pos, lemma, ner, parse, dcoref");
StanfordCoreNLP pipeline = new StanfordCoreNLP(props);

Here is the dependency from my pom.xml:

<dependencies>
<dependency>
    <groupId>edu.stanford.nlp</groupId>
    <artifactId>stanford-corenlp</artifactId>
    <version>3.2.0</version>
    <scope>compile</scope>
</dependency>
</dependencies>
Jonny
  • 1,453
  • 16
  • 25

3 Answers3

54

I actually found the answer to that in the problem description of another question on Stackoverflow.

Quoting W.P. McNeill:

Maven does not download the model files automatically, but only if you add models line to the .pom. Here is a .pom snippet that fetches both the code and the models.

Here's what my dependencies look like now:

<dependencies>
<dependency>
    <groupId>edu.stanford.nlp</groupId>
    <artifactId>stanford-corenlp</artifactId>
    <version>3.2.0</version>
</dependency>
<dependency>
    <groupId>edu.stanford.nlp</groupId>
    <artifactId>stanford-corenlp</artifactId>
    <version>3.2.0</version>
    <classifier>models</classifier>
</dependency>
</dependencies>

The important part to note is the entry <classifier>models</classifier> at the bottom. In order for Eclipse to maintain both references, you'll need to configure a dependency for each stanford-corenlp-3.2.0 and stanford-corenlp-3.2.0-models.

Community
  • 1
  • 1
Jonny
  • 1,453
  • 16
  • 25
  • 11
    In case you are using SBT, you can add the following lines to the library dependencies sequence : "edu.stanford.nlp" % "stanford-corenlp" % "3.2.0", "edu.stanford.nlp" % "stanford-corenlp" % "3.2.0" classifier "models" – eliasah Mar 03 '15 at 13:37
  • 2
    @eliasah: I am doing the same thing as you have stated in your comment , but its not downloading the models ! Its been 2 hrs and still it has not downloaded anything related to models ! – Shivansh Aug 10 '16 at 08:00
2

In case you need to use the models for other languages (like Chinese, Spanish, or Arabic) you can add the following piece to your pom.xml file (replace models-chinese with models-spanish or models-arabic for these two languages, respectively):

<dependency>
    <groupId>edu.stanford.nlp</groupId>
    <artifactId>stanford-corenlp</artifactId>
    <version>3.8.0</version>
    <classifier>models-chinese</classifier>
</dependency>
Pedram
  • 2,421
  • 4
  • 31
  • 49
1

With Gradle apparently you can use:

implementation 'edu.stanford.nlp:stanford-corenlp:3.9.2'
implementation 'edu.stanford.nlp:stanford-corenlp:3.9.2:models'

or if you use compile (depricated):

compile group: 'edu.stanford.nlp', name: 'stanford-corenlp', version: '3.9.2'
compile group: 'edu.stanford.nlp', name: 'stanford-corenlp', version: '3.9.2' classifier: 'models'
gneusch
  • 125
  • 6