Skip to content

Instantly share code, notes, and snippets.

@lucydjo
Last active June 25, 2019 00:11
Show Gist options
  • Save lucydjo/3f516a0af3e33cd83bd056f92894a406 to your computer and use it in GitHub Desktop.
Save lucydjo/3f516a0af3e33cd83bd056f92894a406 to your computer and use it in GitHub Desktop.
Help ! :p
prenom genre
Louis 1
Raphaël 1
Jules 1
Adam 1
Lucas 1
Léo 1
Hugo 1
Arthur 1
Nathan 1
Liam 1
Éthan 1
Maël 1
Paul 1
Tom 1
Sacha 1
Noah 1
Gabin 1
Nolan 1
Enzo 1
Mohamed 1
Aaron 1
Timéo 1
Théo 1
Mathis 1
Axel 1
Victor 1
Antoine 1
Valentin 1
Martin 1
Noé 1
Éden 1
Robin 1
Marius 1
Rayan 1
Clément 1
Baptiste 1
Maxime 1
Samuel 1
Léon 1
Yanis 1
Augustin 1
Eliott 1
Maxence 1
Évan 1
Mathéo 1
Alexandre 1
Thomas 1
Simon 1
Gaspard 1
Naël 1
Tiago 1
Amir 1
Isaac 1
Nino 1
Ibrahim 1
Lyam 1
Lenny 1
Malo 1
Imran 1
Marceau 1
Alexis 1
Kaïs 1
Camille 1
Noa 1
Oscar 1
Noam 1
Mathys 1
Esteban 1
Ayden 1
Ilyes 1
Lorenzo 1
Kylian 1
Adrien 1
Côme 1
Wassim 1
Ismaël 1
Soan 1
Amine 1
Youssef 1
Naïm 1
Milo 1
Benjamin 1
Ayoub 1
Joseph 1
Owen 1
Ali 1
William 1
Jean 1
Louka 1
Adem 1
Bastien 1
Léandre 1
Antonin 1
Noham 1
Logan 1
Kenzo 1
Younes 1
Sandro 1
David 1
Emma 2
Louise 2
Jade 2
Alice 2
Chloé 2
Lina 2
Mila 2
Léa 2
Manon 2
Rose 2
Anna 2
Inès 2
Camille 2
Lola 2
Ambre 2
Léna 2
Zoé 2
Juliette 2
Julia 2
Lou 2
Sarah 2
Lucie 2
Mia 2
Jeanne 2
Romane 2
Agathe 2
Éva 2
Nina 2
Charlotte 2
Inaya 2
Léonie 2
Sofia 2
Margaux 2
Louna 2
Clara 2
Luna 2
Maëlys 2
Olivia 2
Adèle 2
Lilou 2
Clémence 2
Léana 2
Lana 2
Capucine 2
Éléna 2
Victoria 2
Aya 2
Mathilde 2
Margot 2
Iris 2
Anaïs 2
Giulia 2
Alicia 2
Romy 2
Nour 2
Élise 2
Théa 2
Yasmine 2
Victoire 2
Lya 2
Mya 2
Elsa 2
Charlie 2
Assia 2
Lise 2
Lily 2
Noémie 2
Emy 2
Lisa 2
Lyna 2
Marie 2
Soline 2
Apolline 2
Alix 2
Gabrielle 2
Valentine 2
Louane 2
Candice 2
Pauline 2
Faustine 2
Héloïse 2
Océane 2
Inès 2
Mélina 2
Maya 2
Thaïs 2
Roxane 2
Salomé 2
Lila 2
Maria 2
Constance 2
Célia 2
Sara 2
Livia 2
Zélie 2
Lyana 2
Emmy 2
Alya 2
Élisa 2
Maryam 2
const brain = require('brain.js');
const fs = require('fs')
var validator = require('validator');
var csv = require('csv-parser')
const net = new brain.NeuralNetwork();
let trainingData = [];
fs.createReadStream('data/prenom_custom.csv')
.pipe(csv())
.on('data', (data) => {
if (validator.isAlpha(data.prenom, 'fr-FR') == true) {
if (data.genre == 2) {
trainingData.push({ input: data.prenom, output: { femme: 1, homme: 0 } })
}
if (data.genre == 1) {
trainingData.push({ input: data.prenom, output: { femme: 0, homme: 1 } })
}
}
})
.on('end', () => {
let serializedData = serialize(trainingData);
const config = {
log: true,
logPeriod: 100
};
net.train(serializedData, config);
console.log(net.run(encodeForTest("Noémie", 12)));
console.log(net.run(encodeForTest("Julie", 12)));
console.log(net.run(encodeForTest("Claire", 12)));
console.log(net.run(encodeForTest("Amandine", 12)));
console.log(net.run(encodeForTest("Laurence", 12)));
console.log('----------')
console.log(net.run(encodeForTest("Lucas", 12)));
console.log(net.run(encodeForTest("Maxime", 12)));
console.log(net.run(encodeForTest("Arthur", 12)));
console.log(net.run(encodeForTest("Romain", 12)));
console.log(net.run(encodeForTest("Carlito", 12)));
});
function 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++) {
while (data[i].input.length < maxLengthInput) {
data[i].input.push(0);
}
}
return data;
}
function encodeData(data) {
return data.map(d => {
return {
input: encode(d.input),
output: d.output
}
});
}
function serialize(data) {
return fixLengths(encodeData(data));
};
function encodeForTest(d, nombre) {
const newArr = [];
d.split("").forEach(c => {
newArr.push((c.charCodeAt(0) / 255))
});
while (newArr.length < nombre) {
newArr.push(0);
}
return newArr;
}
function encode(d) {
const newArr = [];
d.split("").forEach(c => {
newArr.push((c.charCodeAt(0) / 255))
});
while (newArr.length < 7) {
newArr.push(0);
}
return newArr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment