5.0 / 5
We will cover the following tasks in 52 minutes:
We will understand the Rhyme interface and our learning environment. You will get a virtual machine, you will need Jupyter Notebook and TensorFlow for this course and both of these are already installed on your virtual machine. Jupyter Notebooks are very popular with Data Science and Machine Learning Engineers as one can write code in cells and use other cells for documentation.
Importing Tensorflow and Dataset
We are going to use the IMDB movie reviews from the Internet Movie Database as our dataset. These are split into 25k for training and 25k reviews for testing. The
testing sets consists of equal numbers of positive and negative reviews. This dataset comes packaged with Keras and a bulk of pre-processing that is typically required is already done on this pre-packaged dataset. The dataset is pre-processed where each example is an array of integers representing the words of the movie review. Each label is an integer value of either
0 (negative sentiment) or
1 (positive sentiment).
Preparing the Data
Before feeding into a Neural Network model, we need to convert our examples (the reviews) into tensors. A tensor is a generalization of vectors and matrices to potentially higher dimensions and has a shape and a base data type. We will need our example with the same shape and data type before we feed them into the model. We can do this by padding the arrays so they all have same lengths. We can find the example with max length and pad every other example by additional values so that all examples are of same length.
Building the Model
The model will consist of an input layer, an output layer and two hidden layers. The first layer is an embedding layer takes the integer-encoded vocabulary and looks up the embedding vector for each word-index. These vectors are learned as the model trains. A
GlobalAveragePooling1D layer will then average the embeddings of all the words. The last layer is densely connected with a single output node. Using the sigmoid activation function, this value is a float between 0 and 1, representing a probability, or confidence level of the model.
Training the Model
We will use the
fit method on our model to train the model. We will set epochs to 40 so that there are 40 iterations over all samples in the training data. While training, we will monitor the model’s loss and accuracy on our validation set. We will use a batch size of 512 samples.
Accuracy and Loss Plots
evaluate method on our model will return loss and accuracy given a dataset. The
model.fit() method returns a
History object that contains a dictionary with everything that happened during training. We will use this dictionary to plot our model’s loss and accuracy for both the training set and validation set. This will help us understand the training process better.
About the Host (Amit)
I am a Software Engineer with many years of experience in writing commercial software. My current areas of interest include computer vision and sequence modelling for automated signal processing using deep learning as well as developing chatbots.