hhsecond/corenlp_pywrap

Sentiment Annotator is not working

AbhinavBhatnagar opened this issue · 14 comments

Hello,

I was trying to get this working on some customer related data. None of the hacks are working although through command line I can run the sentiment analysis. Please advise as I don't want to switch to Java for this. Couldn't find anything on sentiment using Stanford CoreNLP APIs.

from corenlp_pywrap import pywrap
full_annotator_list = pywrap.CoreNLP.annotator_full_list + ['sentiment']
cn = pywrap.CoreNLP(url='http://localhost:9000', annotator_list=full_annotator_list)
out = cn.basic("this movie was good but highly overrated", out_format='json')
print(out.content)

Thanks.
AB

Very much appreciated, if you could solve this. I am looking to use sentiment annotator too. Thanks

S.W.

I can confirm that it is an issue in the wrapper. I just download the most current corenlp server, compile it as jar, then run the server. I am able to get sentiment result from the server via standard method: annotator sentiment. However it is not working with sentiment annotator with python wrapper.

S.W.

Well, as a work around I wrote a code to get me the sentiment scores in Java(took the code from stanford sentimentannotator class) and used Pyjnius to wrap around the code to use in Python. Here, issue might be(I guess) the Stanford CoreNLP API is not supporting the sentiment annotator right now or I am missing something to get it working.

Thanks.
AB

@AbhinavBhatnagar Thanks for the heads up. it seems Pyjnius is not working in python 3.5. also another issues, it seems that I am not able to load StanfordCoreNLP.java properly, so I am not able to construct StanfordCoreNLP. any idea?

@AbhinavBhatnagar I know this could be a big ask. could you please share your sentiment scores java code with me? for some reason, my java code is not working. I am new to Java. I am using "Py4j" to access JVM. my email: sceamms@gmail.com

really appreciate it.

S.W.

ok, I also have it working via py4j,wrote a java program.

My bad @sceamms I have been writing a wrapper for you in python. Great!!

@sceamms
@AbhinavBhatnagar

If its working manually, it should work with pywrap. Can you share some screeshot or the code you use for running it manually. Let me check for some subtle bugs.
Do share the code you used with pywrap.
I hope you verified the working of sentiment annotator by using the server method of Stanford .i.e. from browser.

@AbhinavBhatnagar Thank your for your kindness. appreciate it!

@hhsecond there are 2 options depends on your need of sentiment: if you only need sentiment result based on the sentence.e.g. Positive, Neutral, Negative.

It is still to use corenlp server, but the official published release "stanford-corenlp-full-2015-12-09", there is a bug in it, sentiment annotator cannot be added to the server. It is corenlp bug. However you can download the latest corenlp (you need to compile it yourself) from github: https://github.com/stanfordnlp/CoreNLP
follow the instruction to compile it and create a Jar to replace stanford-corenlp-3.6.0.JAR in the working directory of stanford-corenlp-full-2015-12-09.

then you need to download the latest model via: http://nlp.stanford.edu/software/stanford-corenlp-models-current.jar

use this most current model to replace "stanford-corenlp-3.6.0-models.jar" in the folder.

then you restart the server from the web localhost:9000, you will be able to add "sentiment annotator":

if you want to have it python result, there is another wrapper "pycorenlp": it is working with sentiment annotator by default: code as below, very simple.

from pycorenlp import StanfordCoreNLP
nlp = StanfordCoreNLP('http://localhost:9000')
text = '9988??'
output = nlp.annotate(text, properties={'annotators': 'sentiment', 'outputFormat': 'json'})
print(output['sentences'][0]['sentiment'])

in my case, I need to get score distribution for some specific reason, which is a bit more complex, I can not use server directly (it does not support I believe). I need to have access some corenlp java class in python.

for normal purpose, above method should be enough..

good luck.

@AbhinavBhatnagar Very cool! Thank you. Certainly will use it as an alternative. Like to have both options.

@hhsecond I am running into the same issue. The sentiment annotator works well in the browser but gives "AssertionError: annotator not supported: {'sentiment'}" error running the python wrapper. I am running the latest Core NLP 3.7.0 so it should have sentiment support.
I'd really appreciate the help!

Hi @bwang12 , I am no longer maintaining this project. There is a new 3.7 python wrapper for CoreNLP. I haven't tested it but it should have all those features.
Even if you want to use corenlp_pywrap, the script is so simple that you can easily make changes to it. Would be happy to merge the PR if you are working on it.

Closing it due to inactivity