nlp - 使用 Dialogflow 检测任意数量的意图
问题描述
在 Dialogflow(ES 版本)中,我们的意图是检测产品名称和可选数量。例如Do you have Pepsi
或I 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 |
+----------------+----------------+------+
解决方案
我创建了两个实体:@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 会将句子单词与实体匹配,并为每个实体分配不同的值。他还从训练短语中提取实体apples
,juices
尽管它们是复数形式。
我只是想尝试一下它是否可以与单个训练句子一起使用,并且效果出奇的好。首先我尝试了相同的训练语句,结果是:
"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 个产品。
推荐阅读
- qt - QML Mousearea onReleased 未发出
- ios - 为自定义类提供标准类型,但可以添加其他类型
- c++ - SIGTERM 后面是 SIGSEGV
- sql - MS SQL Server 中的字符索引
- pipeline - 如何正确并行化 Luigi 中的类似任务
- javascript - 如何将同一属性上的数组和对象“合并/合并”到平面数组中(使用Javascript)?
- asp.net - ASP.NET json 对象不包含自定义对象
- android - Twilio 语音集成在调试模式下工作,但不在签名的应用程序中
- r - 仅计算单行相异/距离矩阵
- php - 如何在 Laravel 的引导程序中突出显示当前菜单项?