Agent Platform のマルチモーダル データセットを使用すると、生成 AI 用のマルチモーダル データセットを作成、管理、共有、使用できます。マルチモーダル データセットには、次の主な機能があります。
データセットは BigQuery、DataFrame、または Cloud Storage 内の JSONL ファイルから読み込むことができます。
データセットを一度作成して、教師ありファインチューニングやバッチ予測など、さまざまなジョブタイプで使用します。これにより、データの重複や形式の問題を防ぐことができます。
すべての生成 AI データセットを 1 つのマネージド ロケーションに保存します。
スキーマと構造を検証し、ダウンストリーム タスクに必要なリソースを定量化することで、タスクを開始する前にエラーを検出し、費用を見積もることができます。
マルチモーダル データセットは、Agent Platform SDK または REST API を使用して利用できます。
マルチモーダル データセットは、Agent Platform のマネージド データセットの一種です。他のタイプのマネージド データセットとは次の点で異なります。
- マルチモーダル データセットには、任意のモダリティ(テキスト、画像、音声、動画)のデータを含めることができます。他のタイプのマネージド データセットは、単一のモダリティ専用です。
- マルチモーダル データセットは、Agent Platform の生成 AI サービス(生成モデルを使用したチューニングやバッチ予測など)でのみ使用できます。他のマネージド データセット タイプは、Agent Platform 予測モデルでのみ使用できます。
- マルチモーダル データセットは、データのプレビュー、リクエストの検証、費用の見積もりに使用される
assembleやassessなどの追加メソッドをサポートしています。 - マルチモーダル データセットは、大規模なデータセット用に最適化された BigQuery に保存されます。
始める前に
- アカウントにログインします。 Google Cloud を初めて使用する場合は、 アカウントを作成して、実際のシナリオで Google プロダクトのパフォーマンスを評価してください。 Google Cloud新規のお客様には、ワークロードの実行、テスト、デプロイができる無料クレジット $300 分を差し上げます。
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
Enable the Agent Platform, BigQuery, and Cloud Storage APIs.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles.-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
Enable the Agent Platform, BigQuery, and Cloud Storage APIs.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles.- Agent Platform SDK for Python をインストールして初期化する
- 次のライブラリをインポートする。
from google.cloud.aiplatform.preview import datasets # To use related features, you may also need to import some of the following features: from vertexai.preview.tuning import sft from vertexai.batch_prediction import BatchPredictionJob from vertexai.generative_models import Content, Part, Tool, ToolConfig, SafetySetting, GenerationConfig, FunctionDeclaration
データセットを作成する
さまざまなソースからマルチモーダル dataset を作成できます。
Pandas DataFrame から
my_dataset = datasets.MultimodalDataset.from_pandas( dataframe=my_dataframe, target_table_id=table_id # optional )-
my_dataset = datasets.MultimodalDataset.from_bigframes( dataframe=my_dataframe, target_table_id=table_id # optional ) BigQuery テーブルから
my_dataset_from_bigquery = datasets.MultimodalDataset.from_bigquery( bigquery_uri=f"bq://projectId.datasetId.tableId" )BigQuery テーブルから REST API を使用して
curl -X POST \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json" \ "https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT/locations/LOCATION/datasets" \ -d '{ "display_name": "TestDataset", "metadataSchemaUri": "gs://google-cloud-aiplatform/schema/dataset/metadata/multimodal_1.0.0.yaml", "metadata": { "inputConfig": { "bigquery_source": { "uri": "bq://projectId.datasetId.tableId" } } } }'Cloud Storage の JSONL ファイルから読み込みます。次の例では、JSONL ファイルに Gemini 用にすでにフォーマットされたリクエストが含まれているため、アセンブリは必要ありません。
my_dataset = datasets.MultimodalDataset.from_gemini_request_jsonl( gcs_uri = gcs_uri_of_jsonl_file, )既存のマルチモーダル データセットから
# Get the most recently created dataset first_dataset = datasets.MultimodalDataset.list()[0] # Load dataset based on its name same_dataset = datasets.MultimodalDataset(first_dataset.name)
テンプレートを作成して適用する
テンプレートは、マルチモーダル データセットをモデルに渡すことができる形式に変換する方法を定義します。これは、チューニング ジョブまたはバッチ予測ジョブの実行に必要です。
Agent Platform SDK
テンプレートを作成します。テンプレートを作成する方法は 2 つあります。
construct_single_turn_templateヘルパー メソッドを使用します。
template_config = datasets.construct_single_turn_template( prompt="This is the image: {image_uris}", response="{labels}", system_instruction='You are a botanical image classifier. Analyze the provided image ' 'and determine the most accurate classification of the flower.' 'These are the only flower categories: [\'daisy\', \'dandelion\', \'roses\', \'sunflowers\', \'tulips\'].' 'Return only one category per image.' )GeminiExampleからテンプレートを手動で作成します。これにより、マルチターンの会話など、より細かい粒度が可能になります。次のコードサンプルには、field_mappingを指定するためのコメントアウトされたコードも含まれています。これにより、データセットの列名とは異なるプレースホルダ名を使用できます。次に例を示します。
# Define a GeminiExample gemini_example = datasets.GeminiExample( contents=[ Content(role="user", parts=[Part.from_text("This is the image: {image_uris}")]), Content(role="model", parts=[Part.from_text("This is the flower class: {label}.")]), Content(role="user", parts=[Part.from_text("Your response should only contain the class label.")]), Content(role="model", parts=[Part.from_text("{label}")]), # Optional: If you specify a field_mapping, you can use different placeholder values. For example: # Content(role="user", parts=[Part.from_text("This is the image: {uri_placeholder}")]), # Content(role="model", parts=[Part.from_text("This is the flower class: {flower_placeholder}.")]), # Content(role="user", parts=[Part.from_text("Your response should only contain the class label.")]), # Content(role="model", parts=[Part.from_text("{flower_placeholder}")]), ], system_instruction=Content( parts=[ Part.from_text( 'You are a botanical image classifier. Analyze the provided image ' 'and determine the most accurate classification of the flower.' 'These are the only flower categories: [\'daisy\', \'dandelion\', \'roses\', \'sunflowers\', \'tulips\'].' 'Return only one category per image.' ) ] ), ) # construct the template, specifying a map for the placeholder template_config = datasets.GeminiTemplateConfig( gemini_example=gemini_example, # Optional: Map the template placeholders to the column names of your dataset. # Not required if the template placesholders are column names of the dataset. # field_mapping={"uri_placeholder": "image_uris", "flower_placeholder": "labels"}, )データセットに接続します。
my_dataset.attach_template_config(template_config=template_config)
REST
patch メソッドを呼び出し、metadata フィールドを次のように更新します。
- BigQuery テーブルの URI。BigQuery テーブルから作成されたデータセットの場合、これはソース
bigquery_uriです。JSONL や DataFrame などの他のソースから作成されたデータセットの場合、これはデータがコピーされた BigQuery テーブルです。 gemini_template_config。
curl -X PATCH \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
-d $'{
"metadata": {
"input_config": {
"bigquery_source": {
"uri": "bq://projectId.datasetId.tableId"
}
},
"gemini_template_config_source": {
"gemini_template_config": {
"gemini_example": {
"contents": [
{
"role": "user",
"parts": [
{
"text": "This is the image: {image_uris}"
}
]
},
{
"role": "model",
"parts": [
{
"text": "response"
}
]
}
]
"systemInstruction": {
"parts": [
{
"text": "You are a botanical image classifier."
}
]
}
}
}
}
}
}' \
"https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID?updateMask=metadata"
(省略可)データセットを組み立てる
assemble メソッドは、テンプレートを適用してデータセットを変換し、出力を新しい BigQuery テーブルに保存します。これにより、モデルに渡される前にデータをプレビューできます。
デフォルトでは、データセットに添付された template_config が使用されますが、テンプレートを指定してデフォルトの動作をオーバーライドできます。
Agent Platform SDK
table_id, assembly = my_dataset.assemble(template_config=template_config)
# Inspect the results
assembly.head()
REST
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
"https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID:assemble" \
-d '{}'
たとえば、マルチモーダル データセットに次のデータが含まれているとします。
| 行 | image_uris | ラベル |
|---|---|---|
| 1 | gs://cloud-samples-data/ai-platform/flowers/daisy/1396526833_fb867165be_n.jpg | デイジー |
次に、assemble メソッドは、各行にリクエスト本文を含む table_id という名前の新しい BigQuery テーブルを作成します。次に例を示します。
{
"contents": [
{
"parts": [
{
"text": "This is the image: "
},
{
"fileData": {
"fileUri": "gs://cloud-samples-data/ai-platform/flowers/daisy/1396526833_fb867165be_n.jpg",
"mimeType": "image/jpeg"
}
}
],
"role": "user"
},
{
"parts": [
{
"text": "daisy"
}
],
"role": "model"
}
],
"systemInstruction": {
"parts": [
{
"text": "You are a botanical image classifier. Analyze the provided image and determine the most accurate classification of the flower.These are the only flower categories: ['daisy', 'dandelion', 'roses', 'sunflowers', 'tulips'].Return only one category per image."
}
]
}
}
モデルをチューニングする
マルチモーダル データセットを使用して Gemini モデルをチューニングできます。
(省略可)データセットを検証する
データセットを評価して、データセットの形式エラーやモデルエラーなどのエラーが含まれているかどうかを確認します。
Agent Platform SDK
assess_tuning_validity() を呼び出します。デフォルトでは、データセットに添付された template_config が使用されますが、テンプレートを指定してデフォルトの動作をオーバーライドできます。
# Attach template
my_dataset.attach_template_config(template_config=template_config)
# Validation for tuning
validation = my_dataset.assess_tuning_validity(
model_name="gemini-2.5-flash",
dataset_usage="SFT_TRAINING"
)
# Inspect validation result
validation.errors
REST
assess メソッドを呼び出し、TuningValidationAssessmentConfig を指定します。
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
"https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID:assess" \
-d '{
"tuningValidationAssessmentConfig": {
"modelName": "projects/PROJECT_ID/locations/LOCATION/models/gemini-2.5-flash",
"datasetUsage": "SFT_TRAINING"
}
}'
(省略可)リソース使用量を推定する
データセットを評価して、チューニング ジョブのトークン数と課金対象文字数を取得します。
Agent Platform SDK
assess_tuning_resources() を呼び出します。
# Resource estimation for tuning.
tuning_resources = my_dataset.assess_tuning_resources(
model_name="gemini-2.5-flash"
)
print(tuning_resources)
# For example, TuningResourceUsageAssessmentResult(token_count=362688, billable_character_count=122000)
REST
assess メソッドを呼び出し、TuningResourceUsageAssessmentConfig を指定します。
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
"https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID:assess" \
-d '{
"tuningResourceUsageAssessmentConfig": {
"modelName": "projects/PROJECT_ID/locations/LOCATION/models/gemini-2.5-flash"
}
}'
チューニング ジョブを実行する
Agent Platform SDK
from vertexai.tuning import sft
sft_tuning_job = sft.train(
source_model="gemini-2.5-flash",
# Pass the Vertex Multimodal Datasets directly
train_dataset=my_multimodal_dataset,
validation_dataset=my_multimodal_validation_dataset,
)
Google Gen AI SDK
from google import genai
from google.genai.types import HttpOptions, CreateTuningJobConfig
client = genai.Client(http_options=HttpOptions(api_version="v1"))
tuning_job = client.tunings.tune(
base_model="gemini-2.5-flash",
# Pass the resource name of the Multimodal Dataset, not the dataset object
training_dataset={
"vertex_dataset_resource": my_multimodal_dataset.resource_name
},
# Optional
config=CreateTuningJobConfig(
tuned_model_display_name="Example tuning job"),
)
詳細については、チューニング ジョブを作成するをご覧ください。
バッチ予測
マルチモーダル データセットを使用してバッチ予測を取得できます。
(省略可)データセットを検証する
データセットを評価して、データセットの形式エラーやモデルエラーなどのエラーが含まれているかどうかを確認します。
Agent Platform SDK
assess_batch_prediction_validity() を呼び出します。デフォルトでは、データセットに添付された template_config が使用されますが、テンプレートを指定してデフォルトの動作をオーバーライドできます。
# Attach template
my_dataset.attach_template_config(template_config=template_config)
# Validation for batch prediction
validation = my_dataset.assess_batch_prediction_validity(
model_name="gemini-2.5-flash",
dataset_usage="SFT_TRAINING"
)
# Inspect validation result
validation.errors
REST
assess メソッドを呼び出し、batchPredictionValidationAssessmentConfig を指定します。
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
"https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID:assess" \
-d '{
"batchPredictionValidationAssessmentConfig": {
"modelName": "projects/PROJECT_ID/locations/LOCATION/models/gemini-2.5-flash",
}
}'
(省略可)リソース使用量を推定する
データセットを評価して、ジョブのトークン数を取得します。
Agent Platform SDK
assess_batch_prediction_resources() を呼び出します。
batch_prediction_resources = my_dataset.assess_batch_prediction_resources(
model_name="gemini-2.5-flash"
)
print(batch_prediction_resources)
# For example, BatchPredictionResourceUsageAssessmentResult(token_count=362688, audio_token_count=122000)
REST
assess メソッドを呼び出し、batchPredictionResourceUsageAssessmentConfig を指定します。
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
"https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID:assess" \
-d '{
"batchPredictionResourceUsageAssessmentConfig": {
"modelName": "projects/PROJECT_ID/locations/LOCATION/models/gemini-2.5-flash"
}
}'
バッチ予測ジョブを実行する
マルチモーダル データセットを使用してバッチ予測を行うには、組み立てられた出力の BigQuery table_id を渡します。
Agent Platform SDK
from vertexai.batch_prediction import BatchPredictionJob
# Dataset needs to have an attached template_config to batch prediction
my_dataset.attach_template_config(template_config=template_config)
# assemble dataset to get assembly table id
assembly_table_id, _ = my_dataset.assemble()
batch_prediction_job = BatchPredictionJob.submit(
source_model="gemini-2.5-flash",
input_dataset=assembly_table_id,
)
Google Gen AI SDK
from google import genai
client = genai.Client(http_options=HttpOptions(api_version="v1"))
# Attach template_config and assemble dataset
my_dataset.attach_template_config(template_config=template_config)
assembly_table_id, _ = my_dataset.assemble()
job = client.batches.create(
model="gemini-2.5-flash",
src=assembly_table_id,
)
詳細については、バッチ予測ジョブをリクエストするをご覧ください。
制限事項
マルチモーダル データセットは、生成 AI 機能でのみ使用できます。AutoML トレーニングやカスタム トレーニングなどの非生成 AI 機能では使用できません。
マルチモーダル データセットは、Gemini などの Google モデルでのみ使用できます。サードパーティのモデルでは使用できません。
料金
モデルをチューニングしたり、バッチ予測ジョブを実行したりすると、生成 AI の使用量と BigQuery でのデータセットのクエリに対して課金されます。
マルチモーダル データセットの作成、組み立て、評価を行うと、BigQuery でのマルチモーダル データセットの保存とクエリに対して課金されます。具体的には、次のオペレーションはこれらの基盤となるサービスを使用します。
Create個のデータセット- 既存の BigQuery テーブルまたは DataFrame から作成されたデータセットには、追加のストレージ費用は発生しません。これは、データの別のコピーを保存するのではなく、論理ビューを使用するためです。
- 他のソースから作成されたデータセットは、データを新しい BigQuery テーブルにコピーするため、BigQuery でストレージ費用が発生します。たとえば、アクティブな論理ストレージの場合、1 GiB あたり月額 $0.02 です。
Assemble個のデータセットこのメソッドは、モデル リクエスト形式の完全なデータセットを含む新しい BigQuery テーブルを作成します。これにより、BigQuery でストレージ費用が発生します。たとえば、アクティブな論理ストレージの場合、1 GiB あたり月額 $0.02 です。
このメソッドはデータセットを 1 回読み取るため、BigQuery でクエリ費用が発生します。たとえば、オンデマンド コンピューティングの料金は TiB あたり $6.25 です。
Assessはデータセットを 1 回読み取るため、BigQuery でクエリ費用が発生します。たとえば、オンデマンド コンピューティングの料金は TiB あたり $6.25 です。
料金計算ツールを使うと、予想使用量に基づいて費用の見積もりを出すことができます。