【问题标题】:How to work with multiple intents on Microsoft's LUIS如何在 Microsoft 的 LUIS 上使用多个意图
【发布时间】:2018-03-02 17:02:12
【问题描述】:

我正在与 LUIS 合作,我想管理和处理的不仅是最高得分意图,还包括所有其他意图。在这种特定情况下,当有人在同一个短语中询问两件事时,就会发生这种情况。

例如:“我想买苹果”(“买”意图)和“我想卖香蕉”(“卖”意图)与“我想买香蕉卖苹果”(“买”和“销售”的意图相同的话语)。

这个想法是定义一个阈值,该阈值将接受高于此置信度数的任何意图得分为“有效”。

在一些测试中,我发现如果我们对同一个话语的意图很少,这可以工作。

但是,如果我们增加同一话语的意图数量,结果会迅速下降。

我提供了一些示例来阐明我的意思:下面的输出示例是在具有 4 个意图(“购买”、“销售”、“无”和“恶作剧”)和 1 个实体(“水果”)的 LUIS 上生成的

我想买苹果 ==>

{
  "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 以缓解此问题的任何方法?在同一个话语中处理多个意图是我的案例的关键。

非常感谢您的帮助。

【问题讨论】:

  • 每个领域意图应至少有 10 个话语,其中每个意图的话语与其他意图话语不同。 none 意图不应包含任何与域相关的意图,并且应包含至少 10% 的总话语数。
  • 在此处查看我对 1 个 LUIS 查询中的多个意图的回答:stackoverflow.com/questions/48703996/…

标签: nlp microsoft-cognitive azure-language-understanding


【解决方案1】:

您可能需要使用 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()

【讨论】:

  • 只是为了确保我理解你的提议......这个想法是确定哪些句子具有意图并在不同的调用中打破它?我的意思是......如果短语/话语有两个意图,我应该将它分成两个单独的话语并单独提交?
  • 是的,但是除非您使用 NLP 库并进行一些解析,否则您不会知道如何打断句子。请参阅我编辑的答案中的示例代码。
【解决方案2】:

如果你知道你期望的排列,你可能能够得到你需要的信息。

除了单独的买卖意图之外,我还定义了一个单一的“买卖”意图。我创建了两个实体“Buy Fruit”和“Sell Fruit”,每个实体都包含您示例中的“Fruit”实体。然后在“买和卖”意图中,我使用了诸如“我想买苹果卖香蕉”之类的示例话语,以及切换买/卖。我将水果标记为“水果”实体,并将短语分别标记为“买水果”和“卖水果”。

这是我从“我想买一根香蕉卖一个苹果”得到的输出:

{
    "query": "I want to buy a banana and sell an apple",
    "prediction": {
        "topIntent": "buy and sell",
        "intents": {
            "buy and sell": {
                "score": 0.899272561
            },
            "Buy": {
                "score": 0.06608531
            },
            "Sell": {
                "score": 0.03477564
            },
            "None": {
                "score": 0.009155964
            }
        },
        "entities": {
            "Buy Fruit": [
                {}
            ],
            "Sell Fruit": [
                {}
            ],
            "Fruit": [
                "banana",
                "apple"
            ],
            "keyPhrase": [
                "banana",
                "apple"
            ],
            "$instance": {
                "Buy Fruit": [
                    {
                        "type": "Buy Fruit",
                        "text": "buy a banana",
                        "startIndex": 10,
                        "length": 12,
                        "score": 0.95040834,
                        "modelTypeId": 1,
                        "modelType": "Entity Extractor",
                        "recognitionSources": [
                            "model"
                        ]
                    }
                ],
                "Sell Fruit": [
                    {
                        "type": "Sell Fruit",
                        "text": "sell an apple",
                        "startIndex": 27,
                        "length": 13,
                        "score": 0.7225706,
                        "modelTypeId": 1,
                        "modelType": "Entity Extractor",
                        "recognitionSources": [
                            "model"
                        ]
                    }
                ],
                "Fruit": [
                    {
                        "type": "Fruit",
                        "text": "banana",
                        "startIndex": 16,
                        "length": 6,
                        "score": 0.9982499,
                        "modelTypeId": 1,
                        "modelType": "Entity Extractor",
                        "recognitionSources": [
                            "model"
                        ]
                    },
                    {
                        "type": "Fruit",
                        "text": "apple",
                        "startIndex": 35,
                        "length": 5,
                        "score": 0.98748064,
                        "modelTypeId": 1,
                        "modelType": "Entity Extractor",
                        "recognitionSources": [
                            "model"
                        ]
                    }
                ],
                "keyPhrase": [
                    {
                        "type": "builtin.keyPhrase",
                        "text": "banana",
                        "startIndex": 16,
                        "length": 6,
                        "modelTypeId": 2,
                        "modelType": "Prebuilt Entity Extractor",
                        "recognitionSources": [
                            "model"
                        ]
                    },
                    {
                        "type": "builtin.keyPhrase",
                        "text": "apple",
                        "startIndex": 35,
                        "length": 5,
                        "modelTypeId": 2,
                        "modelType": "Prebuilt Entity Extractor",
                        "recognitionSources": [
                            "model"
                        ]
                    }
                ]
            }
        }
    }
}

要完成这项工作,您必须满足所有可能的排列方式,因此严格来说,这并不是识别多种意图的解决方案。它更多的是为您想要满足的单个意图的每个排列定义一个复合意图。在许多不实用的应用程序中,但在您的示例中它可以为您带来满意的结果。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多