Training Data Importers

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.1

Warning

This document is for an old version of Rasa. The latest version is 1.10.26.

Training Data Importers

By default, you can use command line arguments to specify where Rasa should look for training data on your disk. Rasa then loads any potential training files and uses them to train your assistant.

If needed, you can also customize how Rasa imports training data. Potential use cases for this might be:

You can instruct Rasa to load and use your custom importer by adding the section importers to the Rasa configuration file and specifying the importer with its full class path:

importers:
- name: "module.CustomImporter"
  parameter1: "value"
  parameter2: "value2"
- name: "module.AnotherCustomImporter"

The name key is used to determine which importer should be loaded. Any extra parameters are passed as constructor arguments to the loaded importer.

You can specify multiple importers. Rasa will automatically merge their results.

RasaFileImporter (default)

By default Rasa uses the importer RasaFileImporter. If you want to use it on its own, you don’t have to specify anything in your configuration file. If you want to use it together with other importers, add it to your configuration file:

importers:
- name: "RasaFileImporter"

MultiProjectImporter (experimental)

Warning: This feature is currently experimental and might change or be removed in the future.

With this importer you can build a contextual AI assistant by combining multiple reusable Rasa projects.

An example directory structure could look like this:

.
├── config.yml
└── projects
    ├── GreetBot
    │   ├── data
    │   │   ├── nlu.md
    │   │   └── stories.md
    │   └── domain.yml
    └── ChitchatBot
        ├── config.yml
        ├── data
        │   ├── nlu.md
        │   └── stories.md
        └── domain.yml

In this example the contextual AI assistant imports the ChitchatBot project which in turn imports the GreetBot project.

Rasa uses relative paths from the referencing configuration file to import projects. During the training process Rasa will import all required training files, combine them, and train a unified AI assistant.

Writing a Custom Importer

If you are writing a custom importer, this importer has to implement the interface of TrainingDataImporter:

from typing import Optional, Text, Dict, List, Union

import rasa
from rasa.core.domain import Domain
from rasa.core.interpreter import RegexInterpreter, NaturalLanguageInterpreter
from rasa.core.training.structures import StoryGraph
from rasa.importers.importer import TrainingDataImporter
from rasa.nlu.training_data import TrainingData

class MyImporter(TrainingDataImporter):
    """Example implementation of a custom importer component."""
    def __init__(self,...):
        pass
    async def get_domain(self) -> Domain:
        pass
    def get_stories(self,...):
        pass
    async def get_config(self) -> Dict:
        pass
    async def get_nlu_data(self, language: Optional[Text] = "en") -> TrainingData:
        pass

TrainingDataImporter class

Common interface for different mechanisms to load training data.