Zero-Shot Classification

Classify text into custom labels at request time — no training required

You send a single `text` and a list of candidate `labels`. The service scores each label against the text using a Natural Language Inference model and returns the top label, its score, and an `all_scores` map of every label → score. No training step. Synchronous. Note: the response uses an `all_scores` object (label → score), not an array of `[label, score]` pairs. Earlier docs were wrong.

textanalysisnlp

Overview

Features

Custom labels at request time

No training step. Provide any set of labels and the model scores each against the input.

Zero-shot via NLI

For each candidate label a hypothesis is constructed and scored as entailment of the text.

Single best + all scores

Response includes the top label and a complete label→score map for the rest.

Multilingual

Works in any language the underlying NLI model supports — keep labels in the same language as the text for best results.

Use Cases

Ticket routing

Classify support tickets into departments (billing / technical / sales) without training a custom model.

Content tagging

Assign custom tags to articles, reviews, or posts from an arbitrary label set.

Intent detection

Detect user intent (greeting, question, complaint, request) from a label list.

Input / Output

Input

text: string + labels: array of strings

JSON body

Output

label, score, all_scores (label → score map)

JSON

Specs

Latency
~1-3 s (scales with number of labels)
Async
false
Rate Limit
Per API key
Max Input
Model-dependent, typically 512 tokens for the text

Quickstart

Prerequisites

  • -A CN8 Gateway API key with text-classify in allowed_services

1. Classify with custom labels

text-classify

POST text + a labels array. The service returns the best label, its score, and the score for every candidate.

POST/v1/proxy/text-classify
{
  "text": "This new phone has amazing battery life and a great camera.",
  "labels": ["technology", "food", "sports"]
}

Response

{
  "status": "success",
  "data": {
    "label": "technology",
    "score": 0.7642,
    "all_scores": {
      "technology": 0.7642,
      "sports": 0.0023,
      "food": 0.0001
    }
  }
}

Use the same language for labels as the input text. all_scores is an object (dict), not an array of pairs.

Zero-Shot Classification

POSTsync

Score user-defined labels against a text via NLI. Returns top label + an all_scores map.

/v1/proxy/text-classify

Pricing

Billed per request, independent of number of labels.

ServiceUnitPrice
Zero-Shot Classificationitem$0.006/request

Guides & Tips

Important Notes (verified against the live upstream)

  • -Single text per call — the request body is `text` (string), not a `texts` array.
  • -`all_scores` is a dict, not a list of `[label, score]` pairs. Earlier docs were wrong.
  • -Optional flags `label_descriptions`, `multi_label`, `threshold` are silently
  • -accepted but do not change the response shape. They appear to have no effect
  • -on the live upstream — treat them as best-effort.
  • -Cost is per request, not per label.

How it works

  • -For each candidate label a hypothesis like "This example is about X" is built.
  • -The model scores how well the text entails each hypothesis using NLI.
  • -The top label is exposed at `data.label`; the full ranking lives in `all_scores`.

Tips for best results

  • -Keep the label set small (3–20 labels). More labels means more inference time.
  • -Use labels in the same language as the input text.
  • -For nuanced taxonomies with example texts per class, use Few-Shot Classification.

FAQ

Q: How do I rank all labels?

A: Sort the all_scores object by its values (descending). The top entry equals data.label.

Q: Can I do multi-label?

A: The flag is accepted but the response shape is the same — apply your own threshold to all_scores.

Q: What if I have example texts per category?

A: Use Few-Shot Classification — it embeds your examples and computes class prototypes.

Related Products

Changelog

1.2 (2026-04-29)

  • -Aligned to live upstream: response is flat `{label, score, all_scores}` (no results[] wrapper).
  • -Fixed `all_scores` shape: it is an object, not a list of [label, score] pairs.
  • -Documented that label_descriptions / multi_label / threshold flags have no observable effect today.

1.1 (2026-02-23)

  • -Aligned with zero_shot_classifier prose (now superseded).

1.0 (2026-01-26)

  • -Initial catalog.