JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 6
  • Score
    100M100P100Q41499F
  • License MIT

Zero-shot multimodal classification SDK - classify text and images with custom labels, no training required

Package Exports

  • zerolabel
  • zerolabel/dist/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (zerolabel) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

zerolabel

npm version TypeScript

Zero-shot multimodal classification SDK. Classify text and images with custom labelsβ€”no training required. Powered by Google Gemma 3-27B under the hood.

Features

✨ Zero-shot classification: No training data needed, just provide your labels
πŸ”€ Multimodal support: Classify text, images, or both together
⚑ Fast & reliable: Built-in retry logic and error handling
🎯 High accuracy: Powered by Google Gemma 3-27B
πŸ“¦ TypeScript-first: Full type safety and IntelliSense support
πŸš€ Simple API: Easy to integrate, minimal setup required

Installation

npm install zerolabel

Quick Start

import { classify } from 'zerolabel';

// Classify text
const results = await classify({
  texts: ['I love this product!'],
  labels: ['positive', 'negative', 'neutral'],
  inference_api_key: process.env.INFERENCE_API_KEY
});

console.log(results[0].predicted_label); // 'positive'
console.log(results[0].confidence); // 85.3

Authentication

Get your API key from inference.net or contact us for access.

Usage Examples

Text Classification

import { classify } from 'zerolabel';

const results = await classify({
  texts: [
    'The movie was amazing!',
    'I hate this service.',
    'It was okay, nothing special.'
  ],
  labels: ['positive', 'negative', 'neutral'],
  inference_api_key: process.env.INFERENCE_API_KEY
});

results.forEach((result, i) => {
  console.log(`Text ${i + 1}: ${result.predicted_label} (${result.confidence}%)`);
});

Image Classification

import { classify } from 'zerolabel';
import fs from 'fs';

// Convert image to base64
const imageBuffer = fs.readFileSync('path/to/image.jpg');
const imageBase64 = `data:image/jpeg;base64,${imageBuffer.toString('base64')}`;

const results = await classify({
  images: [imageBase64],
  labels: ['cat', 'dog', 'bird', 'other'],
  inference_api_key: process.env.INFERENCE_API_KEY
});

console.log(`Image contains: ${results[0].predicted_label}`);

Multimodal Classification (Text + Image)

const results = await classify({
  texts: ['Check out this cute animal!'],
  images: [imageBase64],
  labels: ['cute cat', 'cute dog', 'not cute', 'not animal'],
  inference_api_key: process.env.INFERENCE_API_KEY
});

Custom Criteria and Instructions

const results = await classify({
  texts: ['The AI model performed well on most tasks.'],
  labels: ['technical', 'non-technical'],
  criteria: 'Focus on the complexity and technical depth of the content',
  additionalInstructions: 'Consider industry jargon and technical terminology',
  inference_api_key: process.env.INFERENCE_API_KEY
});

Batch Processing

const results = await classify({
  texts: [
    'Great customer service!',
    'Product arrived damaged.',
    'Fast delivery, good packaging.',
    'Hard to contact support.'
  ],
  labels: ['service_issue', 'product_issue', 'delivery_issue', 'positive'],
  inference_api_key: process.env.INFERENCE_API_KEY
});

// Process results
results.forEach((result, i) => {
  console.log(`Review ${i + 1}: ${result.predicted_label}`);
  console.log(`Confidence: ${result.confidence}%`);
  console.log(`Probabilities:`, result.probabilities);
  console.log('---');
});

API Reference

ZeroLabelClient

Constructor

new ZeroLabelClient(config: ZeroLabelConfig)

Parameters:

  • config.inference_api_key (string, required): Your inference.net API key
  • config.maxRetries (number, optional): Max retry attempts (default: 3)

Note: All requests are proxied through inference.net - no custom endpoints or models allowed.

Methods

classify(input, options?)

Classify text and/or images against provided labels.

classify(input: ClassificationInput, options?: ClassificationOptions): Promise<ClassificationResult[]>

Parameters:

  • input.texts (string[], optional): Texts to classify
  • input.images (string[], optional): Images as base64 data URIs
  • input.labels (string[], required): Classification labels
  • input.criteria (string, optional): Additional evaluation criteria
  • input.additionalInstructions (string, optional): Extra instructions for the model

Returns: Promise<ClassificationResult[]>

ClassificationResult

interface ClassificationResult {
  text: string;                              // Original input text
  predicted_label: string;                   // Predicted label
  confidence: number;                        // Confidence score (0-100)
  probabilities: Record<string, number>;     // Probability distribution
  logprobs: Record<string, number | null>;   // Log probabilities
  all_logprobs: Record<string, number>;      // All token log probabilities
  prompt: string;                            // Generated prompt
}

Convenience Functions

Quick Classification

For simple use cases, use the classify function:

import { classify } from 'zerolabel';

const results = await classify({
  inference_api_key: 'your-inference-api-key',
  texts: ['Amazing product!'],
  labels: ['positive', 'negative']
});

Client Factory

import { createClient } from 'zerolabel';

const client = createClient({
  inference_api_key: 'your-inference-api-key',
  maxRetries: 5
});

Error Handling

The SDK throws ZeroLabelError for various error conditions:

import { ZeroLabelError } from 'zerolabel';

try {
  const results = await client.classify({
    texts: ['Hello world'],
    labels: [] // Empty labels will throw an error
  });
} catch (error) {
  if (error instanceof ZeroLabelError) {
    console.error(`Error: ${error.message}`);
    console.error(`Code: ${error.code}`);
    console.error(`Status: ${error.statusCode}`);
  }
}

Configuration

Environment Variables

You can set your API key using environment variables:

export INFERENCE_API_KEY="your-inference-api-key"
const client = new ZeroLabelClient({
  inference_api_key: process.env.INFERENCE_API_KEY!
});

Custom Configuration

const client = new ZeroLabelClient({
  inference_api_key: 'your-inference-api-key',
  maxRetries: 5
});

Note: baseUrl and model are not configurable - all requests go through inference.net.

TypeScript Support

The SDK is built with TypeScript and provides full type safety:

import type { 
  ZeroLabelConfig,
  ClassificationInput,
  ClassificationResult,
  ClassificationOptions 
} from 'zerolabel';

// All types are available for import
const config: ZeroLabelConfig = {
  inference_api_key: 'your-inference-api-key'
};

Best Practices

  1. Reuse client instances for better performance
  2. Use descriptive labels for better accuracy
  3. Batch multiple inputs when possible
  4. Handle errors gracefully with try-catch blocks
  5. Set appropriate retry limits based on your use case

Support

License

MIT License - see LICENSE file for details.