Posts

Featured Post

advertisement

create a chatbot using python part 3

  Developing a Model Now that we have preprocessed all of our data we are ready to start creating and training a model. For our purposes we will use a fairly standard feed-forward neural network with two hidden layers. The goal of our network will be to look at a bag of words and give a class that they belong too (one of our tags from the JSON file). We will start by defining the architecture of our model. Keep in mind that you can mess with some of the numbers here and try to make an even better model! A lot of machine learning is trial an error. tensorflow . reset_default_graph () net = tflearn . input_data ( shape = [ None , len ( training [ 0 ])]) net = tflearn . fully_connected ( net , 8 ) net = tflearn . fully_connected ( net , 8 ) net = tflearn . fully_connected ( net , len ( output [ 0 ]), activation = "softmax" ) net = tflearn . regression ( net ) model = tflearn . DNN ( net ) Training & Saving the Model Now that we have setup our model its t...

create a chatbot using python part 4

Loading a Model In the last tutorial we set up and trained a model for our chatbot. Now preproccesing our data and training the model took a little bit of time, time that we don’t want to wait each time we want to use the model. So the first step of this tutorial is going to be changing some aspects of our code to load our model and data if it has already been created. Keep in mind that after doing this if you want to make changes to the model you will have to delete the saved model files or rename them. import nltk from nltk.stem.lancaster import LancasterStemmer stemmer = LancasterStemmer () import numpy import tflearn import tensorflow import random import json import pickle with open ( "intents.json" ) as file : data = json . load ( file ) try : with open ( "data.pickle" , "rb" ) as f : words , labels , training , output = pickle . load ( f ) except : words = [] labels = [] docs_x = [] doc...

Advertisement

ADVERTISEMENT