Socket
Book a DemoInstallSign in
Socket

ai-zero-shot-classifier

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ai-zero-shot-classifier

🧠 powerful JavaScript library that leverages advanced AI embeddings to perform zero-shot text classification. Whether you're dealing with unlabelled data or seeking to classify text against dynamic and user-defined labels, this library provides a seamles

0.0.10
latest
Source
npmnpm
Version published
Weekly downloads
25
-67.95%
Maintainers
1
Weekly downloads
 
Created
Source

ai-zero-shot-classifier

Follow @ahmad_tokyo

Checkout the demo for a quick start!

🚀 Introduction

ai-zero-shot-classifier is a powerful, flexible JavaScript library designed to perform zero-shot text classification using pre-trained AI embeddings. The library supports multiple providers and models, enabling you to choose the best AI tools for your project, whether it's OpenAI's models or alternative providers like Groq.

🧐 Why ai-zero-shot-classifier?

The Problem

Traditional text classification requires extensive labeled data and retraining models to adapt to new categories. This process can be costly, time-consuming, and impractical when dealing with constantly evolving datasets or dynamic categories.

The Innovation

ai-zero-shot-classifier eliminates the need for labeled datasets by leveraging pre-trained AI embeddings. It allows for dynamic and task-specific labels, enabling real-time classification across various domains without retraining models. It supports multiple providers and their respective models, making it adaptable to diverse use cases.

✨ Features

  • Multi-Provider Support: Works with providers like OpenAI and Groq, enabling integration with models such as GPT, Llama, and others.
  • Dynamic Labels: Define your labels dynamically for each classification task.
  • Multiple Similarity Functions: Supports cosine similarity, dot product, and Euclidean distance for flexible classification needs.
  • Batch Processing: Efficiently handles large datasets with customizable batch sizes and concurrency.
  • Highly Configurable: Adjustable settings for embeddings, similarity calculations, and more.
  • Seamless Integration: Simple API designed for easy use in Node.js and browser environments.

📦 Installation

npm install ai-zero-shot-classifier

or

yarn add ai-zero-shot-classifier

🚀 Usage

Basic Example with classify Function

import { classify } from 'ai-zero-shot-classifier';

const labels = ['Technology', 'Health', 'Finance'];
const data = [
  'Artificial Intelligence is transforming industries.',
  'The stock market has seen unprecedented growth.',
  'Healthcare advancements are improving lives.'
];

classify({ labels, data, config: { similarity: 'cosine' } })
  .then((results) => {
    console.log(results);
  })
  .catch((error) => {
    console.error(error);
  });

Example with ZeroShotClassifier Class

import ZeroShotClassifier from 'ai-zero-shot-classifier';

const labels = ['Technology', 'Health', 'Finance'];
const data = [
  'Artificial Intelligence is transforming industries.',
  'The stock market has seen unprecedented growth.',
  'Healthcare advancements are improving lives.'
];

// Create an instance of the classifier
const classifier = new ZeroShotClassifier({
  provider: 'openai', // Specify the provider
  model: 'text-embedding-3-small', // Specify the model
  apiKey: 'your-api-key', // API key for authentication
  labels, // Provide labels for classification
  dimensions: undefined, // Pass dimensions as a number here to configure vector dimensions
});

(async () => {
  try {
    const results = await classifier.classify(data, {
      similarity: 'cosine', // Choose the similarity metric
    });

    // perform more classification

    console.log('Classification Results:', results);
  } catch (error) {
    console.error('Error during classification:', error);
  }
})();

⚙️ Configuration Options

OptionDescriptionDefault
similaritySimilarity function to use (cosine, dot, euclidean)cosine
embeddingBatchSizeDataBatch size for data embeddings50
embeddingBatchSizeLabelsBatch size for label embeddings50
embeddingConcurrencyDataConcurrency for data embeddings5
embeddingConcurrencyLabelsConcurrency for label embeddings5
comparingConcurrencyTopConcurrency for top-level comparisons10
comparingConcurrencyBottomConcurrency for bottom-level comparisons10

🛠️ Development

Clone the repository:

git clone https://github.com/a-tokyo/ai-zero-shot-classifier.git

Install dependencies:

npm install

Run the development server:

npm start

Run tests:

npm test

Checkout the demo for a quick start!

Fallback Demo!

🤝 Contributing

Contributions are welcome! Feel free to open issues or submit pull requests.

Keywords

ai

FAQs

Package last updated on 31 May 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.