Hi,
I was experimenting with LSTM yesteraday and it seems it cannot parse the letter P
This is whats it throwing
/Users/didair/ai/node_modules/brain.js/dist/utilities/data-formatter.js:85
throw new Error('unrecognized character "' + character + '"');
^
Error: unrecognized character "p"
at DataFormatter.toIndexes (/Users/didair/ai/node_modules/brain.js/dist/utilities/data-formatter.js:85:17)
at DataFormatter.toIndexesInputOutput (/Users/didair/ai/node_modules/brain.js/dist/utilities/data-formatter.js:101:23)
at LSTM.formatDataIn (/Users/didair/ai/node_modules/brain.js/dist/recurrent/rnn.js:751:35)
at LSTM.run (/Users/didair/ai/node_modules/brain.js/dist/recurrent/rnn.js:374:24)
at Object.<anonymous> (/Users/didair/ai/example.js:24:22)
at Module._compile (module.js:571:32)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
What does your code look like?
Like this
if i change the query to whatever string without the letter P it does a successful request
`
const brain = require('brain.js');
let memory = require('./memory.json');
var query = "hiphop";
var net = new brain.recurrent.LSTM();
net.train(memory, { log: true, errorTresh: 0.005, iterations: 7500, learningRate: 0.4 } );
var response = net.run(query);
var newResponse = { 'query': query, 'response': response };
console.log('result', newResponse); `
how about your training data?
I have same issue here.
I don't understand correctly how this LSTM works.
For example, a simple test with fibonacci sequence:
const brain = require("brain.js");
// fibonacci
var fibonacci = [
{ input: [1], output: [1] },
{ input: [2], output: [1] }
];
for( var i = 2; i <= 50; i++ ){
var tmp = fibonacci.slice( -2 );
fibonacci.push( { input: [ i ], output: [( parseInt(tmp[0].output) + parseInt(tmp[1].output) )] } );
}
var net = new brain.recurrent.LSTM();
net.train( fibonacci.slice( 0, -1 ), {
errorThresh: 0.005, // error threshold to reach
iterations: 200, // maximum training iterations
log: true, // console.log() progress periodically
logPeriod: 10, // number of iterations between logging
learningRate: 0.3 // learning rate
});
console.log( fibonacci )
console.log( net.run( [ 51 ] ) );
This code above is very simple, it creates a fibonacci sequence with the number position as input and your value as output.
The idea is to predict the 51 th number on sequence. But te error is:
/Users/adriano/Documents/desenvolvimento/neural-network/javascript-nn/brain.js/node_modules/brain.js/dist/utilities/data-formatter.js:85
throw new Error('unrecognized character "' + character + '"');
^
Error: unrecognized character "51"
at DataFormatter.toIndexes (/Users/adriano/Documents/desenvolvimento/neural-network/javascript-nn/brain.js/node_modules/brain.js/dist/utilities/data-formatter.js:85:17)
at DataFormatter.toIndexesInputOutput (/Users/adriano/Documents/desenvolvimento/neural-network/javascript-nn/brain.js/node_modules/brain.js/dist/utilities/data-formatter.js:103:23)
at LSTM.formatDataIn (/Users/adriano/Documents/desenvolvimento/neural-network/javascript-nn/brain.js/node_modules/brain.js/dist/recurrent/rnn.js:751:35)
at LSTM.run (/Users/adriano/Documents/desenvolvimento/neural-network/javascript-nn/brain.js/node_modules/brain.js/dist/recurrent/rnn.js:374:24)
at Object.<anonymous> (/Users/adriano/Documents/desenvolvimento/neural-network/javascript-nn/brain.js/index.js:28:18)
at Module._compile (module.js:398:26)
at Object.Module._extensions..js (module.js:405:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Function.Module.runMain (module.js:430:10)
Then, how can I predict a value with a input not previously trained, using the brain.js?
Because the same example with other vendor (like Tensorflow), returns a result (not correct) but have a result anyway, and here results this issue.
Thank you :)
Mmh I think the correct syntax for the run method would be:
net.run({input:51});
@NicolasBrondin
Thank you, but this is not correct syntax (with current version [email protected]).
If run as array, works:
net.run( [ 49 ] );
If run as object, does not works:
net.run( {input: 49 } );
If run as object with array, does not works:
net.run( {input: [49] } );
Same error to predict the position 51.
Does not works:
net.run( {input: 51 } );
Returns this error:
C:\desenvolvimento\javascript-nn\brain.js\node_modules\brain.js\dist\utilities\data-formatter.js:103
result = this.toIndexes(value1.concat(['stop-input', 'start-output']), maxThreshold);
^
TypeError: value1.concat is not a function
at DataFormatter.toIndexesInputOutput (C:\desenvolvimento\javascript-nn\brain.js\node_modules\brain.js\dist\utilities\data-formatter.js:103:40)
at LSTM.formatDataIn (C:\desenvolvimento\javascript-nn\brain.js\node_modules\brain.js\dist\recurrent\rnn.js:751:35)
at LSTM.run (C:\desenvolvimento\javascript-nn\brain.js\node_modules\brain.js\dist\recurrent\rnn.js:374:24)
at Object.<anonymous> (C:\desenvolvimento\javascript-nn\brain.js\index.js:28:18)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.runMain (module.js:604:10)
Looking into this now, sorry I've been neck deep in other stuff.
Reproduced here: https://jsfiddle.net/robertleeplummerjr/chd5y44c/
Ok the issue is that the existing implementation is for supervised learning, but what we want (including me) is unsupervised learning. In the case of fibonacci numbers, you could feed them all in and then it could learn them, but that isn't ideal here.
I'm going to brainstorm this.
We will have a means of solving this in v2, fyi.
That's quite funny, just came back to try out Brain and bam, this exact error :)
Glad to hear it's being fixed.
Hi,
It looks like the issue still not resolved. Interestingly "indexTable" do not contain the required values. (data-formatter.js:86:17)
Code:
const brain = require('brain.js'),
fs = require('fs');
const data = ['abonent','a臒ac','aeroplan','s蓹naye'];
const lstm = new brain.recurrent.LSTM();
const result = lstm.train(data, { iterations: 1000 });
console.log('Result: ' + lstm.run('box'));
saveFile();
function saveFile() {
fs.writeFile("network.json", JSON.stringify(lstm.toJSON()), function (err) {
if (err)
return console.log(err);
console.log("Data saved.");
});
}
Output:
Error: unrecognized character "x"
at DataFormatter.toIndexes (C:\brainjs\node_modules\brain.js\dist\utilities\data-formatter.js:86:17)
at LSTM.formatDataIn (C:\brainjs\node_modules\brain.js\dist\recurrent\rnn.js:771:35)
at LSTM.run (C:\brainjs\node_modules\brain.js\dist\recurrent\rnn.js:381:24)
at Object.<anonymous> (C:\brainjs\brain.js:9:31)
at Module._compile (module.js:635:30)
at Object.Module._extensions..js (module.js:646:10)
at Module.load (module.js:554:32)
at tryModuleLoad (module.js:497:12)
at Function.Module._load (module.js:489:3)
at Function.Module.runMain (module.js:676:10)
This was be fixed in: https://github.com/BrainJS/brain.js/pull/241
Most helpful comment
@NicolasBrondin
Thank you, but this is not correct syntax (with current version [email protected]).
If run as array, works:
If run as object, does not works:
If run as object with array, does not works:
Same error to predict the position 51.
Does not works:
Returns this error: