wink-naive-bayes-text-classifier
Configurable Naive Bayes Classifier for text with cross-validation support
Classify text, analyse sentiments, recognize user intents for chatbot using wink-naive-bayes-text-classifier
. It's API offers a rich set of features:
- Configure text preparation task such as amplify negation, tokenize, stem, remove stop words, and propagate negation using wink-nlp-utils or any other package of your choice.
- Configure Lidstone or Lapalce additive smoothing.
- Configure Multinomial or Binarized Multinomial Naive Bayes model.
- Export and import learnings in JSON format that can be easily saved on hard-disk.
- Evaluate learning to perform n-fold cross validation.
- Obtain comprehensive metrics including confusion matrix, precision, and recall.
Installation
Use npm to install:
npm install wink-naive-bayes-text-classifier --save
Example
var Classifier = require( 'wink-naive-bayes-text-classifier' );
var nbc = Classifier();
var nlp = require( 'wink-nlp-utils' );
nbc.definePrepTasks( [
nlp.string.tokenize0,
nlp.tokens.removeWords,
nlp.tokens.stem
] );
nbc.defineConfig( { considerOnlyPresence: true, smoothingFactor: 0.5 } );
nbc.learn( 'I want to prepay my loan', 'prepay' );
nbc.learn( 'I want to close my loan', 'prepay' );
nbc.learn( 'I want to foreclose my loan', 'prepay' );
nbc.learn( 'I would like to pay the loan balance', 'prepay' );
nbc.learn( 'I would like to borrow money to buy a vehicle', 'autoloan' );
nbc.learn( 'I need loan for car', 'autoloan' );
nbc.learn( 'I need loan for a new vehicle', 'autoloan' );
nbc.learn( 'I need loan for a new mobike', 'autoloan' );
nbc.learn( 'I need money for a new car', 'autoloan' );
nbc.consolidate();
console.log( nbc.predict( 'I would like to borrow 50000 to buy a new Audi R8 in New York' ) );
console.log( nbc.predict( 'I want to pay my car loan early' ) );
Try experimenting with this example on Runkit in the browser.
Documentation
Check out the Naive Bayes Text Classifier API documentation to learn more.
Need Help?
If you spot a bug and the same has not yet been reported, raise a new issue or consider fixing it and sending a pull request.
About wink
Wink is a family of open source packages for Statistical Analysis, Natural Language Processing and Machine Learning in NodeJS. The code is thoroughly documented for easy human comprehension and has a test coverage of ~100% for reliability to build production grade solutions.
Copyright & License
wink-naive-bayes-text-classifier is copyright 2017-18 GRAYPE Systems Private Limited.
It is licensed under the terms of the MIT License.