Closed bags307 closed 7 years ago
it is supported in natural
A classifier can also be persisted and recalled so you can reuse a training
classifier.save('classifier.json', function(err, classifier) { // the classifier is saved to the classifier.json file! }); To recall from the classifier.json saved above:
natural.BayesClassifier.load('classifier.json', null, function(err, classifier) { console.log(classifier.classify('long SUNW')); console.log(classifier.classify('short SUNW')); }); A classifier can also be serialized and deserialized like so:
var classifier = new natural.BayesClassifier(); classifier.addDocument(['sell', 'gold'], 'sell'); classifier.addDocument(['buy', 'silver'], 'buy');
// serialize var raw = JSON.stringify(classifier); // deserialize var restoredClassifier = natural.BayesClassifier.restore(JSON.parse(raw)); console.log(restoredClassifier.classify('i should sell that'));
This should also work here and is tested in https://github.com/mysamai/natural-brain/blob/master/test/baseline.test.js#L111.
A Note: It is still going to train the net every time you load or restore.
@daffl
i tried seems no need to retrain
BrainJSClassifier.load('brain_classifier.json', null,function(error,classifier) {
console.log('loaded');
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
});
What I meant was that it doesn't store the serialized Neural Network, just the Node Natural training data. Glad it is working though, going to close this issue!
both natural and brain allow for serialization (in the case of brain), or actual saving of a trained classifer (natural).
Is there a similar functionality here?