Search code examples
javamachine-learningnlpstanford-nlpnamed-entity-recognition

Customized StanfordNER


I am trying to build a customized StanfordNer model, training data and properties file are ready.
But when I am trying to run the following code :

java -cp "stanford-ner.jar:lib/*" -mx4g edu.stanford.nlp.ie.crf.CRFClassifier -prop download.txt

This error is popping out :

Error: Could not find or load main class edu.stanford.nlp.ie.crf.CRFClassifier

Steps followed:

  1. Downloaded and extracted stanford-ner-2018-10-16.zip file.
  2. Java 8 installed and $JAVA_HOME has been set.
  3. The properties file (download.txt) has been placed in the folder where stanford-ner-2018-10-16.zip is extracted.

Solution

  • If you are seeing errors like that it means your CLASSPATH is not properly configured.

    You need to run that command in the same folder as the NER download or it won't find the needed jars. That command should be run in whatever directory has stanford-ner.jar and lib in it. Alternatively you can just set the CLASSPATH environment variable and remove the -cp option from the command.

    More info on Java CLASSPATH here: https://docs.oracle.com/javase/tutorial/essential/environment/paths.html