Tutorial: Rasa Basics

Tutorial: Rasa Basics

This page explains the basics of building an assistant with Rasa and shows the structure of a Rasa project. You can test it out right here without installing anything. You can also install Rasa and follow along in your command line.

The glossary contains an overview of the most common terms you’ll see in the Rasa documentation.

Steps to Create Your Assistant

  1. Create a New Project
  2. View Your NLU Training Data
  3. Define Your Model Configuration
  4. Write Your First Stories
  5. Define a Domain
  6. Train a Model
  7. Test Your Assistant
  8. Talk to Your Assistant

In this tutorial, you will build a simple, friendly assistant that will ask how you’re doing and send you a fun picture to cheer you up if you are sad.

1. Create a New Project

The first step is to create a new Rasa project. To do this, run:

rasa init --no-prompt

The rasa init command creates all the files that a Rasa project needs and trains a simple bot on some sample data. This creates the following files:

File Description
__init__.py An empty file that helps Python find your actions
actions.py Code for your custom actions
config.yml Configuration of your NLU and Core models
credentials.yml Details for connecting to other services
data/nlu.md Your NLU training data
data/stories.md Your stories
domain.yml Your assistant’s domain
endpoints.yml Details for connecting to channels like FB Messenger
models/<timestamp>.tar.gz Your initial model

2. View Your NLU Training Data

The first piece of a Rasa assistant is an NLU model. Run the code cell below to see the NLU training data created by the rasa init command:

cat data/nlu.md

The lines starting with ## define the names of your intents, which are groups of messages with the same meaning. Rasa's job will be to predict the correct intent when your users send new messages to your assistant.

3. Define Your Model Configuration

The configuration file defines the NLU and Core components that your model will use.

cat config.yml

The language and pipeline keys specify how the NLU model should be built.

4. Write Your First Stories

At this stage, you will teach your assistant how to respond to your messages.

Here’s an example of a simple conversation:

## story1
* greet
   - utter_greet

You can see the full details in Stories.

5. Define a Domain

The domain defines the universe your assistant lives in: what user inputs it should expect to get, what actions it should be able to predict, how to respond, and what information to store. The domain for our assistant is saved in a file called domain.yml:

cat domain.yml
Key Description
intents Things you expect users to say
actions Things your assistant can do and say
responses Response strings for the things your assistant can say

6. Train a Model

Anytime we add new NLU or Core data, or update the domain or configuration, we need to re-train a neural network on our example stories and NLU data.

rasa train

7. Test Your Assistant

After you train a model, you always want to check that your assistant still behaves as expected.

rasa test

8. Talk to Your Assistant

Congratulations! 🚀 You just built an assistant powered entirely by machine learning. The next step is to try it out!

rasa shell

Next Steps

Now that you’ve built your first Rasa bot, it’s time to learn about some more advanced Rasa features:

You can also use Rasa X to collect more conversations and improve your assistant:

Try Rasa X

👋 I can help you get started with Rasa and answer your technical questions.