当前位置:网站首页>Rasa Chat Robot Tutorial (translation) (1)

Rasa Chat Robot Tutorial (translation) (1)

2022-07-05 12:39:00 NLP journey

brief introduction

rasa Is an open source dialogue robot . Mainly for task-based dialogue robots , Open source code :
Tutorial address :https://rasa.com/docs/rasa/
github Address :https://github.com/RasaHQ/rasa

An example

The tutorial provides an interactive example of getting started rasa Basic concepts of .

Create assistant

This example creates a chat assistant that helps users subscribe to news , Follow these steps to learn how a simple helper is created :

  1. NLU data
    No matter how the user expresses , In order for the machine to understand what the user said , Some message samples that the machine can learn must be provided . Group these samples according to the intention of the message . In the following example , Added “greet" The intent of the , The messages included in this intention are :“hi",“Hey”,"good morning" etc. .
nlu:
- intent: great
	examples:|
		- Hi
		-  Hey!
		- Hallo
		- Good day
		- Good morning
-  intent: subscribe
	example:|
		- I want to get the newsletter
		- can you send me the newsletter?
		- can you sign me up for the newsletter?

- intent: inform
  example:|
  	-My email is  [email protected]
  	[email protected]
  	- please send it to [email protected]

Intentions and their examples are used as training data for robot language understanding module .

  1. Response
    Through the language understanding part , The machine understands the purpose of user expression . Then it needs to reply to the user . Here are some examples of responses , If a reply corresponds to multiple texts , These texts will be randomly selected as reply content .
responses:
   utter_greet:
       - text: |
           Hello! How can I help you?
       - text: |
           Hi!
   utter_ask_email:
       - text: |
           What is your email address?
   utter_subscribed:
       - text: |
           Check your inbox at {email} in order to finish subscribing to the newsletter!
       - text: |
           You're all set! Check your inbox at {email} to confirm your subscription.

stories

stories Is an example of a conversation , It is used to train robots to make corresponding replies based on the user's dialog content . Its format is the user's intention , Then there is the reply of the machine or the action that should be taken .
The first story should be a direct process for robots to help users achieve their goals . then , You can add stories that users do not provide information or turn to other topics . In the following example , Added a user to exchange greetings with the robot , The story of a user making a subscription request and then a machine requesting user information .

stories:
 - story: greet and subscribe
   steps:
   - intent: greet
   - action: utter_greet
   - intent: subscribe
   - action: newsletter_form
   - active_loop: newsletter_form

Forms

In many cases, machines need to collect user information , For example, users subscribe to news , You need to know the user's email . stay Rasa Inside , Collect information and use forms to complete . The following example shows a form for collecting user mailboxes .

slots:
  email:
    type: text
    mappings:
    - type: from_text
      conditions:
      - active_loop: newsletter_form
        requested_slot: email
forms:
  newsletter_form:
    required_slots:
    - email

Rules

Rules Defined some fixed rules , For some purposes , Use rules to define the machine's fixed response to these intentions . For example, in the following example , The first rule defines when identifying users is subscribe When the intention of , Adopt startup newsletter_form act . The second rule is only in newsletter_form It will not start until it is started , When active loop The state is no longer active , Even if the form is completed .

rules:
 - rule: activate subscribe form
   steps:
   - intent: subscribe
   - action: newsletter_form
   - active_loop: newsletter_form

 - rule: submit form
   condition:
   - active_loop: newsletter_form
   steps:
   - action: newsletter_form
   - active_loop: null
   - action: utter_subscribed

Train and talk to your assistant

With the data above , You can train the model . The original text provides an exchange meeting for training , You can train the model by pressing the training button , After training, you can also talk directly .

You can follow the examples provided in the tutorial , Modify the code , Adapt to a new task .

You have built an assistant , What's next ?

After training the model , You can verify whether the robot meets your requirements through dialogue . But for complex tasks , Manual testing is inefficient .rase Provides a method of automated testing , Build for testing stories, And then execute rasa test You can automate the test . The test of stories Long bottom like this :

stories:
- story: test for greet and subscribe
  steps:
  - user: |
     Hello there
    intent: greet
  - action: utter_greet
  - user: |
     I want to subscribe to the newsletter. My email is [email protected]
    intent: subscribe
  - action:  utter_subscribed

summary

Just like program language hello world equally , This part introduces rasa One of the robots hello world Program . Know how to use rasa Data and components to be provided : For training language understanding module NLU data , It is used for the machine to generate a corresponding reply to the user's intention Response data , For dialogue process Stories data , Components that collect user information and what robots must abide by Rules Set up . Last , It also introduces the of automated testing rasa test command .

原网站

版权声明
本文为[NLP journey]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202140526387396.html