Search code examples
neural-networkartificial-intelligencedeep-learningxordeeplearning4j

Why is this XOR neural network having 2 outputs?


Regularly, a simple neural network to solve XOR should have 2 inputs, 2 neurons in hidden layer, 1 neuron in output layer.

However, the following example implementation has 2 output neurons, and I don't get it:

https://github.com/deeplearning4j/dl4j-examples/blob/master/dl4j-examples/src/main/java/org/deeplearning4j/examples/feedforward/xor/XorExample.java

Why did the author put 2 output neurons in there?

Edit: Author of the example noted that he is using 4 neurons in hidden layer, 2 neurons in output layer. But I still don't get it why, why a shape of {4,2} instead of {2,1}?


Solution

  • This is called one hot encoding. The idea is that you have one neuron per class. Each neuron gives the probability of that class.

    I don't know why he uses 4 hidden neurons. 2 should be enough (if I remember correctly).