This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const brain = require('brain.js'); | |
const net = new brain.NeuralNetwork(); | |
net.train([{input: [0, 0], output: [0]}, | |
{input: [0, 1], output: [1]}, | |
{input: [1, 0], output: [1]}, | |
{input: [1, 1], output: [0]}]); | |
const output = net.run([1, 0]); // [0.987] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const encode = d => { | |
const encoded = []; | |
d.split('').map(c => { | |
encoded.push((c.charCodeAt(0) / 255)) | |
}) | |
return encoded | |
} | |
const encodeData = data => data.map( d => encode(d) ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const happy = [ | |
{ | |
input: "I am happy", | |
output: {happy: 1} | |
}, | |
{ | |
input: "I feel fine", | |
output: {happy: 1} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const sad = [ | |
{ | |
input: "I am sad", | |
output: {sad: 1} | |
}, | |
{ | |
input: "I feel bad", | |
output: {sad: 1} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const happy = require('./d-happy') | |
const sad = require('./d-sad') | |
const moods = [ | |
...happy, | |
...sad | |
]; | |
module.exports = moods |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const encode = d => { | |
const newArr = []; | |
d.split('').map(c => { | |
newArr.push((c.charCodeAt(0) / 255)) | |
}) | |
return newArr | |
} | |
const encodeData = data => { | |
return data.map( d => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fixLengths = (data) => { | |
let maxLengthInput = -1; | |
for (let i = 0; i < data.length; i++) { | |
if (data[i].input.length > maxLengthInput) { | |
maxLengthInput = data[i].input.length; | |
} | |
} | |
for (let i = 0; i < data.length; i++) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const brain = require('brain.js') | |
const trainData = require('./src/training-data') | |
const serializer = require('./src/serializer') | |
const net = new brain.NeuralNetwork() | |
net.train(serializer.serialize(trainData), {log: true}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const brain = require('brain.js') | |
const trainData = require('./src/training-data') | |
const serializer = require('./src/serializer') | |
const net = new brain.NeuralNetwork() | |
net.train(serializer.serialize(trainData)) | |
const output = net.run(serializer.encode('Nothing is not ok')) | |
console.log(output) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Booleans | |
Boolean(true) // => true | |
Boolean(false) // => false | |
// Strings | |
Boolean("foo") // => true | |
Boolean("") // => false | |
// Numbers | |
Boolean(1) // => true |
OlderNewer