JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://cdn.rawgit.com/BrainJS/brain.js/develop/browser.js"></script>
JavaScript
let net = new brain.NeuralNetwork();
let trainedNet;
let longest;
train(getTrainingData());
console.log(trainedNet(encode(adjustSize('Last night, it was my great honor to host America’s senior defense and military leaders for dinner at the White House. America’s military is the GREATEST fighting force in the history of the world. They all have my pledge of unwavering commitment to our men and women in uniform! '))));
console.log(trainedNet(encode(adjustSize('Incredible to have a Chicago team in the Final Four. I’ll take that over an intact bracket any day! Congratulations to everybody @loyolachicago - let’s keep it going!'))));
function train(data) {
net.train(processTrainingData(data), {
log: true,
learningRate: 0.1
});
trainedNet = net.toFunction();
}
function encode(arg) {
return arg.split('').map(x => (x.charCodeAt(0) / 400));
}
function processTrainingData(data) {
const processedValues = data.map(d => {
return {
input: encode(d.input),
output: d.output
}
});
console.log(processedValues);
return processedValues;
}
function getTrainingData() {
const trainingData = [{
input: 'RT @ObamaFoundation: This week—50 years since Dr. Martin Luther King, Jr. was killed—@BarackObama and @repjohnlewis sat down with a group o…',
output: {
Barack: 1
}
},
{
input: 'Incredible to have a Chicago team in the Final Four. I’ll take that over an intact bracket any day! Congratulations to everybody @loyolachicago - let’s keep it going!',
output: {
Barack: 1
}
},
{
input: 'In Singapore with young people who are advocating for education, empowering young women, and getting involved all over Southeast Asia with a profoundly optimistic commitment to building the world they want to see. ',
output: {
Barack: 1
}
},
{
input: 'Very thankful for President Xi of China’s kind words on tarrifs and...