diff --git a/README.md b/README.md index 548b81b..1e94bbd 100644 --- a/README.md +++ b/README.md @@ -6,26 +6,34 @@ ![Codecov Coverage](https://img.shields.io/codecov/c/github/A-Tokyo/ai-zero-shot-classifier.svg) ![Twitter Follow](https://img.shields.io/twitter/follow/ahmad_tokyo.svg?label=Follow%20@ahmad_tokyo) -[Demo](https://a-tokyo.github.io/ai-zero-shot-classifier) +--- ## 🚀 Introduction -**ai-zero-shot-classifier** is a 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 seamless and efficient solution. +**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** -In many real-world applications, acquiring labeled data for training classification models is time-consuming, expensive, and sometimes impractical. Traditional supervised learning approaches require vast amounts of annotated data, which isn't always feasible to obtain. Moreover, adapting models to new, unforeseen categories necessitates retraining, which can be resource-intensive. +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** addresses these challenges by using pre-trained embeddings to classify text without any task-specific training. You simply define your labels dynamically, and the classifier matches your data with the closest label based on semantic similarity. +**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 -- **Dynamic Labels**: Classify text using labels you define on the fly. -- **Multiple Similarity Functions**: Supports cosine similarity, dot product, and Euclidean distance. -- **Batch Processing**: Handles embeddings and similarity calculations efficiently using customizable batch sizes and concurrency. -- **Integration-Friendly**: Works seamlessly with OpenAI embeddings and can be easily integrated into your application. +- **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 @@ -39,6 +47,8 @@ or yarn add ai-zero-shot-classifier ``` +--- + ## 🚀 Usage ### Basic Example @@ -62,7 +72,9 @@ classify({ labels, data, config: { similarity: 'cosine' } }) }); ``` -### Configuration Options +--- + +## ⚙️ Configuration Options | Option | Description | Default | |----------------------------|---------------------------------------------------|------------------| @@ -74,6 +86,8 @@ classify({ labels, data, config: { similarity: 'cosine' } }) | `comparingConcurrencyTop` | Concurrency for top-level comparisons | `10` | | `comparingConcurrencyBottom` | Concurrency for bottom-level comparisons | `10` | +--- + ## 🛠️ Development Clone the repository: @@ -100,10 +114,14 @@ Run tests: yarn test ``` +--- + ## 🤝 Contributing Contributions are welcome! Feel free to open issues or submit pull requests. +--- + ## 📄 License This project is licensed under the MIT License. diff --git a/demo/src/Demo/Demo.tsx b/demo/src/Demo/Demo.tsx index bf6b591..99faa52 100644 --- a/demo/src/Demo/Demo.tsx +++ b/demo/src/Demo/Demo.tsx @@ -8,6 +8,8 @@ import classify from '../../../src/classify'; // Adjust the import path as neces function Demo() { // Configuration states const [apiKey, setApiKey] = useState(''); // New state for API Key + const [provider, setProvider] = useState<'openai' | 'groq'>('openai'); // Provider selection + const [model, setModel] = useState('text-embedding-3-small'); // Model selection const [labelsInput, setLabelsInput] = useState('Technology, Health, Finance'); // Comma-separated labels const [similarity, setSimilarity] = useState('cosine'); // 'cosine', 'dot', 'euclidean' @@ -38,9 +40,9 @@ Healthcare advancements are improving lives.`, .map((data) => data.trim()) .filter((data) => data.length > 0); - setCodeString(`import classify from 'ai-zero-shot-classifier'; + setCodeString(`import { classify } from 'ai-zero-shot-classifier'; -/** Your OpenAI API Key */ +/** Your Provider API Key */ const apiKey = '${apiKey}'; /** Labels for classification */ @@ -53,6 +55,8 @@ const data = [ /** Configuration (optional) */ const config = { + provider: '${provider}', + model: '${model}', similarity: '${similarity}', }; @@ -65,7 +69,7 @@ classify({ labels, data, config, apiKey }) console.error(error); }); `); - }, [apiKey, labelsInput, dataInput, similarity]); + }, [apiKey, provider, model, labelsInput, dataInput, similarity]); // Handle classification const handleClassify = async () => { @@ -73,7 +77,6 @@ classify({ labels, data, config, apiKey }) setError(''); setResults([]); - // Parse labels and data const labels = labelsInput .split(',') .map((label) => label.trim()) @@ -97,7 +100,7 @@ classify({ labels, data, config, apiKey }) } if (!apiKey) { - setError('Please provide your OpenAI API Key.'); + setError('Please provide your Provider API Key.'); setLoading(false); return; } @@ -106,8 +109,10 @@ classify({ labels, data, config, apiKey }) const classificationResults = await classify({ labels, data, + provider, + model, config: { similarity }, - apiKey, // Pass the API Key here + apiKey, }); // Combine each data item with its classification result @@ -129,24 +134,41 @@ classify({ labels, data, config, apiKey })

AI Zero-Shot Classifier Demo

-

- Classify text data against predefined labels without training or - fine-tuning using AI. -

+

Classify text data against predefined labels using AI-powered embeddings.

Configuration

- + setApiKey(e.target.value)} />
+
+ + +
+
+ + setModel(e.target.value)} + /> +
{results.map((result, index) => (
  • -

    - Text: {result.text} -

    -

    - Label: {result.label} -

    -

    - Confidence:{' '} - {result.confidence.toFixed(4)} -

    +

    Text: {result.text}

    +

    Label: {result.label}

    +

    Confidence: {result.confidence.toFixed(4)}

  • ))} @@ -221,9 +236,7 @@ classify({ labels, data, config, apiKey }) @@ -231,4 +244,4 @@ classify({ labels, data, config, apiKey }) ); } -export default Demo; +export default Demo; \ No newline at end of file