Social Share

Complete On-Premise and Fully Customisable Chat Bot - Part 4 - Integrating the Natural Language Processor NLP

Welcome back Folks !!

In our part 3 we have seen how to communicate to the bot that we have built. Each and every people would talk the same thing in the different format and on his style. For each response if we start writing the code, Imagine how hard its gonna be.



What can we do for that ?

Natural Language Processor makes it easy to do. NLP is a component that identifies the user conversation and identifies the meaningful context from that.

What NLP is available ?

There are few NLP services like,
1. Dialog flow
2. Luie
3. IBM Voice etc.

But all these are the cloud services and we need to go internet for this. As we speaking about the on premise chat bot we will go for the RASA solution.

What is RASA ?

RASA is a Chatbot server and RASA NLU is the NLP server that comes handy and is built on the python tech stack. Its is a open source and backed by a strong community.

Lets get started with RASA ...

1. Installing the python environment : 

Since we know that the RASA is built on the python tech stack, we need to install the python. To install the python follow the below instructions,

Step 1: Open the respective page for the Operating system of your interest and follow the instruction and install the anaconda with python 3.x (contains most of the packages needed for the RASA)

  • Windows - https://conda.io/docs/user-guide/install/windows.html
  • MacOs - https://conda.io/docs/user-guide/install/macos.html
  • Linux - https://conda.io/docs/user-guide/install/linux.html
Step 2 : Test you Anaconda installation by using "conda list" in the command window.
Step 3 : Test your python using "python -V" command.
Step 4 : let's start installing the RASA NLU server. Open the command prompt and key in the following command 
                 
Step 5 :  RASA NLU used the SpaCy, MITE , SkLearn combinations to server the natural language processing. Most of the cases the combination of the SpaCy and Sklearn will work out. So to install the spacy.
                


Step 6 : Create a folder called "NLU" inside your bot project. < Revisit this post to see the directory structure >

Step 7: Our NLP processor is a model that learns the experiences from the past data and improves on the accuracy. So we need to provide the data that the user might have spoken for a particular intent of interest. So create the folder inside the NLU folder as data.

Step 8 : Following are the contents of the data folder, rasa_data.json file. The main components of the data file are as follows
Below one is the entire file created for a chinese restaurant use case
If you feel this process of editing the intents and entities are difficult. There is a handy tool at

  • online version : https://rasahq.github.io/rasa-nlu-trainer/
  • offline tool : https://github.com/RasaHQ/rasa-nlu-trainer
Just upload the file to the online / Offline version and add the intents and entities as shown in the picture below




Step 9: Now your are in the data directory of the RASA project. Come back a step (means to the root directory). Create the .json file and place the below contents.
Step 10:  Now it time to train the model with the data we created. Open the command window in the current directory and run this command "python -m rasa_nlu.train -c config_spacy.json"

Step 11: Once if the command completes successfully, you can see the projects folder getting created. At this point, invoke another command to run the HTTP server "python -m rasa_nlu.server -c config_spacy.json --server_model_dirs=<newly Created folder path>"

Tadaaaa !! the server is up and running. Using the postman hit the below url and see the magic.
http://localhost:3000/parse?q="Hello this is the user response".

The Nlu server should understand this and give you back the JSON object that have the predicted Intent Name. Use this in the chatbot to respond back to the user.


Comments

  1. This is really awesome. An excellent step by step guide. I am also looking to use the BotKit for integrating it with Microsoft Teams. Do you have something (blog/github sample) that i can follow?

    ReplyDelete
    Replies
    1. Thanks Anuj ! Right now I don't have blog for integrating the bot with Microsoft Teams ! I can take this as a topic to help on others. Integrating with Microsoft Teams is a good idea.

      Delete
  2. Hi Pranav
    That's a very nice piece of article for beginners like us, thanks for that.

    I was able to setup both Bot and NLU server, but the article I think did not cover the integration path between them. Please help us few steps how to integrate

    Thanks

    ReplyDelete
    Replies
    1. Thank you ! Just noted the missing of linking between the two. I will update this with RASA and BOTKIT linking

      Delete
  3. You have written that amazingly. One thing i want to know is how to embed code in blog posts like you have done here?

    ReplyDelete
    Replies
    1. Hi SpaCy with the help of git gist, we can embed the snippet in blogger

      Delete

Post a comment

Latest Technology Videos

Popular posts