a milk tea waiter chatbot for chinese, if you don't know rasa yet, refer to mini rasa tutorial
below
or read the rasa offical docs
you need to download bert_chinese_model and unzip it first: chinese_L-12_H-768_A-12
git clone https://github.com/BI4O/rasa_milktea_chatbot.git
cd rasa_milktea_chatbot
pip install -r requirements.txt -i https://pypi.tuan.tsinghua.edu.cn/simple
start bert server
bert-serving-start -model_dir path/to/chinese_L-12_H-768_A-12/ -num_worker=1
jump to milktea
cd milktea
start action server
rasa run actions
train a model
rasa train
talk to your chatbot
rasa shell
you can order 3 different products,more can be added to model yourself
and choose 3 sizes
- Create a new project
- View NLU training data
- Define model configuration and write the first story
- Define the scope domain of this story story
- Training model
- Test the helper you wrote
Path points to a new empty folder cd path/to/a/blank/folder
Create a new rasa project in this folder rasa init --no-prompt
The following files will be generated in the folder:
__init__.py | Empty file used for positioning |
---|---|
actions.py | Used to define actions (custom script code) |
config.yml | Configure NLU and core models |
credentials.yml | Details for connecting to other servers (not commonly used) |
data/nlu.md | My custom NLU training data |
data/stories.md | My custom stories stories |
domain.yml | The domain of the helper is domian |
endpoints.yml | Tracks connected to fb messages etc. (not commonly used) |
models/ | Model and its parameter files |
cat data/nlu.md
Displayed as follows
# # intent:order
- [奶茶](type)
- [咖啡](type)
- 我想要一杯[奶茶](type)
- 要杯[奶茶](type)
- 有[奶茶](type)吗
- 有[奶茶](type)卖吗
- 想要一杯[咖啡](type)
- 要杯[咖啡](type)
- 有[咖啡](type)吗
- 我想要一杯[卡布奇诺](type)
- 要杯[卡布奇诺](type)
- [卡布奇诺](type)
# # intent:inform_size
- [中](size)
- [中](size)的
- [中](size)杯
- [中](size)杯吧
- 要[中](size)杯
- [大](size)
- [大](size)的
- [大](size)杯
- [大](size)杯吧
- 要[大](size)杯
- [特大](size)
- [特大](size)的
- [特大](size)杯
- [特大](size)杯吧
- 要[特大](size)杯
Intent represents intent and needs to start with ## and end with a newline. For example, there are two intentions shown here: 1. Place an order, 2. Inform the specifications of milk tea. All the rhetoric that customers may use should be placed here, and used for the nlu model to learn how to understand what a person says.
[value](entity)
entity represents the entity, and value represents the specific value of the entity. After training, the nlu model can return variables similar to this to the core model: {"type":"奶茶","size":"大"}
, so that the core model can respond accordingly based on the two parameters type
and size
.
config.yml
will define the previous NLU module and the Core elements that your model will use. This time we use components written by experts. It is also highly recommended that everyone go to https://github.com/GaoQ1 /rasa_nlu_gqView written stories
cat data/stories.md
# # order naicha
- order{ " type " : "奶茶" }
- slot{ " type " : "奶茶" }
- utter_ask_size
- inform_size{ " size " : "大" }
- slot{ " size " : "大" }
- utter_affirm
- confirm
- action_charge
- utter_goodbye
The composition of the story
##
indicates the name of the story , a descriptive name##
*
represent user intent intent{"entity1": "value", "entity2": "value"}
-
beginning indicates the actions performed by the robot.User information
Action acitons
There are two types of actions
utter_xxx can directly return the words to be replied. You only need to explain it in domain.yml to use it.
action_xxx can perform the custom operations you want. In addition to being specified in domain.yml, it also needs to be added in the aciton.py file. For example, you want to have a custom action action_HelloWorld
First add this custom action to domain.yml under acitons
actions:
- aciton_HelloWorld
Then add new class in acitons.py file
class YourCustomAction ( Action ):
def name ( self ):
# 这个返回的值必须和stories.md和domain.yml中说明的一致
return "action_HelloWorld"
def run ( self , dispatcher , tracker , domain ):
# 定义这个动作要执行的你想要的操作
# 比如我想在对话中返回给用户的是HellowWorld!
dispatcher . utter_message ( 'HelloWorld!' )
return []
cat domain.yml
intents:
- greet:
triggers: utter_greet
- goodbye:
triggers: utter_goodbye
- confirm
- deny
- order
- thanks
- inform_size
- unknown_intent
actions:
- utter_greet
- utter_ask_order_what
- utter_ask_size
entities:
- type
- size
slots:
type:
type: text
size:
type: text
templates:
utter_greet:
- text: "你好"
utter_ask_order_what:
- text: "想要喝点什么? "
utter_ask_size:
- text: "想要什么规格的呢?我们有中/大/特大杯"
in
Because in this case, our action is just to send words to the user as a reply. These simple actions are all actions starting with utter_
. This kind of action requires the assistant to select a statement in the templates to reply. In fact, you can also define more For more actions see Custom Actions
Use the following command to automatically check the differences in domain/stories/NLU and retrain the model. The trained model will be time stamped as the new model rasa train
rasa shell