1.0.1 • Published 8 years ago

natural-synaptic v1.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
8 years ago

natural-synaptic

Circle CI

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.

Usage

Installing

You can either clone this repo or install it from npm:

npm install natural-synaptic --save

Training and Classifying

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

Load/Reload from file

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
    });
});
1.0.1

8 years ago

1.0.0

8 years ago