Essence of RASA NLU

Shubham Deshmukh
Analytics Vidhya
Published in
4 min readSep 20, 2019

What is Rasa NLU?

Rasa is Open source conversational AI tool. NLU in Rasa stands for Natural Language Understanding. Confused between NLP and NLU ? Well NLP stands for Natural Language Processing while NLU is short from of Natural Language Understanding. Both share a common goal of understanding the interaction between natural language(e.g English) and computer language. Rasa NLU is Natural Language Processing tool for intent classification, response retrieval, entity extraction and many more. It is specially used to identify sentiments, conversational chatbots, Named-Entity Recognition and identifying the purpose of sentence (intent).

Objective

In this article, we are going to build an intent classification model which will understand user provided intents and classify sentences accordingly. Rasa pipeline is mainly developed for chatbot understanding but here we are tweaking it to get the desired result.

Prerequisites and dependencies

  • Python 3.5
  • Rasa_nlu -0.15.0
  • Rasa_core -0.14.4
  • Visual C++ Build Tools
  • Node.js
  • Tensorflow -1.13.1

We will use tensorflow pipeline provided by Rasa.

Link- https://github.com/RasaHQ/tutorial-tf-pipeline

Anatomy of Tensorflow Pipeline

  1. data/nlu.md: Your NLU training data
  2. data/stories.md: Your stories
  3. domain.yml: Your assistant’s domain
  4. Readme.md: Instruction file
  5. config.yml: Configuration of your NLU and Core models

config.yml includes following components:

Pipeline

Structural outline of the pipeline

Intent Schema

Create/Edit the markdown file(data/nlu_data.md) and provide samples accordingly. I have given four different intent with their samples.

## intent: Inquiry

- Hey, I want to know the price range of washing machines available at your store.
- Do I need to register on your website for more details?
- What is the launch date of your xyz product.
- Good morning can we you please update the case no as completed.
- Is there any progress on my current product?

## intent: Suggestion

- Improve the led screen lights.
- Delivery team should keep track of customers they are delivering.
- Customers should get the message within 2–3 days of order not 5–7 days.
- Warranty period should be increased from 12 month to 18 months.
- Debit/credit cards offers can be made available to all.

## intent: Satisfaction

- The service was nice and i loved it.
- Good performance by the delivery team. My flat was on top floor.
- Fab product. I am enjoying it.
- Thank you very much for fast delivery.
- Great efforts. I issue got resolved within two days.

## intent: Problems

- Product not delivered.It’s frustrating.
- Delivery team not receiving the call. How unprofessional.
- Product has dent on it. I informed but no reply. Cheap service.
- Not happy with the process. It’s too lengthy and tedious.
- Product is missing from the cart. I added to cart few hours ago. It’s annoying.

It’s time for training

python -m rasa_nlu_train -c config.yml — data data/nlu_data.md -o models — fixed_model_name nlu_model — project current — verbose
Training verbose
Training process
Training completed

Testing the classifier

We will pass new sample to our parser to test our accuracy. Intent Classifier generates intent with there confidence level.

interpreter.parse("I don't like you product. take it back its cheap")

{'intent': {'name': 'Problems', 'confidence': 0.7875019907951355},
'entities': [],
'intent_ranking': [{'name': 'Problems', 'confidence': 0.7875019907951355},
{'name': 'Satisfaction', 'confidence': 0.3987600803375244},
{'name': 'Inquiry', 'confidence': 0.0548376739025116},
{'name': 'Suggestion', 'confidence': 0.0}],
'text': "I don't like you product. take it back its cheap"}

interpreter.parse("I really like your product. It's nice and elegant")

{'intent': {'name': 'Satisfaction', 'confidence': 0.7504403591156006},
'entities': [],
'intent_ranking': [{'name': 'Satisfaction', 'confidence': 0.7504403591156006},
{'name': 'Inquiry', 'confidence': 0.43102625012397766},
{'name': 'Problems', 'confidence': 0.29785239696502686},
{'name': 'Suggestion', 'confidence': 0.0}],
'text': "I really like your product. It's nice and elegant"}

interpreter.parse("What is the date of  delivery?")

{'intent': {'name': 'Inquiry', 'confidence': 0.8536046743392944},
'entities': [],
'intent_ranking': [{'name': 'Inquiry', 'confidence': 0.8536046743392944},
{'name': 'Problems', 'confidence': 0.2455110251903534},
{'name': 'Satisfaction', 'confidence': 0.16995489597320557},
{'name': 'Suggestion', 'confidence': 0.04869852960109711}],
'text': 'What is the date of delivery?'}

interpreter.parse("Try to improve service offerings")

{'intent': {'name': 'Suggestion', 'confidence': 0.6914837956428528},
'entities': [],
'intent_ranking': [{'name': 'Suggestion', 'confidence': 0.6914837956428528},
{'name': 'Inquiry', 'confidence': 0.3903597593307495},
{'name': 'Problems', 'confidence': 0.2396610677242279},
{'name': 'Satisfaction', 'confidence': 0.038475312292575836}],
'text': 'Try to improve service offerings'}

I really hope that you liked my little exploration into how to implement a simple intent classifier using Rasa’s tensorflow pipeline. Check out this link for code.

If you have any questions, please contact the author at shubhamdeshmukh@yahoo.in. If you are passionate about Data Science/Machine Learning, please feel free to add me on LinkedIn.

--

--