如何在Microsoft的LUIS上使用多个意图
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何在Microsoft的LUIS上使用多个意图相关的知识,希望对你有一定的参考价值。
我正在与LUIS合作,并希望不仅管理和处理最高得分意图,而且还要管理和处理所有其他人。在这种特定情况下,当某人查询同一短语中的两件事时。
例如:“我想买苹果”(“购买”意图)和“我想卖香蕉”(“卖”意图)与“我想买香蕉和卖苹果”(“买”和“卖”意图在同一个话语上)。
我们的想法是定义一个阈值,该阈值将接受任何高于此置信度数的意图得分“有效”。
在一些测试中,我发现如果我们对同一个话语的意图非常少,这可以起作用。
但是,如果我们增加相同话语上的意图数量,结果会非常快地降低。
我提供了一些例子来澄清我的意思:下面的输出示例是在LUIS上生成的4个意图(“买”,“卖”,“无”和“恶作剧”)和1个实体(“水果”)
我想买苹果==>
{
"query": "i want to buy apples",
"topScoringIntent": {
"intent": "Buy",
"score": 0.999846
},
"intents": [
{
"intent": "Buy",
"score": 0.999846
},
{
"intent": "None",
"score": 0.2572831
},
{
"intent": "sell",
"score": 2.32163586e-7
},
{
"intent": "prank",
"score": 2.32163146e-7
}
],
"entities": [
{
"entity": "apples",
"type": "Fruit",
"startIndex": 14,
"endIndex": 19,
"resolution": {
"values": [
"apple"
]
}
}
]
}
我想卖香蕉==>
{
"query": "i want to sell bananas",
"topScoringIntent": {
"intent": "sell",
"score": 0.999886036
},
"intents": [
{
"intent": "sell",
"score": 0.999886036
},
{
"intent": "None",
"score": 0.253938943
},
{
"intent": "Buy",
"score": 2.71893583e-7
},
{
"intent": "prank",
"score": 1.97906232e-7
}
],
"entities": [
{
"entity": "bananas",
"type": "Fruit",
"startIndex": 15,
"endIndex": 21,
"resolution": {
"values": [
"banana"
]
}
}
]
}
我想吃披萨==>
{
"query": "i want to eat a pizza",
"topScoringIntent": {
"intent": "prank",
"score": 0.997353
},
"intents": [
{
"intent": "prank",
"score": 0.997353
},
{
"intent": "None",
"score": 0.378299
},
{
"intent": "sell",
"score": 2.72957237e-7
},
{
"intent": "Buy",
"score": 1.54754474e-7
}
],
"entities": []
}
现在有了两个意图......每个人的得分开始急剧减少
我想买苹果并卖香蕉==>
{
"query": "i want to buy apples and sell bananas",
"topScoringIntent": {
"intent": "sell",
"score": 0.4442593
},
"intents": [
{
"intent": "sell",
"score": 0.4442593
},
{
"intent": "Buy",
"score": 0.263670564
},
{
"intent": "None",
"score": 0.161728472
},
{
"intent": "prank",
"score": 5.190861e-9
}
],
"entities": [
{
"entity": "apples",
"type": "Fruit",
"startIndex": 14,
"endIndex": 19,
"resolution": {
"values": [
"apple"
]
}
},
{
"entity": "bananas",
"type": "Fruit",
"startIndex": 30,
"endIndex": 36,
"resolution": {
"values": [
"banana"
]
}
}
]
}
如果我们包含第三个意图,LUIS似乎崩溃了:
我想买苹果,卖香蕉和吃披萨==>
{
"query": "i want to buy apples, sell bananas and eat a pizza",
"topScoringIntent": {
"intent": "None",
"score": 0.139652014
},
"intents": [
{
"intent": "None",
"score": 0.139652014
},
{
"intent": "Buy",
"score": 0.008631414
},
{
"intent": "sell",
"score": 0.005520768
},
{
"intent": "prank",
"score": 0.0000210663875
}
],
"entities": [
{
"entity": "apples",
"type": "Fruit",
"startIndex": 14,
"endIndex": 19,
"resolution": {
"values": [
"apple"
]
}
},
{
"entity": "bananas",
"type": "Fruit",
"startIndex": 27,
"endIndex": 33,
"resolution": {
"values": [
"banana"
]
}
}
]
}
您是否知道/建议我应该使用哪种方法来训练LUIS以缓解此问题?在同一个话语中处理多个意图是我的理由的关键。
非常感谢您的帮助。
您可能需要使用NLP对输入进行一些预处理,以便对句子进行分块,然后一次训练/提交一个块。我怀疑LUIS是否足够复杂以处理复合句中的多个意图。
下面是在Python中使用Spacy进行预处理的示例代码 - 没有对更复杂的句子进行测试,但这应该适用于您的例句。您可以使用以下段来提供给LUIS。
多个意图不是一个容易解决的问题,可能还有其他方法来处理它们
import spacy
model = 'en'
nlp = spacy.load(model)
print("Loaded model '%s'" % model)
doc = nlp("i want to buy apples, sell bananas and eat a pizza ")
for word in doc:
if word.dep_ in ('dobj'):
subtree_span = doc[word.left_edge.i : word.right_edge.i + 1]
print(subtree_span.root.head.text + ' ' + subtree_span.text)
print(subtree_span.text, '|', subtree_span.root.head.text)
print()
以上是关于如何在Microsoft的LUIS上使用多个意图的主要内容,如果未能解决你的问题,请参考以下文章
如何将 .wav 音频文件转换为文本并使用 LUIS 识别意图