Rasa NLU online and train version issue

309 views Asked by At

I read a book with title " Building Chatbots with Python: Using Natural Language Processing and Machine Learning" by Sumit Raj and follow the code that written there. And then I came to an example code how to train online the conversation, but then I found out that the code is deprecated. This is the code :

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
import logging
from rasa_core import utils, train
from rasa_core.training import online
from rasa_core.interpreter import NaturalLanguageInterpreter
logger = logging.getLogger(__name__)
def train_agent(interpreter):
    return train.train_dialog_model(domain_file="horoscope_domain.yml",
    stories_file="data/stories.md", output_path="models/dialog", nlu_model_path=interpreter, 
    endpoints="endpoints.yml", max_history=2, kwargs={"batch_size": 50,"epochs": 200, 
    "max_training_samples": 300 })

if __name__ == '__main__': 
    utils.configure_colored_logging(loglevel="DEBUG") 
    nlu_model_path = "./models/nlu/default/horoscopebot" interpreter = 
    NaturalLanguageInterpreter.create(nlu_model_path) agent = train_agent(interpreter)
    online.serve_agent(agent)

then the result is

ImportError: cannot import name ‘online’ from ‘rasa_core.training’

Please help me how the code looks like in the newest version. When I check I use rasa nlu 0.15.1 version.

Many thanks for your help.

1

There are 1 answers

0
Arjaan Buijk On

I highly recommend that you use the latest version, which is version 2.0.# at time of this answer.

Since the version you are using, Rasa has evolved from a python library to a python application and has a powerful command line interface.

You can now train your bot from the command line with the command:

rasa train

You can test the bot with the command:

rasa test

And you talk to the bot with the command:

rasa shell

If you do prefer to use Rasa as a library, you can find the way to train, test & chat in the using Rasa with Jupyter Notebook documentation.