HuggingFace — Zero-shot Text Classification
hf_inference.nlp.zero_shotClassify text into any custom set of categories without requiring model fine-tuning or training data. Provide a list of 2–20 candidate labels; the model determines which best describes the input text. Returns labels ranked by confidence score. Supports multi-label mode (text can match multiple categories). Default model: facebook/bart-large-mnli. Ideal for routing, content moderation, intent detection, and ad-hoc categorization tasks.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| text | Yes | Input text to process. Maximum ~10,000 characters depending on model context window. | |
| model | No | HuggingFace model ID to use for zero-shot classification. Default: "facebook/bart-large-mnli" (MNLI-trained, accurate but slower). Alternatives: "cross-encoder/nli-deberta-v3-small" (lighter and faster). | |
| multi_label | No | If true, scores are independent for each label (text can match multiple categories simultaneously). If false (default), scores are mutually exclusive and sum to 1 (single best category). | |
| candidate_labels | Yes | List of candidate category labels to classify the text into (2–20 labels). Example: ["politics", "sports", "technology", "entertainment"]. Labels can be any descriptive phrases — the model performs inference without prior training on these labels. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| error | No | Present only when the call failed. Includes error code, message, request_id, and any provider-specific extras. | |
| result | No | Tool response payload. Shape varies per tool — consult the tool description and inputSchema. May be an object, array, string, or number depending on the upstream provider response. |