npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ai-zero-shot-classifier

v0.0.8

Published

🧠 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

Downloads

693

Readme

ai-zero-shot-classifier

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

| Option | Description | Default | |----------------------------|---------------------------------------------------|------------------| | similarity | Similarity function to use (cosine, dot, euclidean) | cosine | | embeddingBatchSizeData | Batch size for data embeddings | 50 | | embeddingBatchSizeLabels | Batch size for label embeddings | 50 | | embeddingConcurrencyData | Concurrency for data embeddings | 5 | | embeddingConcurrencyLabels | Concurrency for label embeddings | 5 | | comparingConcurrencyTop | Concurrency for top-level comparisons | 10 | | comparingConcurrencyBottom | Concurrency for bottom-level comparisons | 10 |


🛠️ Development

Clone the repository:

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

Install dependencies:

yarn install

Run the development server:

yarn start

Run tests:

yarn test

🤝 Contributing

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