So in this lecture, we'll be looking at the notebook to do text classification using a CNN.
We'll begin by downloading our dataset, which will be the BBC News data once again.
But note that at this point in the course, you learn the skills to plug in any dataset you like, so
please feel free to do that as an exercise.
The next step is to import everything we need for this notebook.
The next step is to load in our CSB using PD that reads GSV.
The next step is to call the effect head to remind ourselves what our data frame looks like.
As you can see, we have two columns, text and labels.
The next step is to assign a numerical targets for each of our labels.
The next step is to determine the number of classes which we'll call K.
The next step is to split our data into training test.
The next step is to convert our text sentences into sequences.
Note that we are now not using TFI Taf, but instead will be representing each document as a list of
integers.
Note that we've set the max vocab size to two thousand.
The next step is to assign our word to index mapping to a variable and also to check the true vocab
size.
As you can see, there are over 27000 tokens.
The next step is to pad our training sequences.
As you can see, our documents are quite long with a maximum of about a few thousand tokens.
This makes sense since they are news articles.
The next step is to pad the test sequences as well.
But this time, setting the max length to tee this will emulate how we use this model in the real world,
since we wouldn't know the length of any future data that we want to use this model on.
The next step is to create a model.
You can see that I've chosen and embedding size of 50.
But you should feel free to change this as an exercise.
The next step is to create our CNN layers, so we have the input followed by embedding followed by Conven
be followed by global max pooling, followed by dense.
Note that I've commented out the extra convolution and pulling layers.
But as always, you should feel free to test different combinations as an exercise.
Remember that there is no formula for hyper parameters.
You simply choose them based on experiments.
The next step is to call, compile and fit all of which you've seen before.
The next step is to plot the loss per epoch.
So the last for looks good.
The next step is to plot the accuracy per block.
So the accuracy for EPOC looks good, as expected, performance on the train set is better.
So as a final exercise for this lecture, please continue computing other metrics like the F-1 and the
AUC.
In addition, compare the performance of this model to previous models we used on this dataset.
You may be surprised at the result.
Consider why this is the case and think about how this might help guide your decisions about which models
to use in the real world.
Finally, you'll notice that something I mentioned about hyper parameters earlier has now come to fruition,
in particular as our models become more complex.
We have many more hyper parameters to choose.
You can choose the filter size and number of feature maps.
Number of convolution layers with its use flatten or global max pooling and so forth.
This is in addition to the and in part and simple things we saw before, like learning rates.