A natural language classifier for Node Natural using a Synaptic neural network.
This project was inspired by Natural Brain, which is based on a BrainJS neural network. The reason for the re-write is that BrainJS is currently unmaintained (see issue).
Note: This classifier passes the same tests as the Node Natural Bayes classifier.
You can either clone this repo or install it from npm:
npm install natural-synaptic --save
var NaturalSynaptic = require('natural-synaptic');
var classifier = new NaturalSynaptic();
classifier.addDocument('my unit-tests failed.', 'software');
classifier.addDocument('tried the program, but it was buggy.', 'software');
classifier.addDocument('tomorrow we will do standup.', 'meeting');
classifier.addDocument('the drive has a 2TB capacity.', 'hardware');
classifier.addDocument('i need a new power supply.', 'hardware');
classifier.addDocument('can you play some new music?', 'music');
classifier.train();
console.log(classifier.classify('did the tests pass?')); // -> software
console.log(classifier.classify('did you buy a new drive?')); // -> hardware
console.log(classifier.classify('What is the capacity?')); // -> hardware
console.log(classifier.classify('Lets meet tomorrow?')); // -> meeting
console.log(classifier.classify('Can you play some stuff?')); // -> music
var NaturalSynaptic = require('natural-synaptic');
var classifier = new NaturalSynaptic();
classifier.addDocument('my unit-tests failed.', 'software');
classifier.addDocument('tried the program, but it was buggy.', 'software');
classifier.addDocument('tomorrow we will do standup.', 'meeting');
classifier.addDocument('the drive has a 2TB capacity.', 'hardware');
classifier.addDocument('i need a new power supply.', 'hardware');
classifier.addDocument('can you play some new music?', 'music');
classifier.train();
classifier.save("file_to_save.json", function(err) {
NaturalSynaptic.load("file_to_save.json", function(err, newClassifier) {
console.log(newClassifier.classify('did the tests pass?')); // -> software
console.log(newClassifier.classify('did you buy a new drive?')); // -> hardware
console.log(newClassifier.classify('What is the capacity?')); // -> hardware
console.log(newClassifier.classify('Lets meet tomorrow?')); // -> meeting
console.log(newClassifier.classify('Can you play some stuff?')); // -> music
});
});