首页 > 解决方案 > 使用 Dialogflow 检测任意数量的意图

问题描述

在 Dialogflow(ES 版本)中,我们的意图是检测产品名称和可选数量。例如Do you have PepsiI need 4 apples。我们还有一些包含不止一种产品的训练示例。例如:I need 2 brush and 3 chocolates

一般的想法是使实体提取通用,以便我们可以查询n产品数量。例如,1 Pepsi, 2 eggs, 5 ice cream, and 4 tomatoes将正确提取 4 种不同的产品。

但是我们做了一些手动测试,发现实体提取通常不会扩展到任意数量的实体。这是 Dialogflow 的限制,还是我们需要调整我们的训练数据以包含更多具有 4/5+ 产品的示例?

我正在寻找有关使用任意数量的实体处理此类查询的建议。

对话流设置:

ML Threshold: 0.3

实体:

Product: Some product names as training data. **Automated expansion** and **Fuzzy matching** enabled.
Product-count: @sys.number. All options disabled 

Product_Query 意图参数:

+----------------+----------------+------+
| Parameter Name |     Entity     | Type |
+----------------+----------------+------+
| products       | @Products      | List |
| product-count  | @Product-count | List |
+----------------+----------------+------+

标签: nlpdialogflow-esnlu

解决方案


我创建了两个实体:@products 和 @count:

@products         @count       *it sounds dumb to use this @count but is useful for 
banana            1             this example
apple             2
pepsi             3
cocacola          4 
pear              5
orange            6
juice             7
book              8 

然后我创建了一个名为 products_detection 的意图并添加了训练短语:

I want 1 banana, 2 apples, 3 juices, 4 pear, 5 orange, 6 book, 7 cocacola, 8 pepsi

单击输入后,Dialogflow 会将句子单词与实体匹配,并为每个实体分配不同的值。他还从训练短语中提取实体applesjuices尽管它们是复数形式。

我只是想尝试一下它是否可以与单个训练句子一起使用,并且效果出奇的好。首先我尝试了相同的训练语句,结果是:

"parameters": {
      "count2": "3",
      "count14": "7",    <-------------
      "count": "1",                    | You can see that the product and count
      "products14": "cocacola",   <----  matches for all products
      "products13": "book",
      "products12": "orange",
      "count12": "5",
      "count21": "8",
      "count11": "4",
      "count1": "2",
      "products21": "pepsi",
      "count13": "6",
      "products2": "juice",
      "products": "banana",
      "products1": "apple",
      "products11": "pear"
    },

然后我混合了数字和产品并尝试了以下短语:

I want 5 banana, 8 apples, 7 juices, 3 pepsi, 1 cocacola, 2 orange, 4 book, 6 pear

我得到:

"parameters": {
      "count1": "8",
      "count12": "1",
      "count14": "4",
      "count21": "6",
      "products13": "orange",
      "count11": "3",
      "products14": "book",
      "products2": "juice",
      "count": "5",
      "products21": "pear",
      "products1": "apple",
      "products12": "cocacola",
      "count2": "7",
      "products": "banana",
      "products11": "pepsi",
      "count13": "2"
    },

如您所见,产品仍然与计数匹配,这里有超过 5 个产品。


推荐阅读