Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Googleapis Python genai TuningDataset Setup

From Leeroopedia
Knowledge Sources
Domains Fine_Tuning, Data_Preparation
Last Updated 2026-02-15 00:00 GMT

Overview

Concrete tool for specifying training datasets for model fine-tuning provided by the google-genai types module.

Description

TuningDataset is a Pydantic model that specifies the training data source for a fine-tuning job. It supports three mutually exclusive sources: gcs_uri (JSONL file in Google Cloud Storage), vertex_dataset_resource (Vertex AI Multimodal Dataset), or examples (inline list of TuningExample objects). Only one source should be set per TuningDataset instance.

Usage

Create a TuningDataset with the appropriate data source. For production workflows, use gcs_uri pointing to a JSONL file. For quick experiments, use inline examples. Pass the TuningDataset to tunings.tune as the training_dataset parameter.

Code Reference

Source Location

Signature

class TuningDataset(_common.BaseModel):
    """Supervised fine-tuning training dataset."""
    gcs_uri: Optional[str] = None
    vertex_dataset_resource: Optional[str] = None
    examples: Optional[list[TuningExample]] = None

Import

from google.genai import types

I/O Contract

Inputs

Name Type Required Description
gcs_uri Optional[str] No* GCS URI of JSONL training data (*one source required)
vertex_dataset_resource Optional[str] No* Vertex AI Dataset resource name
examples Optional[list[TuningExample]] No* Inline training examples

Outputs

Name Type Description
TuningDataset TuningDataset Dataset specification to pass to tunings.tune

Usage Examples

GCS URI Dataset

from google.genai import types

dataset = types.TuningDataset(
    gcs_uri="gs://my-bucket/training_data.jsonl"
)

Inline Examples

from google.genai import types

dataset = types.TuningDataset(
    examples=[
        types.TuningExample(
            text_input="Classify: I love this product",
            output="positive"
        ),
        types.TuningExample(
            text_input="Classify: Terrible experience",
            output="negative"
        ),
        types.TuningExample(
            text_input="Classify: It was okay",
            output="neutral"
        ),
    ]
)

Related Pages

Implements Principle

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment