I am trying to use the Google NLP API in my Python code and found that when I call using analyze_sentiment or analyze_entity_sentiment, I sometimes get null in "score", which is undocumented behavior. Hence, I tried to use "gcloud ml language analyze-sentiment" and was shocked to find that they return different results! Any hints would be greatly appreciated!
from google.cloud import language
// I setup my credentials here
lsclient = language.LanguageServiceClient(credentials=credentials)
document = types.Document(content="@stevenmnuchin1 @Apple @tim_cook How much did this trip cost us? I\'m sure you took your wife and did some sightseeing.", type=enums.Document.Type.PLAIN_TEXT)
overall_sentiment = lsclient.analyze_sentiment(document=document)
VS.
gcloud ml language analyze-sentiment --content="@stevenmnuchin1 @Apple @tim_cook How much did this trip cost us? I\'m sure you took your wife and did some sightseeing."
From Python - note that it is missing "score" + even the "magnitude" is different! And the "begin_offset" is wrong too...
document_sentiment {
magnitude: 0.6000000238418579
}
language: "en"
sentences {
text {
content: "@stevenmnuchin1 @Apple @tim_cook How much did this trip cost us?"
begin_offset: -1
}
sentiment {
magnitude: 0.30000001192092896
score: -0.30000001192092896
}
}
sentences {
text {
content: "I\'m sure you took your wife and did some sightseeing."
begin_offset: -1
}
sentiment {
magnitude: 0.30000001192092896
score: 0.30000001192092896
}
}
VS. gcloud
{
"documentSentiment": {
"magnitude": 0.3,
"score": -0.1
},
"language": "en",
"sentences": [
{
"sentiment": {
"magnitude": 0.3,
"score": -0.3
},
"text": {
"beginOffset": 0,
"content": "@stevenmnuchin1 @Apple @tim_cook How much did this trip cost us?"
}
},
{
"sentiment": {
"magnitude": 0.0,
"score": 0.0
},
"text": {
"beginOffset": 65,
"content": "I\\'m sure you took your wife and did some sightseeing."
}
}
]
}