Skip to content

Instantly share code, notes, and snippets.

@emreavcilar
Created November 5, 2021 19:15
Show Gist options
  • Save emreavcilar/0d875cd7c856e2c7a3c3da72ff4d489d to your computer and use it in GitHub Desktop.
Save emreavcilar/0d875cd7c856e2c7a3c3da72ff4d489d to your computer and use it in GitHub Desktop.
javascript ai
/*
Smallest #javascript code that uses #artificialintelligence
to create an #autocomplete bot for a chat app using #brainjs.
Visit their website at brain dot js dot org.
*/
// provide training data
const data = [
'Thank you.',
'I\'m not interested.',
'Call me later.'
];
//create an AI model to be trained
const lstm = new brain.recurrent.LSIM();
//train that model
const result = lstm.train(data,{
iterations:1500,
log:details=>console.log(details),
errorThresh:0.011
});
//AI autocomplete is ready!
console.log('autocomplete ' + lstm.run('Call'));
// prints "Call me later."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment