Send a Text Classification Request
Use the /classify endpoint to classify one or more text
inputs.
curl -X POST \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header "Authorization: Bearer $API_KEY" \
--cacert "$SECRETS_DIR/cert.pem" \
--data '{
"model": "twitter-roberta-base-sentiment-latest",
"input": [
"I loved the service.",
"The experience was frustrating."
]
}' \
https://localhost:9091/classifyThe request body includes the following parameters:
model: The name of the text classification model to use.input: A string or an array of strings to classify.
The response includes a classification result for each input string. Each result includes the input index, predicted label, class probabilities, and number of classes.
{
"id": "classify-814098a1f6521d7e",
"model": "twitter-roberta-base-sentiment-latest",
"data": [
{
"index": 0,
"label": "positive",
"probs": [
0.005621818359941244,
0.02003072202205658,
0.9743474125862122
],
"num_classes": 3
},
{
"index": 1,
"label": "negative",
"probs": [
0.9102542400360107,
0.08134238421916962,
0.008403426967561245
],
"num_classes": 3
}
],
"usage": {
"prompt_tokens": 14,
"total_tokens": 14,
"completion_tokens": 0
}
}The response includes the following fields:
id: A unique identifier for the classification request.model: The name of the model used for classification.data: An array of classification results.index: The position of the input text in the request.label: The predicted class label.probs: The probability for the model's classes.num_classes: The number of classes returned by the model.usage: Token usage information for the request.
Parent topic: Use the Text Classification Service