我用rasa编写了一个简单的机器人。为了处理消息,我创建了flask应用程序并将代理加载到该应用程序中。我从请求中收到用户消息和ID,并将其放入代理handle_text方法中,然后得到响应。问题是当我讲了一个故事中定义的一个故事后。我的经纪人停止了回答。
这是我的烧瓶应用程序
app = Flask(__name__)
# Define rasa interpreter
interpreter = None
# Define rasa agent
agent = None
@app.route('/')
def index():
# Receive message from request
message = request.args.get('msg')
# Receive user id from request
user_id = request.args.get('uid')
# Validation
if not message:
return 'No message specified in field \'msg\''
if not user_id:
return 'No user id specified in field \'uid\''
# Put received message into rasa agent
answers = agent.handle_text(message, sender_id=user_id)
# Define text for the response
text = None
if len(answers) > 0:
text = "User: {} | {}".format(user_id, answers[0].get('text'))
else:
text = "User: {} | Nothing to answer".format(user_id)
return text
if __name__ == '__main__':
# Load rasa interpreter
interpreter = RasaNLUInterpreter(NLU_PATH)
# Load rasa agent
agent = Agent.load(CORE_PATH, interpreter=interpreter)
app.run()
我的故事。md是
## Simple flow
* greet
- utter_greet
* bye
- utter_bye
## Order pizza
* greet
- utter_greet
* order_pizza_type
- utter_finish_order_pizza
* bye
- utter_bye
## Story
* order_pizza_type
- utter_finish_order_pizza
## Generated Story -1054914010798310995
* greet
- utter_greet
* order_pizza_type{"Country": "mexican"}
- utter_finish_order_pizza
* bye
- utter_bye
## New Story
* greet
- utter_greet
* order_pizza_wish
- utter_finish_order_pizza
* bye
- utter_bye
和我的config.yml
language: "en"
pipeline:
- name: "nlp_spacy"
- name: "tokenizer_spacy"
- name: "ner_crf"
- name: "tokenizer_whitespace"
- name: "intent_featurizer_count_vectors"
- name: "intent_classifier_tensorflow_embedding"
intent_tokenization_flag: true
intent_split_symbol: "+"
policies:
- name: "KerasPolicy"
featurizer:
- name: MaxHistoryTrackerFeaturizer
max_history: 5
state_featurizer:
- name: BinarySingleStateFeaturizer
- name: "MemoizationPolicy"
max_history: 5
- name: "FallbackPolicy"
nlu_threshold: 0.4
core_threshold: 0.3
我的预期结果
$ curl -X GET "https://localhost?msg=hello&uid=1"
$ curl -X GET "https://localhost?msg=I want to order pizza&uid=1"
$ curl -X GET "https://localhost?msg=Bye&uid=1"
$ curl -X GET "https://localhost?msg=hello&uid=1"
响应
> User: 1 | Hey! How are you?
> User: 1 | Ok I will deliver pizza for you
> User: 1 | Bye
> User: 1 | Hey! How are you?
但是我的实际结果是
$ curl -X GET "https://localhost?msg=hello&uid=1"
$ curl -X GET "https://localhost?msg=I want to order pizza&uid=1"
$ curl -X GET "https://localhost?msg=Bye&uid=1"
$ curl -X GET "https://localhost?msg=hello&uid=1"
响应
> User: 1 | Hey! How are you?
> User: 1 | Ok I will deliver pizza for you
> User: 1 | Bye
> User: 1 | Nothing to answer
说完一个故事情节后,您看不到第二条消息“ hello”的任何响应。
答案 0 :(得分:1)
与评论中的建议相同,我建议使用interactive learning来调试您的机器人并创建新的培训案例。当前,您的训练数据非常稀疏。
您是否使用augmentation进行培训?如果您没有以其他方式指定参数,则默认扩展设置为20
。
如果您使用增强功能,我建议您还添加另一个简短的故事来处理独立的greet
:
## Simple flow
* greet
- utter_greet
还有一件事:
建议使用一般意图,并通过公认的实体来区分它们。
因此,最好有一个意图order_pizza_type
或什至order_pizza_wish
,然后再放置order_pizza
,order
的位置,而不是food_type
和product_to_order
(例如pizza
)等等。如果您有非常相似的意图,例如order_pizza_type
和order_pizza_wish
,NLU将很难区分它们。