hello everyone, welcome to the semicolon
in this tutorial we're going to continue
to build up our chatbot. in the last video
we have pre-processed the data to keep it in
the form of question and answers. our
question was a vector of length 15 and
each word in those 15 words was of
length three hundred, and that is what we
are going to input here into our lstm
model so let's get started. i am using
all these libraries Keras dot models of
sequential, gensim, layeres dot recurrent and
test train split to perform the function
and then from the conversation pickle
the file which we have saved I am loading
this vec_x and vec_y and required and now we're
going to transform it to numpy array.
and as you can see our array is 86
sentences each of length 15 because each
sentence was composed of 15 words and
each word was of length 300 now this is
our input and this is our output. so now
we're going to do test train split to test
our accuracy but it doesn't matter
because it's just words. now we're going
to implement our lstm which, which is
going to have four layers so our lstm
will have output dimension of 300,
because 300 is the, 300 is the length of
the word so each word will be 300 our
input shape will be 15 cross 300 because
one sentence is going to be 15 plus 300
and return sequences to be true because
we need 15 of these, 15 output dimensions
of 300 length and then we initialize it
with glorot_normal and the inner
initialization is also
this, activation is sigmoid in every case.
so we compile this, and our loss is
cosine proximity because, the word to vec
uses cosine proximity as the model of
similarity between to words or the
distance between to words. so I thought
this would give a very good measure of
error when we consider this. so let's run
it and it will take some time and then
I'm going to fit it in steps of 500. so I
start the training but I've already
trained and saved the models as well. so I
will start the training and you can look
at the training and realize it's too
slow and that is why I've done it
already. and as you can see the training
for this has started and it is going on
but I don't want to get into it because
i have already trained on a fastest
computers and saved all these models and
i have these files which i will be
uploading on my github you can download
it from there and test it on your laptop
with the same code and, test the accuracy.
so for now we will be using our chat
program to measure or to judge how
good our chatbot is. so let me stop the
execution here itself and we will be going
to a chat program. so our chat program is
like this. I am importing Keras dot
load model to load this model of mine
and this might take some time. so yes we
don't need anything for now. then what I
am doing is ,I am displaying enter the
message here then I am tokenizing all
the words of the message by doing this,
x dot lower and then tokenize it and
then for every word i am finding the
word vector for it and preparing
it in
the same way as we had prepared our input
data in the last tutorial. so what we
have here is a vector of 14 words, a
vector of a vector of size 15 which has
word vectors, so we have a vector of word
vectors of 15 word vectors. so what I'm
doing is after 14 I am flipping the
sentence. I don't care whatever it is I'm
losing some information but my chatbot
is designed to handle 15 words only. so
don't use long sentences because it
might get my chat bot confused. now if
the length is less than 15 I am a
pending sentend which is, all ones at the
end of the sentences. so to get a uniform
output. now what I'm doing is I'm
predicting the model by using model
dot predict I am predicting the output of
the input and then using the word to
vec function more similar I am finding
the most similar word for each word here.
I am finding the most similar word for
each word vector in a sentence and then,
I'm printing the sentence output, so
let's check how our model works
out. so I'm going to run this and it's
asking enter the message I would like to
expand this so that you can see. so I
write here hi and okay I haven't loaded
this so this might take some more time.
hopefully it won't but let's wait for it
again and then run this part once more.
so that got executed and then it's again
asking enter the message and I press hi
so let's wait for it to reply it might
take one or two seconds but it should be
done pretty quick because it's just
prediction. and it is making us wait so
the output is how are you doing. so this
is a chat bot which
we have trained on just the sentences
which I had shown you before,and these
are padding words because we added 1111
to the end of the sentence. so let's
write how are you. so it said i am doing
a so can, which doesn't make much
sense but it is pretty good because the
chatbot was just trained on 68 words
or 86 words. so I am sorry 86 sentences
so this is pretty good accuracy and
these are again the padding words. so this
some other things which we can try like
how are you doing. I am doing fine,
let's see what it gives. know m also good.
with more training and more iterations I
think we can always improve the accuracy
and this is it, this is our chatbot which
works and which gives I say a good input
so this is it for our chatbot guys hit
the like button if you liked it, hit the
subscribe button if you want to keep
watching more of these and share it with
your friends thank you.