# Mapping output neurons to classes

I have read few articles some say there is no need to have no. of units in output layer = no. of classes why some say they both should be equal.

My questions are

1. If no. of neurons = no. of classes. How are the classes mapped to each neuron/unit in the output layer. To elaborate how does Neural Network decide which neuron/unit deals with which class.

2. After training a neural network using tensorflow on a multiclass classification problem using softmax in out put layer and no. of units in output layer = no. of classes. When I use this trained network on test sample, the output is a numpy array of probabilities of each class. How do I whther the first element of that array represents which class.

3. If no. of units is not equal to no. of classes can some one share a link of such an example for multiclass problems.

• can you provide a link to article where they mention that no. of output units is not equal to number of classes? – Ruchit Vithani Jul 19 at 7:26
• @RuchitVithani This is the stack over flow answer I found as such it does make sense but I dont know will it work? stackoverflow.com/questions/21773913/… – Hitesh Somani Jul 19 at 8:14

1. The mapping between output units and classes is decided by you. You assign each class an index from $$0$$ to $$N-1$$, where $$N$$ is the number of classes. This values (or one-hot versions of them) are what you supply as expected output to the loss function. Output units form a vector of size $$N$$, with each unit being at a specific position in that vector. The unit at position $$i$$ represents the class with index $$i$$.
2. The output of the softmax is also a vector of $$N$$ probability values. The probability at position $$i$$ represents the probability of the input data belonging to the class with index $$i$$.