1

我试图在我的 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."
      }
    }
  ]
}
4

0 回答 0