Understanding the Basics of Rasa - Open source conversational AI
Rasa Open Source is a machine learning framework to automate text and voice-based assistants.
Building contextual assistants & chat bots that really help customers is hard. Rasa provides infrastructure & tools necessary for high-performing, resilient, proprietary contextual assistants that work. With Rasa, all developers can create better text- and voice-based assistants.
Why Rasa?
The main advantage of RASA NLU over those stacks is that you have access to the entire Python processing pipeline and can extend it with your complex custom logic. RASA NLU offers infrastructure capabilities such as model persistence or HTTP access that are required on conversational solutions in the real world.
Who use Rasa NLU?
Rasa | Dialogflow |
---|---|
Requires installation of multiple components | No installation, get started immediately |
Requires technical knowledge | Easy to use, non-techies can also build bots |
Open-source, code available in GitHub | Closed system |
No interface provided, write JSON or markdown files | Web-based interface for building bots |
No hosting provided (at least in the free version) | Data is hosted on the cloud |
Host it on your server | Can’t be hosted on your servers or on-premise |
No out of box integration | Out of box integration with Google Assistant, Slack, Messenger, Skype etc |
Image Source: Spaceo
Cons of Rasa
- Although for low traffic volumes, the service is free, if the volumes increase, you need to move to a paid plan.
- Rasa isn’t for beginners. You need a prior knowledge in chat-bot and NLP.
- Fine control over dialogue processing will not be available to the programmer.
- spaCy is one of Rasa’s default pipelines for processing user inputs, uses a lot of computer memory. Depending on the server configuration, spaCy could slow down other processes.
Image Source: SlideShare
Elements of RASA:
- Natural Language Understanding (NLU)
- Natural Language Generation (NLG)
- Dialogue Management
1. Natural Language Understanding (NLU)
Rasa NLU is a kind of natural language understanding module. It comprises loosely coupled modules combining a number of natural language processing and machine learning libraries in a consistent API.
What NLU actually do?
- Convert text to Vectors and classify the intent.
- Extraction of entities (If any)
For this process NLU convert the incoming text to tokens using Tokenizer and then
Part of speech tagger: A part-of-speech tagger, or POS-tagger, processes a sequence of words, and attaches a part of speech tag to each word.
Chunker: One of the main goals of chunking is to group into what are known as "noun phrases." These are phrases of one or more words that contain a noun, maybe some descriptive words, maybe a verb, and maybe something like an adverb. The idea is to group nouns with the words that are in relation to them
After chunker the entity is recognized and extracted.
2. Natural Language Generation (NLG)
Natural Language Generation is a subdivision of Artificial Intelligence that aims to reduce communicative gaps between machines and humans. The technology, typically accepts input in non-linguistic format and turn it into human understandable formats like reports, documents, text messages etc.
3. Dialogue Management
Why Dialogue Handling with Rasa Core?
• No more state machines! • Reinforcement Learning: too much data. reward functions_. • Need a simple solution for everyone
How it works?
By extracting intent and entities from input text, those data are mess up with the previous state to get the new action. Those new actions are updated to the state and produce the output as well as used for next input.
How to Install Rasa:
Prerequisites:
- Python 3
- Visual studio 14.0.0+ (not VS Code)
Install rasa using pip (If you don't have pip installed follow this blog to install it)
pip install rasa
Once it got installed, rasa CLI is enabled.
Init Project using
rasa init
Inside your project folder (Empty folder), command prompt
It will ask the following questions,
- Please enter a path where the project will be created [default: current directory]- Specify path or press enter for default
- Do you want to train an initial model?- For beginners, yes(recommended), It takes some time to train the model.
- Do you want to speak to the trained assistant on the command line?- No(Recommended), If you want to see how rasa chatbot work, you can press yes.
If you want to skip these question, add — no-prompt
rasa init --no-prompt
By this process, some files are created in your specified directory, which is explained in upcoming blogs.
This creates the following files:
- init.py: This is an empty python file that helps to find your actions.
- actions.py: You can customize your action code in this python file.
- config.yml (*): This file is used for the configuration of your NLU and Core models. This file has enough details like language, pipeline, epochs detail of NLU, and protocols for cores.
- credentials.yml: This has the details for connecting to other services. This contains the credential details.
- data/nlu.md (*): This file contain the intent name and intent for the NLU, you start writing intent from here.
- data/stories.md (*): This file contains the story of your bot. This is the bridge between intent and the response
- domain.yml (*): This contains the intent list, response, action, slots, and form list. This is the domain of your bot.
- endpoints.yml: This file have the details for connecting to channels like FB messenger.
- models/
.tar.gz: This is the model trained by rasa. - (optional) data/responses.md(*): You can create a response file separately in the data folder.
The most important files are marked with a ‘*’.
Train and Review bot:
After you create your own bot, you have to train it, by the following code
rasa train
It will create a new model in the models folder. And you can test it in two different ways:
- Using shell
rasa shell
This will create an interface to chat with your bot.
- Using postman/curl
First, run the following command
rasa run -m models --enable-api --log-file out.log
which create localhost in which you can interact using curl
curl localhost:5005/model/parse -d '{"text":"hello"}
List of other API's provided
route | METHOD | Usage |
---|---|---|
/conversations/ |
POST | add_message |
/conversations/ |
POST | append_events |
/webhooks/rest | GET | custom_webhook_RestInput.health |
/webhooks/rest/webhook | POST | custom_webhook_RestInput.receive |
/model/test/intents | POST | evaluate_intents |
/model/test/stories | POST | evaluate_stories |
/conversations/ |
POST | execute_action |
/domain | GET | get_domain |
/ | GET | hello |
/model | PUT | load_model |
/model/parse | POST | parse |
/conversations/ |
POST | predict |
/conversations/ |
PUT | replace_events |
/conversations/ |
GET | retrieve_story |
/conversations/ |
GET | retrieve_tracker |
/status | GET | status |
/model/predict | POST | tracker_predict |
/model/train | POST | train |
/conversations/ |
POST | trigger_intent |
/model | DELETE | unload_model |
/version | GET | version |
In this topic, we came across
- What is Rasa
- Pros and Cons
- Elements of Rasa
- How to install it
- What are the files it contains and how to test it
Next Article : Architecture and creating a bot using Rasa