Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 1,000,000+ packages pre-installed, including wink-naive-bayes-text-classifier with all npm packages installed. Try it out:

// Load Naive Bayes Text Classifier var Classifier = require( 'wink-naive-bayes-text-classifier' ); // Instantiate var nbc = Classifier(); // eslint-disable-line new-cap // Load wink nlp and its model const winkNLP = require( 'wink-nlp' ); // Load language model const model = require( 'wink-eng-lite-web-model' ); const nlp = winkNLP( model ); const its = nlp.its; const prepTask = function ( text ) { const tokens = []; nlp.readDoc(text) .tokens() // Use only words ignoring punctuations etc and from them remove stop words .filter( (t) => ( t.out(its.type) === 'word' && !t.out(its.stopWordFlag) ) ) // Handle negation and extract stem of the word .each( (t) => tokens.push( (t.out(its.negationFlag)) ? '!' + t.out(its.stem) : t.out(its.stem) ) ); return tokens; }; nbc.definePrepTasks( [ prepTask ] ); // Configure behavior nbc.defineConfig( { considerOnlyPresence: true, smoothingFactor: 0.5 } ); // Train! 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' ); // Consolidate all the training!! nbc.consolidate(); // Start predicting... console.log( nbc.predict( 'I would like to borrow 50000 to buy a new Audi R8 in New York' ) ); // -> autoloan console.log( nbc.predict( 'I want to pay my car loan early' ) ); // -> prepay

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

wink-naive-bayes-text-classifier v2.2.1

Naive Bayes Text Classifier

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free