Я пытаюсь использовать Google NLP API в своем коде Python и обнаружил, что когда я звоню с использованием analyse_sentiment или analysis_entity_sentiment, я иногда получаю нулевое значение в "счете", что является недокументированным поведением. Поэтому я попытался использовать «gcloud ml language analysis-sentiment» и был шокирован, обнаружив, что они дают разные результаты! Любые советы будут с благодарностью!
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."
Из Python - обратите внимание, что в нем отсутствует «оценка» + даже «величина» отличается! И "begin_offset" тоже неправильно ...
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."
}
}
]
}