Skip to main content

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:

1. Import the Classifier component:

import { Classifier } from '@optimaxer/web-classifier';

2. 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.

tip

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').

info

If you encounter any issues, make sure:

  • The library is correctly installed and imported.
  • The setup method completes successfully before calling classify.
  • The model and engine names are correctly specified.