Wit.ai Python – 从API输出中提取置信度水平

我刚开始使用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)]

希望这对您有帮助

Related Posts

L1-L2正则化的不同系数

我想对网络的权重同时应用L1和L2正则化。然而,我找不…

使用scikit-learn的无监督方法将列表分类成不同组别,有没有办法?

我有一系列实例,每个实例都有一份列表,代表它所遵循的不…

f1_score metric in lightgbm

我想使用自定义指标f1_score来训练一个lgb模型…

通过相关系数矩阵进行特征选择

我在测试不同的算法时,如逻辑回归、高斯朴素贝叶斯、随机…

可以将机器学习库用于流式输入和输出吗?

已关闭。此问题需要更加聚焦。目前不接受回答。 想要改进…

在TensorFlow中,queue.dequeue_up_to()方法的用途是什么?

我对这个方法感到非常困惑,特别是当我发现这个令人费解的…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注