Artificial Intelligence | Chatbot

ChatBot

Chat bot is a self-learned Artificial Intelligence based bot which uses the machine learning and guess the input meaning by user and answer to the user after understanding.

Language: Python

APIs: TensorFlow, tflearn, nltk, random

 

Here, we used the language Python to apply Machine learning concepts. The very famous package of python is tensorflow which is commonly used to implement these concepts while the tflearn API of tensorflow has also been used to implement the deep learning concepts.

 

Futhermore we provided the training data to the model of chatbot and trained it by providing different inputs.

In addition Chabot will be trained by the inputs and will return the responses after each input.

 

 

Importing Libraries:

# things we need for NLP

import nltk

from nltk.stem.lancaster import LancasterStemmer

stemmer = LancasterStemmer()

 

# things we need for Tensorflow

import numpy as np

import tflearn

import tensorflow as tf

import random

 

Creating Model & Saving:

# reset underlying graph data

tf.reset_default_graph()

# Build neural network

net = tflearn.input_data(shape=[None, len(train_x[0])])

net = tflearn.fully_connected(net, 8)

net = tflearn.fully_connected(net, 8)

net = tflearn.fully_connected(net, len(train_y[0]), activation=’softmax’)

net = tflearn.regression(net)

 

# Define model and setup tensorboard

model = tflearn.DNN(net, tensorboard_dir=’tflearn_logs’)

# Start training (apply gradient descent algorithm)

model.fit(train_x, train_y, n_epoch=1000, batch_size=8, show_metric=True)

model.save(‘model.tflearn’)

 

Loading Saved Data:

 

# load our saved model

model.load(‘./model.tflearn’)

 

Using The Neural Network of 3 hidden Layers:

 

net = tflearn.input_data(shape=[None, len(train_x[0])])

net = tflearn.fully_connected(net, 8)

net = tflearn.fully_connected(net, 8)

net = tflearn.fully_connected(net, len(train_y[0]), activation=’softmax’)

net = tflearn.regression(net)

 

 

Add a Comment

Your email address will not be published. Required fields are marked *