Some texts (or images) belong to more than one category—think hashtags, product facets, or moderation flags. With LLMs you can ask for all applicable labels in one go.
In the example below, we provide a news headline and ask the model to return all relevant labels from a predefined list—such as space, science, technology, and climate. Multiple labels can be assigned to a single input. The special label none is included to indicate when no categories are applicable, which is great in cases where the input is not relevant to any of the labels.
Copy
Ask AI
curl https://api.inference.net/v1/chat/completions \ -H "Authorization: Bearer $INFERENCE_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "meta-llama/llama-3.2-11b-instruct/fp-16", "messages": [ { "role": "system", "content": "You are a multi-label classifier. Given a headline and a list of possible labels, return all applicable labels as an array. Only include labels from the provided list. If none apply, return [\"none\"]. Respond only with the array of matching labels." }, { "role": "user", "content": "Headline: \"Russia funds new AI climate project\"" } ], "response_format": { "type": "json_schema", "json_schema": { "name": "news_tags", "strict": true, "schema": { "type": "object", "properties": { "labels": { "type": "array", "items": { "type": "string", "enum": ["space","science","technology","climate", "none"] } } }, "required": ["labels"], "additionalProperties": false } } } }'