Creating a dataset for tuning a text generation model
Getting started
To use the examples:
You can start working from the management console right away.
-
Create a service account and assign the
ai.editorrole to it. -
Get the service account API key and save it.
The following examples use API key authentication. Yandex Cloud ML SDK also supports IAM token and OAuth token authentication. For more information, see Authentication in Yandex Cloud ML SDK.
-
Use the pip
package manager to install the ML SDK library:pip install yandex-cloud-ml-sdk
-
Get API authentication credentials as described in Authentication with the Yandex AI Studio API.
-
To use the examples, install cURL
. -
Install gRPCurl
. -
(Optional) Install the jq
JSON stream processor. -
Get an IAM token used for authentication in the API.
Note
The IAM token has a short lifetime: no more than 12 hours.
Upload the dataset
Prepare UTF-8
Create a tuning dataset:
-
In the management console
, select the folder for which your account has theai.playground.userandai.datasets.editorroles or higher. -
In the list of services, select AI Studio.
-
In the left-hand panel, click
Datasets. -
Click Create dataset.
-
Enter a name and descriptions for the dataset. Follow these naming requirements:
- It must be from 2 to 63 characters long.
- It can only contain lowercase Latin letters, numbers, and hyphens.
- It must start with a letter and cannot end with a hyphen.
-
In the Type field, select Text generation.
-
Optionally, add or delete dataset labels. You can use them to split or join resources into logical groups.
-
Click Select file or drag the JSON file you created earlier to the loading area.
-
Click Create dataset.
-
Create a file named
dataset-create.pyand add the following code to it:#!/usr/bin/env python3 from __future__ import annotations import pathlib from yandex_cloud_ml_sdk import YCloudML from yandex_cloud_ml_sdk.exceptions import DatasetValidationError def main() -> None: sdk = YCloudML( folder_id="<folder_ID>", auth="<API_key>", ) # Viewing the list of all previously uploaded datasets for dataset in sdk.datasets.list(): print(f"List of existing datasets {dataset=}") # Deleting all previously uploaded datasets for dataset in sdk.datasets.list(): dataset.delete() # Creating a tuning dataset for the YandexGPT Lite base model dataset_draft = sdk.datasets.draft_from_path( task_type="TextToTextGeneration", path="<file_path>", upload_format="jsonlines", name="YandexGPT Lite tuning", ) # Waiting for the data to be uploaded and the dataset to be created operation = dataset_draft.upload_deferred() tuning_dataset = operation.wait() print(f"new {tuning_dataset=}") if __name__ == "__main__": main()Where:
-
<folder_ID>: ID of the folder the service account was created in. -
<API_key>: Service account API key you got earlier required for authentication in the API.The following examples use API key authentication. Yandex Cloud ML SDK also supports IAM token and OAuth token authentication. For more information, see Authentication in Yandex Cloud ML SDK.
-
<file_path>: Path to the file containing the ready-made examples for model tuning.
-
-
Run the file you created:
python3 dataset-create.pyResult:
new tuning_dataset=Dataset(id='fdsv21bmp09v********', folder_id='b1gt6g8ht345********', name= 'YandexGPT Lite tuning', description=None, metadata=None, created_by='ajegtlf2q28a********', created_at=datetime.datetime(2025, 3, 12, 19, 31, 44), updated_at=datetime.datetime(2025, 3, 12, 19, 32, 20), labels=None, allow_data_logging=False, status=<DatasetStatus.READY: 3>, task_type='TextToTextGeneration', rows=3, size_bytes=3514, validation_errors=())Save the new dataset's ID (the
idfield value): you will need it to fine-tune the model.
-
Create a dataset:
grpcurl \ -H "Authorization: Bearer <IAM_token>" \ -d @ \ llm.api.cloud.yandex.net:443 yandex.cloud.ai.dataset.v1.DatasetService/Create <<EOM { "folder_id": "<folder_ID>", "name": "My awesome dataset", "task_type": "TextToTextGeneration", "upload_format": "jsonlines" } EOMWhere:
<IAM_token>: IAM token of the service account you got before you started.<folder_ID>: ID of the folder you are creating the dataset in.
Result:
{ "datasetId": "fdso08c1u1cq********", "dataset": { "datasetId": "fdso08c1u1cq********", "folderId": "b1gt6g8ht345********", "name": "My awesome dataset", "status": "DRAFT", "taskType": "TextToTextGeneration", "createdAt": "2025-01-20T10:36:50Z", "updatedAt": "2025-01-20T10:36:50Z", "createdById": "ajeg2b2et02f********", "createdBy": "ajeg2b2et02f********" } }Save the new dataset's ID (the
datasetIdfield value): you will need it to upload data to the dataset. -
Get a link to upload data into the dataset:
grpcurl \ -H "Authorization: Bearer <IAM_token>" \ -d '{"dataset_id": "<dataset_ID>", "size_bytes": <dataset_size>}' \ llm.api.cloud.yandex.net:443 yandex.cloud.ai.dataset.v1.DatasetService/GetUploadDraftUrl | jqWhere:
<IAM_token>: IAM token of the service account you got before you started.<dataset_ID>: Dataset ID you saved in the previous step.<dataset_size>: Size in bytes of the file with data for tuning. In the terminal, you can get the file size using thels -l <file_path>command.
Result:
{ "datasetId": "fdso08c1u1cq********", "uploadUrl": "https://storage.yandexcloud.net/ai-fomo-drafts-prod/b1gt6g8ht345********/fdso08c1u1cq********?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20250120T105352Z&X-Amz-SignedHeaders=content-length%3Bhost&X-Amz-Expires=86400&X-Amz-Credential=YCAJE_WuJJ9D1r6huCoc8I3yO%2F20250120%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Signature=611d7951994ae939acf4d32cc0c154c738d02adb2a04707a704f34ca********" }The
uploadUrlfield of the response contains a link you can use to upload your data into the dataset.Tip
If you did not use jq, replace all
\u0026occurrences with&in the link to use it to upload the dataset. -
Upload your data by specifying the link you got in the previous step and the path to the fine-tuning data file:
curl \ --request PUT \ --upload-file <file_path> \ "<link>" -
After the data upload is complete, run the dataset validation:
grpcurl \ -H "Authorization: Bearer <IAM_token>" \ -d '{"dataset_id": "<dataset_ID>"}' \ llm.api.cloud.yandex.net:443 yandex.cloud.ai.dataset.v1.DatasetService/ValidateWhere:
<IAM_token>: IAM token of the service account you got before you started.<dataset_ID>: Dataset ID you saved in the previous step.
Result:
{ "id": "fdso01v2jdd4********", "createdAt": "2025-01-20T11:03:48Z", "modifiedAt": "2025-01-20T11:03:48Z" }Save the validation operation ID (
idfield). You will need it in the next step. -
Dataset validation may take some time. To find out validation status and get an error report (if any), send this request:
grpcurl \ -H "Authorization: Bearer <IAM_token>" \ -d '{"operation_id": "<validation_operation_ID>"}' \ llm.api.cloud.yandex.net:443 yandex.cloud.operation.OperationService/GetWhere:
<IAM_token>: IAM token of the service account you got before you started.<validation_operation_ID>: ID of the validation operation you saved in the previous step.
Result:
{ "id": "fdso01v2jdd4********", "createdAt": "2025-01-20T11:03:48Z", "modifiedAt": "2025-01-20T11:04:46Z", "done": true, "response": { "@type": "type.googleapis.com/yandex.cloud.ai.dataset.v1.ValidateDatasetResponse", "datasetId": "fdso08c1u1cq********", "isValid": true } }The
isValidfield is set totrue. This means the loaded dataset was validated successfully.