O'Reilly logo

Mastering Apache Spark 2.x - Second Edition by Romeo Kienzler

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Deeplearning4j

So, now that we've covered ND4J, we want to actually create our neural network. So let's start with the famous XOR example, which actually trains a neural network for learning XOR.

Let's first generate some training data inline:

/*      * list off input values, 4 training samples with data for 2 input-neurons each      */     var input: INDArray = Nd4j.zeros(4, 2)      /*      *  correspondending list with expected output values, 4 training samples with      *  data for 2 output-neurons each      */     var labels: INDArray = Nd4j.zeros(4, 2);      /*      *  create first dataset when first input=0 and second input=0      */     input.putScalar(Array(0, 0), 0);     input.putScalar(Array(0, 1), 0);      /*      *  then the first output fires for false, and the second is 0 (see class comment) */ ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required