Google recently open sourced a seq2seq project google seq2seq
tensorflow launched dynamic_rnn to replace the original bucket. This project is based on the seq2seq model of dynamic_rnn.
Here I have built some conversation predictions. Chinese corpus itself is relatively scarce. Theoretically, the more corpus, the better the model will be, but it will encounter many new problems, so I will not explain them here.
The dialogue materials are in Q.txt A.txt in the data directory and can be replaced with your own dialogue materials.
# 新增小黄鸡语料
# 添加
python prepare_dialog.py 5000
seq = Seq2seq()
# 训练
seq.train()
# 预测
seq.predict("天气")
# 重新训练
seq.retrain()
me > 天气
AI > 地点: 重庆
气温: 7
注意: 天气较凉,较易发生感冒,请适当增加衣服。体质较弱的朋友尤其应该注意防护。
This project has added Action support, and you can customize your own functions. Support for multiple rounds of sessions will be added later!
In the action.py file, register your own action tag and corresponding interface, such as:
# 注意:参数为固定参数
def act_weather(model, output_str, raw_input):
#TODO: Get weather by api
page = requests.get("http://wthrcdn.etouch.cn/weather_mini?city=重庆")
data = page.json()
temperature = data['data']['wendu']
notice = data['data']['ganmao']
outstrs = "地点: %sn气温: %sn注意: %s" % ("重庆", temperature.encode("utf-8"), notice.encode("utf-8"))
return outstrs
actions = {
"__Weather__":act_weather
}
Tips: The parameters of the interface are temporarily fixed and will be updated later.
At the same time, the training corpus is designed as follows:
# Q.txt
天气
# A.txt
__Weather__