Wit.ai Python - 从 API 输出中提取置信度
Wit.ai Python - Extract confidence level from API output
我是 Wit.ai 的新手,并已开始在我的代码中实现它。我正在考虑一种比硬编码更简单的方法来从给定的 wit.ai API 输出中提取所有置信度。
例如(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"
}
提前谢谢你。
您可以迭代 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)]
希望对您有所帮助
我是 Wit.ai 的新手,并已开始在我的代码中实现它。我正在考虑一种比硬编码更简单的方法来从给定的 wit.ai API 输出中提取所有置信度。
例如(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"
}
提前谢谢你。
您可以迭代 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)]
希望对您有所帮助