from convlab2.nlu.jointBERT.multiwoz import BERTNLU from convlab2.nlu.milu.multiwoz import MILU from convlab2.dst.rule.multiwoz import RuleDST from convlab2.policy.rule.multiwoz import RulePolicy from convlab2.nlg.template.multiwoz import TemplateNLG from convlab2.dialog_agent import PipelineAgent, BiSession from convlab2.evaluator.multiwoz_eval import MultiWozEvaluator from pprint import pprint import random import numpy as np import torch
print("import done!")
建立模型并建造一个agent
1 2 3 4 5 6 7 8 9 10 11 12 13
# go to README.md of each model for more information # BERT nlu,understanding sys_nlu = BERTNLU() # simple rule DST,tracking sys_dst = RuleDST() # rule policy,rule sys_policy = RulePolicy() # template NLG,生成 sys_nlg = TemplateNLG(is_user=False) # assemble,集成到一个pipeline里 sys_agent = PipelineAgent(sys_nlu, sys_dst, sys_policy, sys_nlg, name='sys')
print("build agent done!")
和agent进行手动输入对话测试
1 2 3 4 5 6 7 8 9 10 11 12
# 对话1 sys_agent.response("I want to find a moderate hotel") >>> We have 18 such places . How about bridge guest house ? Fits your request perfectly .
sys_agent.response("Which type of hotel is it ?") >>> It is a guesthouse .
sys_agent.response("OK , where is its address ?") >>> It is located at 124 tenison road.
sys_agent.response("Thank you !") >>> Thank you for contacting the help desk . Have a great day .
1 2 3 4 5 6 7 8 9
# 对话2 sys_agent.response("Try to find me a Chinese restaurant in south area .") >>> There are 3 different places that match your description . The lucky star has some great reviews . How about chinese ?
sys_agent.response("Which kind of food it provides ?") >>> They serve chinese .
sys_agent.response("Book a table for 5 , this Sunday .") >>> Your reference number is 00000003 .
3. Build a simulator to chat with the agent and evaluate
>>> init goal: {'attraction': {'info': {'area': 'east'}, 'reqt': {'address': '?', 'entrance fee': '?', 'phone': '?'}}} -------------------------------------------------- user: I am planning a trip to town and want to sight see a bit . Can you let me know some attractions I may be interested in ? Can you recommend some attractions in the east ? sys: There are 10 , anything in particular you are looking for ? I recommend saint barnabas press gallery. They are located at the belfast yard, coldham's road .
user: Sounds good . Could I get the phone number of the attraction ? Can you let me know what the entrance fee is too ? sys: The attraction phone number is 01223902088 . Its entrance fee is ? .
user: Does it have an entrance fee ? sys: Its entrance fee is ? .
user: Does it have an entrance fee ? sys: Their entrance fee is ? by our system currently .
user: Does it have an entrance fee ? sys: Their entrance fee is ? by our system currently .
user: I will need the entrance fee please . sys: Its entrance fee is ? .
user: I would like to know the entrance fee . sys: Their entrance fee is ? by our system currently .
user: What are the entrance fees ? sys: The entry fee is ? .
user: Can you tell me the entrance fee ? sys: Their entrance fee is ? by our system currently .
user: Does it have an entrance fee ? sys: Their entrance fee is ? by our system currently .
user: Does it have an entrance fee ? sys: Its entrance fee is ? .
user: Is there an entrance fee ? sys: The entry fee is ? .
user: Can you let me know what the entrance fee is too ? sys: The entry fee is ? .
user: Can you tell me the entrance fee ? sys: The entry fee is ? .
user: I will need the entrance fee please . sys: Their entrance fee is ? by our system currently .
user: I would like to know the entrance fee . sys: Their entrance fee is ? by our system currently .
user: I just need to know how much the entrance fee is . sys: Their entrance fee is ? by our system currently .
user: Can you give me the entrance fee ? sys: Their entrance fee is ? by our system currently .
user: Can you let me know what the entrance fee is too ? sys: The entry fee is ? .
user: Does it have an entrance fee ? sys: Its entrance fee is ? .