Rasa Mechanism/Work Flow Explained! (An Extremely Simplified Unofficial Version)

Rasa Mechanism

Rasa has become a popular open source framework for building conversational AI in recent years. It is mainly composed of Rasa NLU (natural language understanding) and Rasa Core (mainly constructing conversations). Both can be used independently, but here we explore the combined usage in 4 steps.

1. Learning Language(s)

In the first step, we provide a large training corpus. Rasa transforms most of the words in text (such as WSJ news in the past 10 years) into vectors in multidimensional space through embedding techniques from machine learning (the dimensions are generally hundreds, Figure 1 shows the case of 2 dimensions). I take this step as establishing a sense of languages for Rasa.

Figure 1: A thumb up means more similar; A thumb down means less similar

2. Learning Intents

The second step is to provide Rasa with some NLU data. Intent represents a user’s intention of a sentence (such as "greet","goodbye","request_upstream_downstream","calculation","request_weather_information", etc.) Each intent requires 12-20 training sentences. The following figure shows several training sentences for the intent of searching for nearby restaurants.

Figure 2:Examples of training materials

Extracting specific information from users’ statements requires Rasa to identify entities. The highlights in Figure 2 are different entities. In simple terms, by manually labeling the entities in the sentence, when Rasa encounters a new sentence not in the training materials. For example, the user may state “I want a Mexican restaurant.” Rasa can infer that ‘Mexican’ is a type of cuisine through its sense of languages (similar words) as well as its sense of specific entities (“cuisine”). Of course, the inference may not be correct, mainly relying on training materials and NER (Named-entity Recognition) algorithms.

3. Learning Skills

The third step is to teaching Rasa various actions in a file called domain. Establishing a dialogue with Rasa on the basis of NLU requires knowing what to do after understanding the user’s semantics. Rasa’s reaction/action can be defined by templates (default strings as responses), actions (any python script), etc. If Rasa knows that the user means to “greet,” you can make it say ‘hi’, or make it look into your database according to entities extracted from users’ statements (such as 'Mexican ’ ~ ‘cuisine’).

Figure 3: Skills defined in the domain (these examples are all templates and ‘{}’ indicate variables extracted previous conversations)

4. Context-aware Conversations

The fourth step is to give Rasa conversations, called “stories,” to train Rasa’s conversational skills. The story combines the user’s semantics with Rasa’s corresponding response. Because people’s actual conversations can go in different directions according to the previous contexts, we can teach Rasa to deal with various situations through storytelling. Figure 4 trains Rasa to handle different user responses. Of course, we don’t need to provide a story for all possible scenes, Rasa can deal with unseen conversations by combining and recreating old stories.

Figure 4:One Example of Stories

At the same time, Rasa has many other convenient features, such as interactive learning (no need to write stories in advance), fallback (when the confidence of intent recognition is lower than a threshold you set, you can make it perform a default action such as using a seq2seq model). We can see that even though Rasa is an industry-leading open source technology, its functionality involves quite a lot of manual brainstorming and designing implementation. We look forward to the future of Rasa as the community keeps improving it.

This is an extremely simplified version as for how Rasa works under the hood. Any suggestions or feedback would be greatly appreciated!

About the author: http://zackLight.com
:+1: :sparkles: :camel: :rocket: :metal: :tada:

Image Sources

  1. Figure 1: https://www.zhihu.com/question/32275069/answer/109446135
  2. Other figures: rasa_core/examples/restaurantbot at master · RasaHQ/rasa_core · GitHub

Liability Statement

Please take this article with a grain and salt. I am not personally liable for the mistakes or future changes in the Rasa framework.


I also wrote a document that talks about the steps to take upon adding new intents or actions. Please let me know if anyone is interested, and I can post it. :slight_smile:

Please post your write-up also.

Hello, sorry about the delay. I found out that there are some changes in the latest version of Rasa that required some changes on my template and workflow.

Regardless, based on rasa-core==0.10.4, rasa-core-sdk==0.11.5, and rasa-nlu==0.13.4, my write up about updating functionalities is the README.md here:

1 Like