Search code examples
javastanford-nlpsentiment-analysistraining-data

How to create a Stanford coreNLP model by training?


I'm very new to Stanford's coreNLP and I'm trying to train it by creating a model. I have a folder that has dev.txt, train.txt, and test.txt as well as a jar file named stanford-corenlp-3.5.1-models.jar. According to this question, I can create a model by executing the following command in the terminal:

java -mx8g edu.stanford.nlp.sentiment.SentimentTraining -numHid 25 -trainPath train.txt -devPath     dev.txt -train -model model.ser.gz

However, when I run that in the terminal, I get the following error:

Error: could not find or load main class edu.stanford.nlp.sentiment.SentimentTraining

Can anyone provide step-by-step instructions of how to go about training CoreNLP? I went on the Stanford website to see how training is done, but I'm still confused. I thought all I needed to create a model (e.g model.ser.gz) were those three text files and one jar file.

Any help is very appreciated, thank you!


Solution

  • You need to include the CoreNLP jar file in your classpath. So, your java command should look like:

    java -cp /path/to/corenlp/jar:/path/to/corenlp/library/dependencies -mx8g ...

    From the root of the CoreNLP distribution, you can just include all the jars in the directory; e.g.,

    java -cp "*" -mx8g edu.stanford.nlp.sentiment.SentimentTraining -numHid 25 -trainPath train.txt -devPath dev.txt -train -model model.ser.gz