Maven fails to download CoreNLP models
Asked Answered
I

3

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>
Ideography answered 28/8, 2013 at 15:48 Comment(0)
I
55

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.

Ideography answered 28/8, 2013 at 15:48 Comment(2)
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"Filiation
@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 !Cusco
S
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>
Sunk answered 14/8, 2017 at 3:3 Comment(0)
I
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'
Instructions answered 25/6, 2020 at 20:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.