weblifier v1.0.0
A Node JS Website Classifier
A javascript website classification library for Node.js. Written in pure JS, the library currently relies on the concept of text classification, by both the title
& meta description
of the target website.
Released under the terms of the MIT LICENSE.
Can this code be trusted?
Don't trust. Verify.
If your intent is to use this library in production, please stop and verify the code yourself before using it.
Installation
npm i weblifier
Usage
const Classifier = require("weblifier");
API
Creating the data
The acceptable format for data would be an array with nested objects. Each object should have the following keys, text
& category
. The category
is the corresponding value to the text
. Kindly note all data must be placed in a json
file.
[
{ "text": "How to Buy Bitcoin", "category": "financial" },
{
"text": "Buy & Sell Locally - Buy. Sell. Simple.",
"category": "ecommerce"
},
...
]
Initiating an instance
let classifier = new Classifier();
Encoding the data
Before training the model you have to encode the data to a bag of words. The encodeData
method does that for you based on your input.
classifier.encodeData(argv[, callback]);
- argv -
(Array|String)
, The argument can be a file name, or an external URL where the data is located, addtionally it can be an array. - callback -
Function
An optional callback function.
Load the encoded data
Once the data is encoded you'll have to load it in order for the model to utilize it.
classifier.loadData(argv[, callback]);
- argv -
(Array|String)
, The argument can be a file name, or an external URL where the encoded data is located, addtionally it can be an encoded array. - callback -
Function
An optional callback function.
Adding data
Once the data has been encoded, you can also use the addData
method, it automatically encodes the given input and concatenates it to the encoded array.
classifier.addData(argv);
- argv -
(Array|Object)
, The argument can an array of objects, or an object.
Training the model
Once you have encoded & loaded the data you can move on to the step of training the model.
classifier.train([optionsOrCallback][, callback]);
- optionsOrCallback -
(Function|Object)
, An optional object or callback argument. Kindly refer to Tensorflow's official documentationargs
parameter for more information. - callback -
Function
An optional callback function.
Classifying a website
Once the model is trained you can use it to classify a website.
classifier.classify(argv[, callback]);
- argv -
String
, The url to the target website. - callback -
Function
An optional callback function.
Saving the model
Once the model is trained you can save it, this will allow you to utilize it when necessary without having to train the model again.
classifier.save(argv[, callback]);
- argv -
*
, Kindly refer to Tensorflow's official documentation for more information. - callback -
Function
An optional callback function.
Saving the data
You can also save the encoded data, doing so you won't have to call the encodeData
method everytime when you initiate an instance.
classifier.saveData([argvOrCallback][, callback]);
- argvOrCallback -
(Function|String)
, The argument can be a file name where the data should be stored, or a callback function. Kindly note,.json
is automatically appended to the argument. - callback -
Function
An optional callback function.
Loading the model
classifier.load(argv[, callback]);
- argv -
*
, Kindly refer to Tensorflow's official documentation for more information. - callback -
Function
An optional callback function.
Upcoming features
- Adding pre-trained model(s).
- Adding default datasets.
- Adding a file upload feature to the
saveData
method. - Adding a debug option with the possibility of getting the raw output.
3 years ago