Skip to content

Commit

Permalink
fix dialogue bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
zqhZY committed Sep 8, 2018
1 parent 238edd5 commit 268a6a6
Show file tree
Hide file tree
Showing 15 changed files with 9,536 additions and 17 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ out/
tmp_training_data.json
.DS_Store
models/
projects/
test_models/model_*
test_projects/test_project_*

rasa_nlu/tmbo_test.py
.mypy_cache/
.mypy_cache/
26 changes: 12 additions & 14 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def run(self, dispatcher, tracker, domain):
dispatcher.utter_message("您好,您{}共消费二十八元。".format(time))
return []


'''
class MobilePolicy(KerasPolicy):
def model_architecture(self, num_features, num_actions, max_history_len):
"""Build a Keras model and return a compiled model."""
Expand All @@ -82,17 +82,17 @@ def model_architecture(self, num_features, num_actions, max_history_len):
logger.debug(model.summary())
return model

'''

def train_dialogue(domain_file="mobile_domain.yml",
model_path="models/dialogue",
model_path="projects/dialogue",
training_data_file="data/mobile_story.md"):
agent = Agent(domain_file,
policies=[MemoizationPolicy(), MobilePolicy()])
policies=[MemoizationPolicy(), KerasPolicy()])

training_data = agent.load_data(training_data_file)
agent.train(
training_data_file,
max_history=2,
training_data,
epochs=200,
batch_size=16,
augmentation_factor=50,
Expand All @@ -102,7 +102,6 @@ def train_dialogue(domain_file="mobile_domain.yml",
agent.persist(model_path)
return agent


def train_nlu():
from rasa_nlu.converters import load_data
from rasa_nlu.config import RasaNLUConfig
Expand All @@ -115,28 +114,27 @@ def train_nlu():

return model_directory


def run_ivrbot_online(input_channel=ConsoleInputChannel(),
interpreter=RasaNLUInterpreter("models/ivr/demo"),
interpreter=RasaNLUInterpreter("projects/ivr_nlu/demo"),
domain_file="mobile_domain.yml",
training_data_file="data/mobile_story.md"):
agent = Agent(domain_file,
policies=[MemoizationPolicy(), KerasPolicy()],
interpreter=interpreter)

agent.train_online(training_data_file,
training_data = agent.load_data(training_data_file)
agent.train_online(training_data,
input_channel=input_channel,
max_history=2,
batch_size=50,
batch_size=16,
epochs=200,
max_training_samples=300)

return agent


def run(serve_forever=True):
agent = Agent.load("models/dialogue",
interpreter=RasaNLUInterpreter("models/ivr/demo"))
agent = Agent.load("projects/dialogue",
interpreter=RasaNLUInterpreter("projects/ivr_nlu/demo"))

if serve_forever:
agent.handle_channel(ConsoleInputChannel())
Expand Down
35 changes: 35 additions & 0 deletions projects/dialogue/domain.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"states": [
"intent_greet",
"intent_confirm",
"intent_goodbye",
"intent_thanks",
"intent_inform_item",
"intent_inform_package",
"intent_inform_time",
"intent_request_management",
"intent_request_search",
"intent_deny",
"intent_inform_current_phone",
"intent_inform_other_phone",
"entity_item",
"entity_time",
"entity_phone_number",
"entity_price",
"slot_item_0",
"slot_phone_number_0",
"slot_price_0",
"slot_time_0",
"prev_action_listen",
"prev_action_restart",
"prev_utter_greet",
"prev_utter_goodbye",
"prev_utter_default",
"prev_utter_thanks",
"prev_utter_ask_morehelp",
"prev_utter_ask_time",
"prev_utter_ask_package",
"prev_utter_ack_management",
"prev_action_search_consume"
]
}
81 changes: 81 additions & 0 deletions projects/dialogue/domain.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
action_factory: null
action_names:
- utter_greet
- utter_goodbye
- utter_default
- utter_thanks
- utter_ask_morehelp
- utter_ask_time
- utter_ask_package
- utter_ack_management
- action_search_consume
actions:
- utter_greet
- utter_goodbye
- utter_default
- utter_thanks
- utter_ask_morehelp
- utter_ask_time
- utter_ask_package
- utter_ack_management
- bot.ActionSearchConsume
config:
store_entities_as_slots: true
entities:
- item
- time
- phone_number
- price
intents:
- greet
- confirm
- goodbye
- thanks
- inform_item
- inform_package
- inform_time
- request_management
- request_search
- deny
- inform_current_phone
- inform_other_phone
slots:
item:
initial_value: null
type: rasa_core.slots.TextSlot
phone_number:
initial_value: null
type: rasa_core.slots.TextSlot
price:
initial_value: null
type: rasa_core.slots.TextSlot
time:
initial_value: null
type: rasa_core.slots.TextSlot
templates:
utter_ack_management:
- text: 已经为您办理好了{item}
utter_ask_morehelp:
- text: 还有什么能帮您吗
- text: 您还想干什么
utter_ask_package:
- text: 我们现在支持办理流量套餐:套餐一:二十元包月三十兆;套餐二:四十元包月八十兆,请问您需要哪个?
- text: 我们有如下套餐供您选择:套餐一:二十元包月三十兆;套餐二:四十元包月八十兆,请问您需要哪个?
utter_ask_time:
- text: 你想查哪个时间段的
- text: 你想查几月份的
utter_default:
- text: 您说什么
- text: 您能再说一遍吗,我没听清
utter_goodbye:
- text: 再见,为您服务很开心
- text: Bye, 下次再见
utter_greet:
- text: 您好!,我是机器人小热,很高兴为您服务。
- text: 你好!,我是小热,可以帮您办理流量套餐,话费查询等业务。
- text: hi!,人家是小热,有什么可以帮您吗。
utter_thanks:
- text: 不用谢
- text: 我应该做的
- text: 您开心我就开心
topics: []
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"py/object": "rasa_core.featurizers.MaxHistoryTrackerFeaturizer", "max_history": 5, "remove_duplicates": true, "state_featurizer": {"py/object": "rasa_core.featurizers.SingleStateFeaturizer", "slot_feature_len": null, "user_feature_len": null}, "use_intent_probabilities": false}
Loading

0 comments on commit 268a6a6

Please sign in to comment.