AI: BrainJs

Js library for AI, following https://scrimba.com/p/pVZJQfg/cP369Sg tutorial.

9 flashcards · Computer Science · by lakesare

  1. Suppose we want to train our AI to execute XOR operation. What should be in place of ______________-s? const net = new brain.NeuralNetwork({ hiddenLayers: [3] });net.______________([ { input: [0, 0], output: [0] }, { input: [0, 1], output: [1] }, { input: [1, 0], output: [1] }, { input: [1, 1], output: [0] }]); console.log(net.______________([0, 0])); => ______________console.log(net.______________([1, 1]));console.log(net.______________([1, 0]));

    const net = new brain.NeuralNetwork({ hiddenLayers: [3] });net.train([ { input: [0, 0], output: [0] }, { input: [0, 1], output: [1] }, { input: [1, 0], output: [1] }, { input: [1, 1], output: [0] }]); console.log(net.run([0, 0])); => [0.05683637782931328]console.log(net.run([1, 1]));console.log(net.run([1, 0]));

  2. How to log the error from back propagation?

  3. What's the relu activation function? const config = { binaryThresh: 0.5, hiddenLayers: [3], // array of ints for the sizes of the hidden layers in the network activation: 'sigmoid', // supported activation types: ['sigmoid', 'relu', 'leaky-relu', 'tanh'], leakyReluAlpha: 0.01, // supported for activation type 'leaky-relu' }; // create a simple feed forward neural network with backpropagation const net = new brain.NeuralNetwork(config);

    // activation "relu" function relu(value) { return value < 0 ? 0 : value; }

  4. How many hidden layers does this neural network have?

    2 hidden layers

  5. What does the :hiddenLayers option accept? const net = new brain.NeuralNetwork({ hiddenLayers: [__________, __________] });

    new brain.NeuralNetwork({ hiddenLayers: [numberOfHiddenLayers, sizeOfEachLayer]}) You can use this to specify the number of hidden layers in the network and the size of each layer. For example, if you want two hidden layers - the first with 3 nodes and the second with 4 nodes, you'd give: hiddenLayers: [3, 4]; By default brain.js uses one hidden layer with size proportionate to the size of the input array.

  6. What does brain js do when one of the properties is not mentioned? // input: { red, green, blue } // ouput: { light, neutral, dark } const colors = [ { green: 0.2, blue: 0.4 }, { green: 0.4, blue: 0.6 }, { red: 0.2, green: 0.8, blue: 0.8 } ]; const brightnesses = [ { neutral: 1 }, { light: 0.8 }, { neutral: 0.7, light: 0.5 }, { dark: 0.5, neutral: 0.5 }, { dark: 0.6, neutral: 0.3 }, ];

    0 is used in its place.

  7. What's the input to net.train([_____________])?

    An array of objects { input: [], output: [] }. net.train([ { input: [0, 0], output: [0] }, { input: [0, 1], output: [1] }, { input: [1, 0], output: [1] }, { input: [1, 1], output: [0] } ]);

  8. Given this data - what actual object do we want to pass to net.train(____________);? // input: { red, green, blue } // ouput: { light, neutral, dark } const colors = [ { green: 0.2, blue: 0.4 }, { green: 0.4, blue: 0.6 }, { red: 0.2, green: 0.8, blue: 0.8 }, { green: 1, blue: 1 }, { red: 0.8, green: 1, blue: 1 }, { red: 1, green: 1, blue: 1 }, { red: 1, green: 0.8, blue: 0.8 }, { red: 1, green: 0.6, blue: 0.6 }, { red: 1, green: 0.4, blue: 0.4 }, { red: 1, green: 0.31, blue: 0.31 }, { red: 0.8…

    [ { input: { green: 0.2, blue: 0.4 }, output: { dark: 0.8 } }, { input: { green: 0.4, blue: 0.6 }, output: { neutral: 0.8 } }, {input: {red: 0.2, green: 0.8, blue: 0.8}, output: {light: 0.7}}, {input: {green: 1, blue: 1}, output: {light: 0.8}}, {input: {red: 0.8, green: 1, blue: 1}, output: {light: 0.9}}, {input: {red: 1, green: 1, blue: 1}, output: {light: 1}}, {input: {red: 1, green: 0.8, blue: 0.8}, output: {light: 0.8}}, {input: {red: 1, green: 0.6, blue: 0.6}, output: {neutral: 0.7, light:…

  9. What does LSTM stand for?

    Long short-term memory Long short-term memory is an artificial recurrent neural network architecture used in the field of deep learning. Unlike standard feedforward neural networks, LSTM has feedback connections. It can not only process single data points, but also entire sequences of data.