Jupyter Notebooks

These docs are for version 1.x of Rasa Open Source.

User Guide

NLU

Core

Conversation Design

API Reference

Migrate from (beta)

Reference

Versions

viewing: 1.10.24

Jupyter Notebooks

This page contains the most important methods for using Rasa in a Jupyter notebook.

Running asynchronous Rasa code in Jupyter Notebooks requires an extra requirement, since Jupyter Notebooks already run on event loops. Install this requirement in the command line before launching jupyter:

pip install nest_asyncio

Then in the first cell of your notebook, include:

import nest_asyncio
nest_asyncio.apply()
print("Event loop ready.")

To create a project if you don’t already have one, run:

from rasa.cli.scaffold import create_initial_project
import os
project = "test-project"
create_initial_project(project)
os.chdir(project)
print(os.listdir("."))

To train a model, define the following variables:

config = "config.yml"
training_files = "data/"
domain = "domain.yml"
output = "models/"
print(config, training_files, domain, output)

Train a Model

Now we can train a model by passing in the paths to the rasa.train function:

import rasa
model_path = rasa.train(domain, config, [training_files], output)
print(model_path)

Chat with your assistant

To start chatting with an assistant:

from rasa.jupyter import chat
chat(model_path)

Evaluate your model against test data

Use the convenience function:

import rasa.data as data
stories_directory, nlu_data_directory = data.get_core_nlu_directories(training_files)
print(stories_directory, nlu_data_directory)

To test your model:

rasa.test(model_path, stories_directory, nlu_data_directory)
print("Done testing.")

The results will be written to a file called results. NLU errors will be reported to errors.json:

if os.path.isfile("errors.json"):
    print("NLU Errors:")
    print(open("errors.json").read())
else:
    print("No NLU errors.")

if os.path.isdir("results"):
    print("Core Errors:")
    print(open("results/failed_stories.md").read())