方法 1 - 多意图
您可以使用多意图(不要与多实体混淆)。你需要做的是:
- 分别为意图编写示例 nlu 数据(您已有的)
- 为多意图组合写入 nlu 数据。理论上,Rasa 将同时使用来自单一意图和多意图示例的信息来正确分类。这意味着您在多意图中不需要那么多训练示例
- 写一些处理这些多意图的故事
- 在分词器配置中指定一个分隔符:
intent_split_symbol: "+"
请注意,您需要同时拥有要支持的多意图和故事的 NLU 数据,否则 Rasa 将无法在 NLU 中识别它们,并且不会在 Core 中执行任何操作。
参考资料:
示例
这可以给你这样的东西:
nlu.md
# intent:show transactions
- please show me my latest transactions
- show me my transactions
- ...
# intent:pay bill
- pay my bill please
- i want to pay my bill
- go ahead and pay the bills
- ...
# intent:show transactions+pay bill
- Show my latest transactions and then pay my bill after showing the balance.
- show me my transactions and go ahead and pay the bills
-
请注意,您可以编写一个脚本来自动从单个意图生成一些多意图示例
stories.md
# story 1
* show transactions
- action_show_transactions
# story 2
* pay bill
- action_pay_bill
# story 3 (combined)
* show transactions+pay bill
- action_show_transactions
- action_pay_bill
config.yml
language: "en"
pipeline:
- name: "WhitespaceTokenizer"
intent_split_symbol: "+"
- name: "CountVectorsFeaturizer"
- name: "EmbeddingIntentClassifier"
请注意,我使用的拆分符号与文档中的拆分符号不同。
方法 2 - 作为实体的指令
另一种方法是使用单个意图 ask_action 和一个或多个标识您的指令的实体。
然后您可以有一个操作action_execute_instructions 来处理所有这些问题。它会查看最新消息中的实体,并执行您需要的任何内容。
您如何理解指令很大程度上取决于您选择如何定义实体以及如何设法将它们映射到您想要的指令。有SynonymMapper,但它根本不灵活,如果您有一个不完全匹配的新示例,它将失败。在这种情况下,您最好编写自己的 NLU 管道组件。
说实话,我认为这不是一个好方法。实体应该是,嗯,实体(即:对象、位置等)
nlu.md
# intent:ask_action
- [Show my latest transactions](instruction) and then [pay my bill](instruction) after showing the balance.
- [show me my transactions](instruction) and go ahead and [pay the bills](instruction)
- [pay the bill](instruction)
stories.md
# story 1
* ask_action
- action_execute_instructions
建议
我强烈建议使用最简单的方法。一旦你的机器人上线,你应该检查你的用户如何使用它,看看是否需要更复杂的意图组合(如果你做多意图)。