Create a Target Array

Learn how to create the target array for the MNIST dataset.

Construction of a target array

Now we need to turn these ideas into target arrays for the neural network training. We can see that if the label for a training example is 55, we need to create a target array for the output node where all the elements are small except the one corresponding to the label 55. That could look like:

[0,0,0,0,0,1,0,0,0,0][0, 0, 0, 0, 0, 1, 0, 0, 0, 0]

In fact, we need to rescale those numbers because we’ve already seen how trying to get the neural network to create outputs 00 and 11, which are impossible for the activation function, will drive large weights and a saturated network. So, we’ll use the values 0.010.01 and 0.990.99 instead, so the target for the label 55 should be:

[0.01,0.01,0.01,0.01,0.01,0.99,0.01,0.01,0.01,0.01][0.01, 0.01, 0.01, 0.01, 0.01, 0.99, 0.01, 0.01, 0.01, 0.01]

Let’s have a look at the following Python code to construct the target matrix:

Get hands-on with 1200+ tech skills courses.