@optimaxer/web-classifier
v1.3.6
Published
Welcome to **@optimaxer/web-classifier**, a powerful JavaScript library designed for natural language text classification. Whether you are building a customer feedback analysis tool, a sentiment analysis application, or any other system that requires text
Downloads
202
Readme
@optimaxer/web-classifier
Welcome to @optimaxer/web-classifier, a powerful JavaScript library designed for natural language text classification. Whether you are building a customer feedback analysis tool, a sentiment analysis application, or any other system that requires text categorization, this library provides a robust and efficient solution to meet your needs.
@optimaxer/web-classifier leverages state-of-the-art language models and embedding techniques to classify user texts into predefined categories. A key feature of this library is that the small language model is loaded and executed directly on the end user's device. This approach not only saves on computational resource costs but also enhances data privacy by keeping user data local.
Overview
@optimaxer/web-classifier provides a comprehensive suite of tools for classifying natural language texts. It is built with flexibility and usability in mind, offering components that are straightforward to use while providing powerful classification capabilities.
Components
- Classifier: The core component of the library, responsible for setting up and executing text classification. It supports initializing with a variety of models and embedding engines to best fit your application's needs.
How It Works
The library operates in two main stages:
- Setup: Initialize the classifier by configuring the necessary components, including selecting the language model and embedding engine. The small language model will be loaded and run on the end user's device, which helps save on computational costs and keeps user data private. This step ensures that the classifier is properly prepared for processing texts.
- Classify: Once set up, you can use the classifier to categorize texts into predefined categories. The classification process involves analyzing the text and applying machine learning models to determine the appropriate category.
Due to the restrictions of the Firefox browser, these libraries and functionalities may not work well on Firefox. Please note this limitation.
Quickstart
Getting Started with web-classifier Library
Getting started with the web-classifier library is straightforward. Follow these steps to integrate and utilize the library in your web application effectively.
Step 1: Install the Library
To begin using @optimaxer/web-classifier, you'll first need to install it in your project. You can do this using npm. Open your terminal and run the following command:
npm install @optimaxer/web-classifier
This command will add the library to your project's dependencies.
Step 2: Setting Up the Classifier
Once the library is installed, you need to set up the Classifier component. This step involves initializing the classifier with the appropriate configurations, including the Small Language Model and Browser Embedding Engine.
Here’s how to do it:
Import the Classifier component:
import { Classifier } from '@optimaxer/web-classifier';
Configure the Classifier:
You need to specify the model and engine for the classifier. For example, if you are using 'gemma' as your model and 'mediapipe' as your embedding engine, you can set it up like this:
const classifier = await classifier.setup({ model: 'gemma', inferenceEngine: 'mediapipe', mode: 'local' });
Step 3: Classifying Texts
With the classifier set up, you can now classify user texts into predefined categories. The classify method allows you to categorize texts based on the configured classifier.
Here’s an example:
const sentiment = await classifier.classify('I absolutely love this product!', 'sentiment', ['positive', 'negative']);
The classify method will return the classification result based on the specified categories.
You need to specify the text to classify, the type of classification (e.g., 'sentiment', 'general'), and the categories you want to classify into (e.g., 'positive' and 'negative').