Skip to content

Commit

Permalink
docs(README): remove API details
Browse files Browse the repository at this point in the history
  • Loading branch information
sanjayaksaxena committed Oct 10, 2018
1 parent b37c740 commit c5e3eae
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 87 deletions.
68 changes: 8 additions & 60 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Configurable [Naive Bayes](https://en.wikipedia.org/wiki/Naive_Bayes_classifier)

Classify text, analyse sentiments, recognize user intents for chatbot using **`wink-naive-bayes-text-classifier`**. It is a part of [wink](http://winkjs.org/) — a growing family of high quality packages for Statistical Analysis, Natural Language Processing and Machine Learning in NodeJS.

It's [API](#api) offers a rich set of features:
It's [API](http://winkjs.org/wink-naive-bayes-text-classifier/NaiveBayesTextClassifier.html) offers a rich set of features:

1. Configure text preparation task such as **amplify negation**, **tokenize**, **stem**, **remove stop words**, and **propagate negation** using [wink-nlp-utils](https://www.npmjs.com/package/wink-nlp-utils) or any other package of your choice.
2. Configure **Lidstone** or **Lapalce** additive smoothing.
Expand All @@ -18,14 +18,14 @@ It's [API](#api) offers a rich set of features:
5. Evaluate learning to perform n-fold cross validation.
6. Obtain comprehensive metrics including **confusion matrix**, **precision**, and **recall**.

## Installation
### Installation
Use [npm](https://www.npmjs.com/package/wink-naive-bayes-text-classifier) to install:
```
npm install wink-naive-bayes-text-classifier --save
```


## Example
### Example
```javascript

// Load Naive Bayes Text Classifier
Expand Down Expand Up @@ -66,67 +66,15 @@ console.log( nbc.predict( 'I want to pay my car loan early' ) );

```

## API
### Documentation
Check out the [Naive Bayes Text Classifier](http://winkjs.org/wink-naive-bayes-text-classifier/) API documentation to learn more.


#### definePrepTasks( tasks )

Defines the text preparation `tasks` to transform raw incoming text into an array of tokens required during `learn()`, `evaluate()` and `predict()` operations. The `tasks` should be an array of functions. The first function in this array must accept a string as input; and the last function must return an array of tokens as JavaScript Strings. Each function must accept one input argument and return a single value. `definePrepTasks` returns the count of `tasks`.

As illustrated in the usage, [wink-nlp-utils](https://www.npmjs.com/package/wink-nlp-utils) offers a rich set of such functions.

#### defineConfig( config )
Defines the configuration from the `config` object. This object must define 2 properties viz. (a) `considerOnlyPresence` and `smoothingFactor`. The `considerOnlyPresence` must be a boolean — true indicates a binarized model; default value is false. The `smoothingFactor` defines the value for additive smoothing; its default value is **1**. The `defineConfig()` must be called before attempting to learn.

#### learn( input, label )
Simply learns that the `input` belongs to the `label`. If the input is a JavaScript String, then `definePrepTasks()` must be called before learning.


#### consolidate()
Consolidates the learning. It is a prerequisite for `evaluate()` and/or `predict()`.

#### evaluate( input, label )

It is used to evaluate the learning against a test data set. The `input` is used to predict the label, which is compared with the `label` to populate a confusion matrix.

#### metrics()

It computes a detailed metrics consisting of macro-averaged *precision*, *recall* and *f-measure* along with their label-wise values and the *confusion matrix*.

#### predict( input )
Predicts the label for the `input`. If it is unable to predict then it returns a value **`'unknown'`**.

#### computeOdds( input )
Computes the log base-2 of odds of every label for the `input`; and returns the array of `[ label, odds ]` in descending
order of `odds`. Here is an example of the returned array:

```javascript
[
[ 'prepay', 6.169686751688911 ],
[ 'autoloan', -6.169686751688911 ]
]
```

If it is unable to make prediction then it returns a value **`[ [ 'unknown', 0 ] ]`**.

#### exportJSON()
The learning can be exported as JSON text that may be saved in a file.

#### importJSON( json )
An existing JSON learning can be imported for prediction. It is essential to `definePrepTasks()` and `consolidate()` before attempting to predict.

#### stats()
Returns basic stats of learning in terms of count of samples under each label, total words, and the size of vocabulary.

#### reset()
It completely resets the classifier by re-initializing all the learning related variables, except the preparatory tasks. It is useful during cross fold-validation.

## Need Help?
### Need Help?
If you spot a bug and the same has not yet been reported, raise a new [issue](https://github.com/winkjs/wink-naive-bayes-text-classifier/issues) or consider fixing it and sending a pull request.


## Copyright & License
**wink-naive-bayes-text-classifier** is copyright 2017 [GRAYPE Systems Private Limited](http://graype.in/).
### Copyright & License
**wink-naive-bayes-text-classifier** is copyright 2017-18 [GRAYPE Systems Private Limited](http://graype.in/).

It is licensed under the under the terms of the GNU Affero General Public License as published by the Free
Software Foundation, version 3 of the License.
2 changes: 1 addition & 1 deletion docs/NaiveBayesTextClassifier.html
Original file line number Diff line number Diff line change
Expand Up @@ -2078,7 +2078,7 @@ <h5>Returns:</h5>
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Wed Oct 10 2018 17:16:37 GMT+0530 (IST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Wed Oct 10 2018 17:30:26 GMT+0530 (IST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>

<script>prettyPrint();</script>
Expand Down
2 changes: 1 addition & 1 deletion docs/global.html
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ <h5>Returns:</h5>
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Wed Oct 10 2018 17:16:37 GMT+0530 (IST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Wed Oct 10 2018 17:30:26 GMT+0530 (IST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>

<script>prettyPrint();</script>
Expand Down
31 changes: 7 additions & 24 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ <h2><a href="index.html">Home</a></h2><h2><a href="http://winkjs.org" target="_b
<article><h1>wink-naive-bayes-text-classifier</h1><p>Configurable <a href="https://en.wikipedia.org/wiki/Naive_Bayes_classifier">Naive Bayes</a> Classifier for text with cross-validation support</p>
<h3><a href="https://travis-ci.org/winkjs/wink-naive-bayes-text-classifier"><img src="https://api.travis-ci.org/winkjs/wink-naive-bayes-text-classifier.svg?branch=master" alt="Build Status"></a> <a href="https://coveralls.io/github/winkjs/wink-naive-bayes-text-classifier?branch=master"><img src="https://coveralls.io/repos/github/winkjs/wink-naive-bayes-text-classifier/badge.svg?branch=master" alt="Coverage Status"></a> <a href="http://inch-ci.org/github/winkjs/wink-naive-bayes-text-classifier"><img src="http://inch-ci.org/github/winkjs/wink-naive-bayes-text-classifier.svg?branch=master" alt="Inline docs"></a> <a href="https://david-dm.org/winkjs/wink-naive-bayes-text-classifier"><img src="https://david-dm.org/winkjs/wink-naive-bayes-text-classifier/status.svg" alt="dependencies Status"></a> <a href="https://david-dm.org/winkjs/wink-naive-bayes-text-classifier?type=dev"><img src="https://david-dm.org/winkjs/wink-naive-bayes-text-classifier/dev-status.svg" alt="devDependencies Status"></a> <a href="https://gitter.im/winkjs/Lobby"><img src="https://img.shields.io/gitter/room/nwjs/nw.js.svg" alt="Gitter"></a></h3><p><img align="right" src="https://decisively.github.io/wink-logos/logo-title.png" width="100px" ></p>
<p>Classify text, analyse sentiments, recognize user intents for chatbot using <strong><code>wink-naive-bayes-text-classifier</code></strong>. It is a part of <a href="http://winkjs.org/">wink</a> — a growing family of high quality packages for Statistical Analysis, Natural Language Processing and Machine Learning in NodeJS.</p>
<p>It's <a href="#api">API</a> offers a rich set of features:</p>
<p>It's <a href="http://winkjs.org/wink-naive-bayes-text-classifier/NaiveBayesTextClassifier.html">API</a> offers a rich set of features:</p>
<ol>
<li>Configure text preparation task such as <strong>amplify negation</strong>, <strong>tokenize</strong>, <strong>stem</strong>, <strong>remove stop words</strong>, and <strong>propagate negation</strong> using <a href="https://www.npmjs.com/package/wink-nlp-utils">wink-nlp-utils</a> or any other package of your choice.</li>
<li>Configure <strong>Lidstone</strong> or <strong>Lapalce</strong> additive smoothing.</li>
Expand All @@ -62,8 +62,8 @@ <h3><a href="https://travis-ci.org/winkjs/wink-naive-bayes-text-classifier"><img
<li>Evaluate learning to perform n-fold cross validation.</li>
<li>Obtain comprehensive metrics including <strong>confusion matrix</strong>, <strong>precision</strong>, and <strong>recall</strong>.</li>
</ol>
<h2>Installation</h2><p>Use <a href="https://www.npmjs.com/package/wink-naive-bayes-text-classifier">npm</a> to install:</p>
<pre class="prettyprint source"><code>npm install wink-naive-bayes-text-classifier --save</code></pre><h2>Example</h2><pre class="prettyprint source lang-javascript"><code>
<h3>Installation</h3><p>Use <a href="https://www.npmjs.com/package/wink-naive-bayes-text-classifier">npm</a> to install:</p>
<pre class="prettyprint source"><code>npm install wink-naive-bayes-text-classifier --save</code></pre><h3>Example</h3><pre class="prettyprint source lang-javascript"><code>
// Load Naive Bayes Text Classifier
var Classifier = require( 'wink-naive-bayes-text-classifier' );
// Instantiate
Expand Down Expand Up @@ -99,26 +99,9 @@ <h2>Installation</h2><p>Use <a href="https://www.npmjs.com/package/wink-naive-ba
// -> autoloan
console.log( nbc.predict( 'I want to pay my car loan early' ) );
// -> prepay
</code></pre><h2>API</h2><h4>definePrepTasks( tasks )</h4><p>Defines the text preparation <code>tasks</code> to transform raw incoming text into an array of tokens required during <code>learn()</code>, <code>evaluate()</code> and <code>predict()</code> operations. The <code>tasks</code> should be an array of functions. The first function in this array must accept a string as input; and the last function must return an array of tokens as JavaScript Strings. Each function must accept one input argument and return a single value. <code>definePrepTasks</code> returns the count of <code>tasks</code>.</p>
<p>As illustrated in the usage, <a href="https://www.npmjs.com/package/wink-nlp-utils">wink-nlp-utils</a> offers a rich set of such functions.</p>
<h4>defineConfig( config )</h4><p>Defines the configuration from the <code>config</code> object. This object must define 2 properties viz. (a) <code>considerOnlyPresence</code> and <code>smoothingFactor</code>. The <code>considerOnlyPresence</code> must be a boolean — true indicates a binarized model; default value is false. The <code>smoothingFactor</code> defines the value for additive smoothing; its default value is <strong>1</strong>. The <code>defineConfig()</code> must be called before attempting to learn.</p>
<h4>learn( input, label )</h4><p>Simply learns that the <code>input</code> belongs to the <code>label</code>. If the input is a JavaScript String, then <code>definePrepTasks()</code> must be called before learning.</p>
<h4>consolidate()</h4><p>Consolidates the learning. It is a prerequisite for <code>evaluate()</code> and/or <code>predict()</code>.</p>
<h4>evaluate( input, label )</h4><p>It is used to evaluate the learning against a test data set. The <code>input</code> is used to predict the label, which is compared with the <code>label</code> to populate a confusion matrix.</p>
<h4>metrics()</h4><p>It computes a detailed metrics consisting of macro-averaged <em>precision</em>, <em>recall</em> and <em>f-measure</em> along with their label-wise values and the <em>confusion matrix</em>.</p>
<h4>predict( input )</h4><p>Predicts the label for the <code>input</code>. If it is unable to predict then it returns a value <strong><code>'unknown'</code></strong>.</p>
<h4>computeOdds( input )</h4><p>Computes the log base-2 of odds of every label for the <code>input</code>; and returns the array of <code>[ label, odds ]</code> in descending
order of <code>odds</code>. Here is an example of the returned array:</p>
<pre class="prettyprint source lang-javascript"><code>[
[ 'prepay', 6.169686751688911 ],
[ 'autoloan', -6.169686751688911 ]
]</code></pre><p>If it is unable to make prediction then it returns a value <strong><code>[ [ 'unknown', 0 ] ]</code></strong>.</p>
<h4>exportJSON()</h4><p>The learning can be exported as JSON text that may be saved in a file.</p>
<h4>importJSON( json )</h4><p>An existing JSON learning can be imported for prediction. It is essential to <code>definePrepTasks()</code> and <code>consolidate()</code> before attempting to predict.</p>
<h4>stats()</h4><p>Returns basic stats of learning in terms of count of samples under each label, total words, and the size of vocabulary.</p>
<h4>reset()</h4><p>It completely resets the classifier by re-initializing all the learning related variables, except the preparatory tasks. It is useful during cross fold-validation.</p>
<h2>Need Help?</h2><p>If you spot a bug and the same has not yet been reported, raise a new <a href="https://github.com/winkjs/wink-naive-bayes-text-classifier/issues">issue</a> or consider fixing it and sending a pull request.</p>
<h2>Copyright &amp; License</h2><p><strong>wink-naive-bayes-text-classifier</strong> is copyright 2017 <a href="http://graype.in/">GRAYPE Systems Private Limited</a>.</p>
</code></pre><h3>Documentation</h3><p>Check out the <a href="http://winkjs.org/wink-naive-bayes-text-classifier/">Naive Bayes Text Classifier</a> API documentation to learn more.</p>
<h3>Need Help?</h3><p>If you spot a bug and the same has not yet been reported, raise a new <a href="https://github.com/winkjs/wink-naive-bayes-text-classifier/issues">issue</a> or consider fixing it and sending a pull request.</p>
<h3>Copyright &amp; License</h3><p><strong>wink-naive-bayes-text-classifier</strong> is copyright 2017-18 <a href="http://graype.in/">GRAYPE Systems Private Limited</a>.</p>
<p>It is licensed under the under the terms of the GNU Affero General Public License as published by the Free
Software Foundation, version 3 of the License.</p></article>
</section>
Expand All @@ -135,7 +118,7 @@ <h2>Copyright &amp; License</h2><p><strong>wink-naive-bayes-text-classifier</str
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Wed Oct 10 2018 17:16:37 GMT+0530 (IST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Wed Oct 10 2018 17:30:26 GMT+0530 (IST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>

<script>prettyPrint();</script>
Expand Down
2 changes: 1 addition & 1 deletion docs/wink-naive-bayes-text-classifier.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,7 @@ <h1 class="page-title">wink-naive-bayes-text-classifier.js</h1>
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Wed Oct 10 2018 17:16:37 GMT+0530 (IST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Wed Oct 10 2018 17:30:26 GMT+0530 (IST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>

<script>prettyPrint();</script>
Expand Down

0 comments on commit c5e3eae

Please sign in to comment.