google-app-engine - “gcloud ml language analyze-sentiment”从 Python 客户端 analyze_sentiment 返回不同的结果
问题描述
我试图在我的 Python 代码中使用 Google NLP API,发现当我使用 analyze_sentiment 或 analyze_entity_sentiment 调用时,有时会在“score”中得到 null,这是未记录的行为。因此,我尝试使用“gcloud ml language analyze-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。云
{
"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."
}
}
]
}
解决方案
推荐阅读
- mergesort - 合并排序的辅助内存?
- javascript - 如何优化 Typescript 中的 if 语句
- awk - 大文件的 AWK 条件失败,但适用于较小的文件
- c++ - 如何在 main 中调用重载的 + 运算符函数,只传递一个参数?
- c# - 如何在 dotnet core3 中使用 Glimpse?当导航 https://localhost:44398/Glimpse.axd 发生 404 错误
- javascript - 如何设置一个失败的承诺值
- algorithm - 递归关系:T(n) = T(ceil(n/3)) + T(ceil(3n/5)) + 100*n
- javascript - 在循环中重用变量时,哪一个更有效?
- sqlite - 如何在 SQLite 中找到所有与另一个人共享相同地址的人
- bash - 在不同的 Jenkins 阶段不再找到命令