Introduction

A chatbot is a software application used to conduct an on-line chat conversation via text . In this blog post, I will show how to create a Simple Chatbot with tensorflow 2 for your organization.

Dataset Preparation

once, the dataset is built . half the work is already done. the way we structure the dataset is the main thing in chatbot. I have used a JSON file to create a the dataset.

JSON files are just like dictionaries in python. you can store in json files just like you do in dictionaries in python



Input: These are exactly the messages that the user is going to be sending to the bot.

tags : tags are used to categorise the inputs and map them to a particular type of response

responses : once, we have mapped an input to an appropriate tag, we can select one of the response to give back to the user.

This basically how the dataset is structured for the chatbot.

Machine Learning Part :

1.Importing the Libraries


2.Importing the Data


Output
The data is stored in a json file, which can be imported and used as a pandas dataframe. This data was manually created by me. hence, it’s not that big.
we all know that deep learning requires large chunks of data. but, That is not the case here. I have utilized a neural network architecture powerful enough to handle this small amount of data

3.Pre-Processing the data



Tensorflow’s tokenizer assigns a unique token to each distinct word. and padding is done to get all the data to the same length so as to send it to an RNN layer. target variables are also encoded to decimal values.

4.Input Length, Output Length and Vocabulary



input length and output length are obvious. they are for the input shape and output shape of the neural network. vocabulary size is for the embedding layer to create unique vector representations for each word.

5. Neural Network



The Network consist of an embedding layer which is one of the most powerful things in the field of natural language processing. the outputs of the embedding layer is the input of the reccurent layer with lstm gate. then, the output is flattened and a regular dense layer is used with a softmax activation function.
The main part is the embedding layer which gives has a corresponding vector for each word in the dataset


6. Model Analysis

The model got a perfect accuracy of 100%.

7. Testing



Output


Conclusion

So, This is the Chatbot that I have created with tensorflow2 utilizing the power of embedding matrix. This same method can be used to build chatbots for any type of organization but not a generalized one.