Created
October 26, 2022 04:29
-
-
Save cookieukw/dde4a755952ec648a98d54f4e6378876 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 config = { | |
hiddenLayers: [3], | |
iterations: 2000, | |
log: true, | |
learningRate: 0.001, | |
momentum: 0.1, | |
errorThresh: 0.001, | |
longPeriod: 50 | |
} | |
const fs = require("fs") | |
const brain = require("brain.js") | |
const vex = new brain.recurrent.LSTM({ | |
activation: "leaky-relu" | |
}) | |
const vex_neural = fs.readFileSync("vex_neural.json","utf8") | |
const trainData = JSON.parse(fs.readFileSync("data.json","utf8")).slice(151) | |
const log = l => console.log(l) | |
vex.fromJSON(JSON.parse(vex_neural)) | |
let encode = (word) => { | |
let arr = word | |
.normalize('NFD') | |
.replace(/\p{Diacritic}/gu, "") | |
.replace(/[\u0300-\u036f]/g, '') | |
.toLowerCase() | |
.split(' ') | |
.filter(e => String(e).trim()) | |
return arr.map(letter => (letter.charCodeAt(0) / 255)) | |
}; | |
const saveVex = ()=> { | |
fs.writeFileSync("vex_neural.json",JSON.stringify(vex.toJSON())); | |
}; | |
async function load(){ | |
for(let pos in trainData){ | |
let obj = trainData[pos]; | |
vex.train([{ | |
input: `Oque é ${obj["name"]}?`, | |
output: obj.meanings | |
}], config) | |
vex.train([{ | |
input: obj.name, | |
output: obj.synonyms | |
}], config) | |
log(`${pos} de ${trainData.length}`) | |
saveVex() | |
} | |
} | |
load() | |
vex.maxPredictionLength = 100 | |
log({gg:vex.run("oq é tempo")}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment