So in this lecture, we will be looking at the notebook to implement and then for multiclass classification
and code, we'll begin by downloading our data set, which will be the BBC News data once again.
The next step is to import everything we need for this script.
Notice that there's nothing new.
The next step is to read in our 6V using PD that reads GSV.
The next step is to call the effect head to remind ourselves what our data looks like.
As you recall, there are two columns containing the text and the labels.
Now, as you recall, for TensorFlow, we need to specify our targets as integers from zero up to K
minus one.
To do this more easily.
Note that we can simply take the labels in our data frame, convert them to category type and then call
the codes attribute.
This basically does what we need.
Converting every label to a unique integer starting from zero.
So as you can see, this returns a a series of integers from zero up to four.
The next step is to take what we got above and to assign it to a new column called Targets.
The next step is to split our data into train and test.
The next step is to compute the TF IDF representation of our training and test sets.
The next step is to assign the targets to why trained and why test.
The next step is to get the number of classes, which is the maximum target plus one.
The next step is to get the number of dimensions in our data, which is the number of columns in X.
The next step is to build our model.
Note that this is exactly like our logistic regression model, but with one more dense in the middle,
you'll see that I've chosen 300 hidden units.
This is arbitrary.
So please play around with this value on your own as an exercise.
You'll also notice that have specified the activation function as well.
You again, please try others on your own.
See if you can improve the result and post your solution on the Q&A.
The next step is to call motto that summary to look at the structure of our model.
So notice that the first dense layer has many more parameters than what we've seen before.
This is about seven to eight million weights.
The next step is to call model that compile notice our use of the sparse, categorical cross entropy
where we set from logic to true.
The next step is to convert our to free of matrices into Nampai arrays.
The next step is to call the fit method to find our model parameters.
The next step is to plot the loss for Epoch.
OK, so the last report looks good.
Notice that the validation loss is not as good as the train loss, which is expected.
The next step is to plot the accuracy for Epoch.
Again, notice how the validation accuracy is not as good as the train accuracy, which again is expected.
The next step is to check a histogram of our labels.
So since our labels are relatively balanced, there's no real need to check the AUC or the F1.
So as a final exercise for this lecture, please implement a neural network for our sentiment analysis
dataset, as you recall.
One thing we did previously was to interpret that model, and the results made a lot of sense.
We saw that the most positive weights were assigned to positive words, while the most negative weights
were assigned to negative words.
Consider by yourself whether or not a neural network would have such a nice interpretability.