-
Notifications
You must be signed in to change notification settings - Fork 73
Description
I am comparing the corenlp wrapper with stanza for sentiment analysis but they output different results for many cases.
Any Idea why?
The code-
from pycorenlp import StanfordCoreNLP
text = 'Ein Neujahrsvorsatz könnte sein dass die Regierung nie vergißt, wofür das Digitale ist für alle Menschen, groß und klein.und dass sie Euch mit einbezieht und nicht nur auf die Wirtschaft schielt.'
nlp = StanfordCoreNLP('http://localhost:9000')
res = nlp.annotate(text,
properties={
'annotators': 'sentiment',
'outputFormat': 'json',
'timeout': 10000,
})
for s in res["sentences"]:
print("%d: '%s': %s %s" % (
s["index"],
" ".join([t["word"] for t in s["tokens"]]),
s["sentimentValue"], s["sentiment"]))
Output -
'Ein Neujahrsvorsatz könnte sein dass die Regierung nie vergißt , wofür das Digitale ist für alle Menschen , groß und klein.und dass sie Euch mit einbezieht und nicht nur auf die Wirtschaft schielt .': 1 Negative
import stanza
text = 'Ein Neujahrsvorsatz könnte sein dass die Regierung nie vergißt, wofür das Digitale ist für alle Menschen, groß und klein.und dass sie Euch mit einbezieht und nicht nur auf die Wirtschaft schielt.'
0 is negative, 1 is neutral, 2 is positive https://stanfordnlp.github.io/stanza/sentiment.html
nlp = stanza.Pipeline(lang='de', processors='tokenize,sentiment')
doc = nlp(text)
for a, sentence in enumerate(doc.sentences):
print(sentence.sentiment)
Output -
1