In this video, we'll be discussing multi-class
neural networks.
In particular, we'll talk about multi-class
neural networks; we'll also talk about multi-class
neural networks in PyTorch.
And then we'll give a brief introduction to
deep neural networks.
So in multi-class neural networks were trying
to predict multiple classes.
So for the MINST dataset we're trying to determine
if our class Y is in digit between 0 & 9.
So multi-class neural networks function pretty
similar to regular neural networks.
Instead of adding a logistic function in the
output, we add a neuron for each class when
a classify, and these neurons have their
own set of parameters.
And then to classify the actual class, which
simply look at the output of each neuron and
select the maximum value, exactly like Softmax function.
So I like to think of it as follows: we have
our Softmax output, and instead of putting
the input feature X we input the outputs to
the hidden layer into the Softmax function,
and then we classify it like a regular Softmax
function.
So we can also use this for two classes and
the only difference is we'll have two outputs.
And I usually use it this way because I can
use a lot of the previal features and functions
that I used before for the two-class problem.
But again, that's up to you, if you have a
two-class classification problem, you can
use a soft max function or the logistic function.
So we take our input, we pass it to the hidden
layer, and then we pass it to the output layer
with multiple outputs, and then we apply the
same methodology we use for the Softmax function.
So let's see how to build a multi-class a
neural network in PyTorch.
So here's our custom module and everything
looks pretty similar.
We have our input dimension.
And then we have the number of hidden layers
denoted by H.
So we take the input to our hidden layer,
and what we're going to do is we're going
to construct the second layer, and D_out will
be the number of classes.
In our last output, we won't apply a sigmoid
activation function.
We can also do it using a sequential module,
where D_out is the number of classes we'd
like as an output.
So we can load the data set, just like the
Softmax example.
And we use the CrossEntropyLoss, like we did
in the Softmax example.
And just to note, our torch sensor has to
be long and has to be n not n x 1 like in
logistic regression.
And we still have to convert our MINST data
set to a 1D tensor or vector, with 784 dimensions.
So we'll construct our neural network object
or model.
The first parameter with the number of input
dimensions.
The second parameter will be the number of
neurons.
And the final parameter will be the number
of classes.
And then we'll optimize it using the SGD optimizer.
We'll create a training loader object.
And a validation loader object.
And then we'll train the model using a function.
And the training process is identical to that
used in Softmax function.
So refer to the Softmax video to see how to
build that function.
So you can also go deep with the neural networks
and this means we're just adding more hidden layers.
So everything is the same.
The data input feature; and we pass it to
the first hidden layer.
And then the output of this hidden layers
is passed the second hidden layer, until we
get to the final.
And for this particular case, we have 5 hidden layers, and each hidden layer doesn't
necessarily have to be the same size.
In this example we have 4 hidden layers.
So before we get to build neural networks
with more hidden layers, we have to see historically
why these networks didn't function before.
And that's it for this video.
