Inference Providers documentation

Text Classification

Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

Text Classification

Text Classification is the task of assigning a label or class to a given text. Some use cases are sentiment analysis, natural language inference, and assessing grammatical correctness.

For more details about the text-classification task, check out its dedicated page! You will find examples and related materials.

Recommended models

Explore all available models and find the one that suits you best here.

Using the API

import os
from huggingface_hub import InferenceClient

client = InferenceClient(
    provider="hf-inference",
    api_key=os.environ["HF_TOKEN"],
)

result = client.text_classification(
    "I like you. I love you",
    model="BAAI/bge-reranker-v2-m3",
)

API specification

Request

Headers
authorizationstringAuthentication header in the form 'Bearer: hf_****' when hf_**** is a personal user access token with “Inference Providers” permission. You can generate one from your settings page.
Payload
inputs*stringThe text to classify
parametersobject
        function_to_applyenumPossible values: sigmoid, softmax, none.
        top_kintegerWhen specified, limits the output to the top K most probable classes.

Response

Body
(array)object[]Output is an array of objects.
        labelstringThe predicted class label.
        scorenumberThe corresponding probability.
Update on GitHub