Using fine-tuned classifiers based on YandexGPT
To run a request to the classifier of a model fine-tuned in DataSphere, use the classify Text Classification API method.
Getting started
Get API authentication credentials as described in Authentication with the Yandex Foundation Models API.
Send a request to the classifier
To send a request to the classifier:
To use the examples, install cURL
The example below is intended to be run in MacOS and Linux. To run it in Windows, see how to work with Bash in Microsoft Windows.
-
Create a file with the request body, e.g.,
body.json
:{ "modelUri": "cls://<folder_ID>/<classifier_ID>", "text": "<prompt_text>" }
Where:
modelUri
: ID of the model that will be used to classify the message. The parameter contains Yandex Cloud folder ID and the ID of the model tuned in DataSphere.text
: Message text. The total number of tokens per request must not exceed 8,000.
The names of the classes between which the model will be distributing requests must be specified during model tuning; therefore, they are not provided in the request.
-
Send a request to the classifier by running the following command:
export IAM_TOKEN=<IAM_token> curl \ --request POST \ --header "Authorization: Bearer ${IAM_TOKEN}" \ --data "@<path_to_request_body_file>" \ "https://llm.api.cloud.yandex.net:443/foundationModels/v1/textClassification"
Note
The
https://llm.api.cloud.yandex.net:443/foundationModels/v1/textClassification
endpoint works only with fine-tuned classifiers. For prompt-based classifiers, usehttps://llm.api.cloud.yandex.net/foundationModels/v1/fewShotTextClassification
.In the response, the service will return the classification results with the
confidence
values for the probability of classifying the request text into each class:{ "predictions": [ { "label": "<class_1_name>", "confidence": 0.00010150671005249023 }, { "label": "<class_2_name>", "confidence": 0.000008225440979003906 }, ... { "label": "<class_n_name>", "confidence": 0.93212890625 } ], "modelVersion": "<model_version>" }
In multi-class classification, the sum of the
confidence
values for all classes is always1
.In multi-label classification, the
confidence
value for each class is calculated independently (the sum of the values is not equal to1
).