例如,下面的句子。"hi good afternoon how are you doing". 这个笑话的意图是'问候'。当我请求'模型解析'的API时,它会返回正确的意图和实体。但是当我在这句话前面加上特殊字符''时,比如。"hi good afternoon how are you doing", "model parse "返回的意图是 "hi good afternoon how are you doing "而不是 "greet". 我看了rasa的源码,如下。
我如何处理特殊字符'',以考虑到源代码的RegexInterpreter,我举了这个例子? 最好是在不修改源代码的情况下解决。请帮助我,谢谢。
答:我想实现以下三个函数。
我想同时实现以下三个函数。
"model parse "返回的实际结果如下:
{
"text": "/ greet {\" people \ ": \" tom \ "}",
"intent": {
"name": "greet",
"confidence": 1.0
},
"intent_ranking": [
{
"name": "greet",
"confidence": 1.0
}
],
"entities": [
{
"entity": "people",
"start": 6,
"end": 22,
"value": "tom"
}
]
}
2,当message.text='Hi Tom,下午好'
'模型解析'返回的实际结果如下。
{
"text": "Hi Tom, good afternoon",
"intent": {
"name": "greet",
"confidence": 0.923
},
"intent_ranking": [
{
"name": "greet",
"confidence": 0.923
}
],
"entities": [
{
"entity": "people",
"start": 2,
"end": 5,
"value": "tom",
"confidence": 0.8433478958,
"extractor": "CRFEntityExtractor"
}
]
}
3,当message.text = 'Hi Tom, good afternoon'的时候
模型解析'实际返回的结果如下(这不是我想要的)。
{
"text": "/ Hi Tom, good afternoon",
"intent": {
"name": "Hi Tom, good afternoon",
"confidence": 1.0
},
"intent_ranking": [
{
"name": "Hi Tom, good afternoon",
"confidence": 1.0
}
],
"entities": []
}
但我期望的结果是这样的
{
"text": "Hi Tom, good afternoon",
"intent": {
"name": "greet",
"confidence": 0.923
},
"intent_ranking": [
{
"name": "greet",
"confidence": 0.923
}
],
"entities": [
{
"entity": "people",
"start": 2,
"end": 5,
"value": "tom",
"confidence": 0.8433478958,
"extractor": "CRFEntityExtractor"
}
]
}
请注意,第三个和第二个不同之处在于第三个 message.text 只在开头加上了''。
所以,有没有一种方法可以很好的解决这个问题,并且可以同时满足以上三种情况呢?
存在 /
在用户消息的开头,是直接触发意图的设定方式。从你所举的例子来看,它不像是在真实用户情况下会经常发生的事情(如果有的话)。也就是说,如果你确实想确保只有实际的意图才可以被触发。/
,你可以创建一个 自定义组件 其中去掉了任何前导 /
如果它后面没有被你的训练数据中已有的意图所跟随。
然而,在进行这种努力之前,我建议检查这种情况实际发生的频率。