+2

Build a Machine Learning Application with TensorFlow: a chatBot

I've been fascinating on clever machine since I was at the university. Therefore, I do a little research about the awesomeness of machine learning, and I am thrilled to show you guy the result of what I found where we can use machine learning theory to make machine clever. So in this article, I am going to show you how can we use tensorflow(checkout my post to know why I choose tensorflow) to build a chatBot. However, I don't explain the code behind this machine because my purpose is for booting your motivation to research on machine learning.

What is chatBot?

A chatbot (also known as a talkbot, chatterbot, Bot, chatterbox, Artificial Conversational Entity) is a computer program which conducts a conversation via auditory or textual methods. source: Wiki

In short, a chatbot is computer artificial intelligence program which developed to simulate intelligent conversation through written or spoken text. It has been applied for a customer support service which respond to user question or request, and many more. Example: on Facebook, an admin of page can enable Bot for respond to their follower when they off line.

However, the Bot in this article we will use a conversation from movies for traning, so we can have some fun with it. So, let's get start:

The requirement

To be able to run the bot on your machine you need:

  • python2.7 or above
  • tensorflow==0.12.0
  • numpy For serve to web
  • click==6.6
  • Flask==0.11.1
  • itsdangerous==0.24
  • Jinja2==2.8
  • MarkupSafe==0.23
  • Werkzeug==0.11.10

And you need to have some knowledge of python language. If you cannot install tensorflow, please checkout my previous post Set up tensorflow

Download source code

you can download the code for be able to run the bot on your local from the original source: tensorflow_chatbot, or you can clone the code from my repo chatBot.

Let train our machine

We need to prepare our data before can train to our machine by run this comman:

# go into data directory
cd data
# execute python comman
python prepare_data.py

To train the bot, edit the seq2seq.ini file so that mode is set to train like so

mode = train

then run this command

python execute.py

Then you need to wait for bot to be train. It took 32h for me to train my bot to get result like picture above. Since it has a check point so you can terminate and continue training later on. Be aware that while train our machine will need a lot of CPU capicity. Therefore, your PC might be slovewhen you try to use other application while training, so you run it at night when you sleep.

Let test our bot

After you spen some hours to train our Bot now it time to test our machine. To test the bot, edit the seq2seq.ini file so that mode is set to test like so

mode = test

then run this command

python execute.py

And then you will see console for you to input a text.

Test our bot on web

Now, let test our bot on web. To demo this Bot, I am going to use python to server a json to my rails application. By start python server with comman:

python server/app.py

and you will see Then we can access to python web UI via: http://127.0.0.1:5000/ or we can start our rails app:

cd railsApp
rails s

And access to our web via: http://127.0.0.1:3000/ Then you can play around like this:

Resouces

What next?

I hope this article will boot your motivation to start or continue researching on machine learning field by giving an example to you guy how awesome thing could be build with machine learning. However, I didn't describe any code behind the scene to build this Bot yet. So the next articles, I will writea machine learning serial where I will start from the very basic level. And I hope one day we could build awesome machine learning APPs.


All rights reserved

Viblo
Hãy đăng ký một tài khoản Viblo để nhận được nhiều bài viết thú vị hơn.
Đăng kí