智慧aiPython从API输出中提取置信度

2024-10-01 09:25:13 发布

您现在位置:Python中文网/ 问答频道 /正文

我是新来的智慧ai并开始在我的代码中实现它。我在考虑一种比硬编码更简单的方法,从给定的数据中提取所有的置信度智慧aiAPI输出。你知道吗

例如(API输出):

{
  "_text": "I believe I am a human",
  "entities": {
    "statement": [
      {
        "confidence": 0.97691847787856,
        "value": "I",
        "type": "value"
      },
      {
        "confidence": 0.91728476663947,
        "value": "I",
        "type": "value"
      }
    ],
     "query": [
      {
        "confidence": 1,
        "value": "am",
        "type": "value"
      }
    ]
  },
  "msg_id": "0YKCUvDvHC2gyydiU"
}

先谢谢你。你知道吗


Tags: 数据方法代码textapi编码valuetype
1条回答
网友
1楼 · 发布于 2024-10-01 09:25:13

您可以迭代entities以获得confidence。你知道吗

比如:

data = {
"_text": "I believe I am a human",
"entities": {
    "statement": [
    {
        "confidence": 0.97691847787856,
        "value": "I",
        "type": "value"
    },
    {
        "confidence": 0.91728476663947,
        "value": "I",
        "type": "value"
    }
    ],
    "query": [
    {
        "confidence": 1,
        "value": "am",
        "type": "value"
    }
    ]
},
"msg_id": "0YKCUvDvHC2gyydiU"
}
confidence = list()
for k , v in data['entities'].iteritems():
    for item in v:
        confidence.append( (item['value'], item['confidence']))

print confidence

这给了我们:

[('I', 0.97691847787856), ('I', 0.91728476663947), ('am', 1)]

希望这有帮助

相关问题 更多 >