concept more than two class in category Keras

appears as: more th two classes
Probabilistic Deep Learning: With Python, Keras and TensorFlow Probability

This is an excerpt from Manning's book Probabilistic Deep Learning: With Python, Keras and TensorFlow Probability.

The output layer gives the probability for the instance to be a real or fake banknote. You have seen that one neuron is sufficient in a binary classification problem because knowing the probability p of one class fixes the probability of the other class to 1 - p. You can also use two neurons in the output layer: one neuron modeling the probability for the first class and the other neuron modeling the probability for the second class. This output layer design generalizes to classification tasks with more than two classes. In that case, the output layer has as many neurons as you have classes in the classification problem. Each neuron stands for a class, and you want to interpret the output of the neuron as the probability for the class. This can be done using the softmax function. The softmax function takes the weighted sum z□i and transforms it into a probability pi by setting

4.2.2   Classification problems with more than two classes

What happens if you have more than two classes? Nothing special, you might think, and you are right. You’ve already done this in several exercises in chapter 2 where you have tackled the task of discriminating between the ten digits in the MNIST data set. Recall, when setting up the DL models for the MNIST task, you used the same loss as in a binary classification model: loss='categorical_crossentropy'. Let’s check out how you can use the maximum likelihood approach to derive the loss function and show that using the crossentropy is appropriate.

Let’s use the same procedure for a classification task with more than two classes. In the MNIST example, you have ten classes and you use an NN with ten output nodes - one for each class. Recall for example the architecture that we used in chapter 2 for the MNIST handwritten digit classification task that was shown in figure 2.12 (which we repeat in figure 4.8).

Figure 4.8: A fully connected NN with two hidden layers. For the MNIST example, the input layer has 784 values for the 28 x 28 pixels. The output layer has ten nodes, one for each class.

In the MNIST task you want to discriminate between 10 classes (0, 1, …,9). Therefore you set up an NN with ten output nodes, each providing the probability that the input corresponds to the respective class. These ten probabilities define the ten parameters of the CPD in the MNIST classification model. The model of the classification CPD is called multinomial distribution, which is an extension of the Bernoulli distribution to more than two classes. In case of the MNIST classification task with ten classes the multinomial CPD and can be expressed as follows: