Neural network output returning Null

Asked

Viewed 110 times

0

I’m making a neural net with brain.js, to learn the alphabet. the code is as follows::

const alfabeto = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "T", "U", "V", "W", "X", "Y", "Z"];

function converteLetrasemNumeros(letras) {
	let alfabeto = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	let codigos = [];
        let numeros = [];
	for (let i = 0; i < letras.length; i++) {
		codigos.push(alfabeto.indexOf(letras[i].toUpperCase()) + 1);
	}
  	numeros.push(codigos);
	return numeros;
}
function converteNumerosemLetras(numero) {
  let letra;
  console.log(String.fromCharCode(numero+64));
  return letra;
}
let trainingData = [];
trainingData.push(converteLetrasemNumeros(alfabeto));

const neuralNetwork = new brain.recurrent.LSTMTimeStep({hiddenLayers: [2][3]});

console.log(neuralNetwork.train(trainingData, {errorTrash: 0.0001, iterations: 25000}));

console.log(neuralNetwork.run(converteLetrasemNumeros(["A", "B", "C"])));
<html>
    <head>
        <script src="https://cdn.rawgit.com/BrainJS/brain.js/45ce6ffc/browser.js"></script>
        <script src="index.js"></script>
    </head>
    <body>
    </body>
</html>

The network output, as you can see when executing the code, returns Null.

  • 1

    Use the answer field for the solution instead of adding in the question

1 answer

1


I already found the solution to the problem. The Error was in this block:

for (let i = 0; i < letras.length; i++) {
    codigos.push(alfabeto.indexOf(letras[i].toUpperCase()) + 1);
}
numeros.push(codigos);

I was adding values to the Array numbers, outside the loop, which in turn received values from another Array. So the corrected code looks like this:

for (let i in letras) {
    numeros.push(alfabeto.indexOf(letras[i].toUpperCase()) + 1);
}
return numeros

Browser other questions tagged

You are not signed in. Login or sign up in order to post.