

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 準備資料以微調模型
<a name="model-customization-prepare"></a>

若要為您的自訂模型準備訓練和驗證資料集，您可以建立 `.jsonl` 檔案，其中每一行都是對應於記錄的 JSON 物件。您必須先至少準備訓練資料集，才能開始模型自訂任務。您建立的檔案必須符合您選擇的自訂方法和模型的格式。其中的記錄必須符合大小要求，視您的模型而定。

如需有關模型需求的資訊，請參閱 [訓練和驗證資料集的模型需求](#model-training-validation-requirements)。若要查看用於自訂不同模型的訓練和驗證資料集的預設配額，請參閱 AWS 一般參考中的 [Amazon Bedrock 端點和配額](https://docs.aws.amazon.com/general/latest/gr/bedrock.html)中的**訓練和驗證記錄總和**配額。

是否支援驗證資料集，以及訓練和驗證資料集的格式取決於下列因素。
+ 微調自訂任務的類型。
+ 資料的輸入和輸出模態。

如需微調 Amazon Nova 模型的資訊，請參閱[微調 Amazon Nova 模型](https://docs.aws.amazon.com/nova/latest/userguide/customize-fine-tune.html)。

## 支援用於微調的模態
<a name="model-customization-data-support"></a>

下列各節說明每個模型支援的不同微調功能，依其輸入和輸出模式進行組織。如需微調 Amazon Nova 模型的資訊，請參閱[微調 Amazon Nova 模型](https://docs.aws.amazon.com/nova/latest/userguide/customize-fine-tune.html)。

**文字轉文字模型**

文字轉文字模型可以針對各種文字型任務進行微調，包括對話式和非對話式應用程式。如需有關為微調文字轉文字模型準備資料的資訊，請參閱 [準備用於微調文字轉文字模型的資料](#preparing-text-data)。

下列非對話式模型已針對摘要、翻譯和問題回答等任務進行最佳化：
+ Amazon Titan Text G1 - Express
+ Amazon Titan Text G1 - Lite
+ Amazon Titan Text Premier
+ Cohere Command
+ Cohere Command Light
+ Meta Llama 3.1 8B Instruct
+ Meta Llama 3.1 70B Instruct

下列對話式模型專為單回合和多回合互動而設計。如果模型使用 Converse API，您的微調資料集必須遵循 Converse API 訊息格式，並包含系統、使用者和助理訊息。如需範例，請參閱 [準備用於微調文字轉文字模型的資料](#preparing-text-data)。如需 Converse API 操作的詳細資訊，請參閱 [與 Converse API 操作進行對話](conversation-inference.md)。
+ Anthropic Claude 3 Haiku
+ Meta Llama 3.2 1B Instruct (Converse API 格式)
+ Meta Llama 3.2 3B Instruct (Converse API 格式)
+ Meta Llama 3.2 11B Instruct Vision (Converse API 格式)
+ Meta Llama 3.2 90B Instruct Vision (Converse API 格式)
+ Meta Llama 3.3 70B Vision Instruct (Converse API 格式)

**文字影像轉文字和文字轉影像模型**

下列模型支援微調影像產生和文字影像處理。這些模型會根據文字輸入處理或產生影像，或根據文字和影像輸入產生文字。如需準備資料以微調文字影像轉文字和文字轉影像模型的相關資訊，請參閱 [準備用於微調影像和文字處理模型的資料](#preparing-image-text-data)。
+ Amazon Titan Image Generator G1 V1
+ Meta Llama 3.2 11B Instruct Vision
+ Meta Llama 3.2 90B Instruct Vision
+ Meta Llama 3.3 70B Vision Instruct

**影像轉嵌入**

下列模型支援對分類和擷取等任務進行微調。這些模型會從影像輸入產生數值表示 (嵌入)。如需有關準備資料以微調影像轉嵌入模型的資訊，請參閱 [準備用於微調影像產生和嵌入模型的資料](#preparing-image-generation-data)。
+ Amazon Titan Multimodal Embeddings G1
+ Amazon Titan Image Generator G1 V1

## 訓練和驗證資料集的模型需求
<a name="model-training-validation-requirements"></a>

以下各節列出模型的訓練和驗證資料集需求。如需 Amazon Nova 模型資料集限制條件的相關資訊，請參閱[微調 Amazon Nova 模型](https://docs.aws.amazon.com/nova/latest/userguide/customize-fine-tune.html)。

### Amazon Titan Text Premier
<a name="quotas-cm-titan-premier"></a>


****  

| Description | 最大值 (微調) | 
| --- | --- | 
| 批次大小為 1 時，輸入和輸出記號數的總和 | 4,096 | 
| 批次大小為 2、3 或 4 時，輸入和輸出字符數的總和 | N/A | 
| 資料集中每個範例的字元配額 | 字符配額 x 6 (預估) | 
| 訓練資料集檔案大小 | 1 GB | 
| 驗證資料集檔案大小 | 100 MB | 

### Amazon Titan Text G1 - Express
<a name="quotas-cm-titan-text"></a>


****  

| Description | 最大值 (微調) | 
| --- | --- | 
| 批次大小為 1 時，輸入和輸出記號數的總和 | 4,096 | 
| 批次大小為 2、3 或 4 時，輸入和輸出字符數的總和 | 2,048 | 
| 資料集中每個範例的字元配額 | 字符配額 x 6 (預估) | 
| 訓練資料集檔案大小 | 1 GB | 
| 驗證資料集檔案大小 | 100 MB | 

### Amazon Titan Text G1 - Lite
<a name="quotas-cm-titan-text-lite"></a>


****  

| Description | 最大值 (微調) | 
| --- | --- | 
| 批次大小為 1 或 2 時，輸入和輸出字符數的總和 | 4,096 | 
| 批次大小為 3、4、5 或 6 時，輸入和輸出字符數的總和 | 2,048 | 
| 資料集中每個範例的字元配額 | 字符配額 x 6 (預估) | 
| 訓練資料集檔案大小 | 1 GB | 
| 驗證資料集檔案大小 | 100 MB | 

### Amazon Titan Image Generator G1 V1
<a name="quotas-cm-titan-image"></a>


****  

| Description | 最小值 (微調) | 最大值 (微調) | 
| --- | --- | --- | 
| 訓練範例中的文字提示長度，以字元為單位 | 3 | 1,024 | 
| 訓練資料集中的記錄 | 5 | 10,000 | 
| 輸入影像大小 | 0 | 50 MB | 
| 輸入影像的高度 (以像素為單位) | 512 | 4,096 | 
| 輸入影像的寬度 (以像素為單位) | 512 | 4,096 | 
| 輸入影像總像素數 | 0 | 12，582，912 | 
| 輸入影像長寬比 | 1：4 | 4：1 | 

### Amazon Titan Multimodal Embeddings G1
<a name="quotas-cm-titan-mm-embed"></a>


****  

| Description | 最小值 (微調) | 最大值 (微調) | 
| --- | --- | --- | 
| 訓練範例中的文字提示長度，以字元為單位 | 0 | 2，560 | 
| 訓練資料集中的記錄 | 1,000 | 500,000 | 
| 輸入影像大小 | 0 | 5 MB | 
| 輸入影像的高度 (以像素為單位) | 128 | 4096 | 
| 輸入影像的寬度 (以像素為單位) | 128 | 4096 | 
| 輸入影像總像素數 | 0 | 12，528，912 | 
| 輸入影像長寬比 | 1：4 | 4：1 | 

### Meta Llama 3.1
<a name="quotas-cm-meta-llama-3-1"></a>


****  

| Description | 最小值 (微調) | 最大值 (微調) | 
| --- | --- | --- | 
| 輸入字符 | 0 | 16,000 | 
| 輸出字符 | 0 | 16,000 | 
| 資料集中每個範例的字元配額 | 0 | 字符配額 x 6 (預估) | 
| 輸入和輸出字符的總和 | 0 | 16,000 | 
| 訓練和驗證記錄的總和 | 100 | 10,000 (可使用服務配額進行調整) | 

### Meta Llama 3.2
<a name="quotas-cm-meta-llama-3-2"></a>

Meta Llama-3.2 11B Vision Instruct 和 Meta Llama-3.2 90B Vision Instruct 支援的影像格式包括：`gif`、`jpeg`、`png` 和 `webp`。若要在微調這些模型期間估計影像轉字符轉換，您可以使用此公式作為近似值：`Tokens = min(2, max(Height // 560, 1)) * min(2, max(Width // 560, 1)) * 1601`。影像會根據大小轉換為大約 1,601 到 6,404 個字符。


****  

| Description | 最小值 (微調) | 最大值 (微調) | 
| --- | --- | --- | 
| 輸入和輸出字符的總和 | 0 | 16,000 (10000 適用於 Meta Llama 3.2 90B) | 
| 訓練和驗證記錄的總和 | 100 | 10,000 (可使用服務配額進行調整) | 
| Meta Llama 11B and 90B instruct 模型的輸入影像大小) | 0 | 10 MB | 
| Meta Llama 11B and 90B instruct 模型的輸入影像高度 (以像素為單位) | 10 | 8192 | 
| Meta Llama 11B and 90B90B instruct 模型的輸入影像寬度 (以像素為單位) | 10 | 8192 | 

### Meta Llama 3.3
<a name="quotas-cm-meta-llama-3-3"></a>


****  

| Description | 最小值 (微調) | 最大值 (微調) | 
| --- | --- | --- | 
| 輸入和輸出字符的總和 | 0 | 16000 | 
| 訓練和驗證記錄的總和 | 100 | 10,000 (可使用服務配額進行調整) | 

### CohereCommand
<a name="quotas-cm-cohere-command"></a>


****  

| Description | 最大值 (微調) | 
| --- | --- | 
| 輸入字符 | 4,096 | 
| 輸出字符 | 2,048 | 
| 資料集中每個範例的字元配額 | 字符配額 x 6 (預估) | 
| 訓練資料集中的記錄 | 10,000 | 
| 驗證資料集中的記錄 | 1,000 | 

### Anthropic Claude 3 Haiku
<a name="anthropic-claude-3-haiku"></a>


****  

| Description | 最大值 (微調) | 
| --- | --- | 
| 記錄數下限 | 32 | 
| 訓練記錄數上限 | 10,000 | 
| 驗證記錄數上限 | 1,000 | 
| 記錄總數上限 | 10,000 (可使用服務配額進行調整) | 
| 字符數上限 | 32,000 | 
| 訓練資料集大小上限 | 10 GB | 
| 驗證資料集大小上限 | 1 GB | 

## 準備用於微調文字轉文字模型的資料
<a name="preparing-text-data"></a>

**注意**  
如需微調 Amazon Nova 模型的資訊，請參閱[微調 Amazon Nova 模型](https://docs.aws.amazon.com/nova/latest/userguide/customize-fine-tune.html)。

對於微調文字轉文字模型，每個 JSON 物件都是包含結構化欄位的範例，旨在引導模型根據提供的文字提示產生所需的文字輸出。資料格式會依使用案例而有所不同，大致可分類為非對話式和對話式使用案例。

------
#### [ Non-conversational tasks ]

非對話式任務涉及為指定的輸入產生單一輸出。每個資料集範例都包含一個具有輸入文字的 `prompt` 欄位，以及一個具有預期輸出的 `completion` 欄位。此格式支援一系列任務，例如問答、摘要、翻譯、文字完成和資訊擷取。

範例格式

```
{"prompt": "What is the capital of France?", "completion": "The capital of France is Paris."}
{"prompt": "Summarize the article about climate change.", "completion": "Climate change refers to the long-term alteration of temperature and typical weather patterns in a place."}
```

每個字符使用大約 6 個字元來估計規劃資料集大小的字符數量。

------
#### [ Converse API format (Single turn and Multi turn) ]

若要使用 Converse API，您可以呼叫 `Converse` 或 `ConverseStream` 操作，將訊息傳送到模型。若要呼叫 `Converse`，您需要 `bedrock:InvokeModel` 操作的許可。若要呼叫 `ConverseStream`，您需要 `bedrock:InvokeModelWithResponseStream` 操作的許可。如需詳細資訊，請參閱[使用 Converse API](conversation-inference-call.md)。如需 Converse API 操作的詳細資訊，請參閱 [與 Converse API 操作進行對話](conversation-inference.md)。

範例格式

```
{
    "schemaVersion": "bedrock-conversation-2024",
    "system": [
        {
            "text": "You are a digital assistant with a friendly personality"
        }
    ],
    "messages": [
        {
            "role": "user",
            "content": [
                {
                    "text": "What is the capital of Mars?"
                }
            ]
        },
        {
            "role": "assistant",
            "content": [
                {
                    "text": "Mars does not have a capital. Perhaps it will one day."
                }
            ]
        }
    ]
}
```

------
#### [ Anthropic Claude 3 Haiku: Single-turn conversations ]

單回合對話式任務涉及隔離交換，其中模型僅根據目前的使用者輸入產生回應，而不考慮先前的上下文。每個資料集範例會使用訊息陣列，並具有 `user` 和 `assistant` 的交替角色。

格式

```
{"system": "<system message>","messages":[{"role": "user", "content": "<user query>"},{"role": "assistant", "content": "<expected generated text>"}]}
```

範例

```
{"system": "You are an helpful assistant.","messages":[{"role": "user", "content": "what is AWS"},{"role": "assistant", "content": "it's Amazon Web Services."}]}
```

------
#### [ Anthropic Claude 3 Haiku: Multi-turn conversations ]

多回合對話式任務涉及延伸對話，其中模型必須產生回應，同時保留先前交換的上下文。此格式擷取互動式任務的動態性質，例如客戶支援或複雜的討論。

格式

```
{"system": "<system message>","messages":[{"role": "user", "content": "<user query 1>"},{"role": "assistant", "content": "<expected generated text 1>"}, {"role": "user", "content": "<user query 2>"},{"role": "assistant", "content": "<expected generated text 2>"}]}
```

範例

```
{"system": "system message","messages":[{"role": "user", "content": "Hello there."},{"role": "assistant", "content": "Hi, how can I help you?"},{"role": "user", "content": "what are LLMs?"},{"role": "assistant", "content": "LLM means large language model."},]}  
```

------

## 準備用於微調影像和文字處理模型的資料
<a name="preparing-image-text-data"></a>

**注意**  
如需微調 Amazon Nova 模型的資訊，請參閱[微調 Amazon Nova 模型](https://docs.aws.amazon.com/nova/latest/userguide/customize-fine-tune.html)。

對於微調影像文字轉文字模型，每個 JSON 物件都是一個範例，其中包含以 `messages` 陣列為結構的對話，由代表使用者輸入和助理回應的交替 JSON 物件所組成。使用者輸入可以同時包含文字和影像，而助理回應一律為文字。此結構支援單回合和多回合對話流程，讓模型能夠有效地處理各種任務。Meta Llama-3.2 11B Vision Instruct 和 Meta Llama-3.2 90B Vision Instruct 支援的影像格式包括：`gif`、`jpeg`、`png` 和 `webp`。

若要允許 Amazon Bedrock 存取影像檔案，請在主控台中，將類似於 [存取 S3 中訓練和驗證檔案以及寫入輸出檔案的許可](model-customization-iam-role.md#model-customization-iam-role-s3) 中的 IAM 政策新增到您設定的 Amazon Bedrock 模型自訂服務角色或自動為您設定的角色。您在訓練資料集中提供的 Amazon S3 路徑必須位於您在政策中指定的資料夾中。

**單回合對話**

單回合對話的每個 JSON 物件都包含使用者訊息和助理訊息。使用者訊息包含設為*使用者*的角色欄位，以及包含陣列*的內容*欄位，其中包含描述輸入模式 `type` 的欄位 (*文字*或*影像*)。對於文字輸入，`content` 欄位包含具有使用者問題或提示 `text` 的欄位。對於影像輸入，`content` 欄位會指定影像 `format` (例如 *jpeg*、*png*) 及其 `source`，其中的 `uri` 指向影像的 Amazon S3 位置。`uri` 代表存放在 Amazon S3 儲存貯體中影像的唯一路徑，通常格式為 `s3://<bucket-name>/<path-to-file>`。助理訊息包含以下欄位：設為*助理*的 `role` 欄位；`content` 欄位，其中包含 `type` 欄位設為*文字*的陣列；以及內含助理所產生回應的 `text` 欄位。

範例格式

```
{
    "schemaVersion": "bedrock-conversation-2024",
    "system": [{
        "text": "You are a smart assistant that answers questions respectfully"
    }],
    "messages": [{
            "role": "user",
            "content": [{
                    "text": "What does the text in this image say?"
                },
                {
                    "image": {
                        "format": "png",
                        "source": {
                            "s3Location": {
                                "uri": "s3://your-bucket/your-path/your-image.png",
                                "bucketOwner": "your-aws-account-id"
                            }
                        }
                    }
                }
            ]
        },
        {
            "role": "assistant",
            "content": [{
                "text": "The text in the attached image says 'LOL'."
            }]
        }
    ]
}
```

**多回合對話**

多回合對話的每個 JSON 物件都包含一系列具有交替角色的訊息，其中使用者訊息和助理訊息的結構一致，以允許有一致的交換。使用者訊息包含設為*使用者*的 `role` 欄位集，以及描述輸入模式的 `content` 欄位。對於文字輸入，`content` 欄位包含一個具有使用者問題或後續追蹤的 `text` 欄位，而對於影像輸入，它指定影像 `format` 及其 `source`，其中的 `uri` 指向影像的 Amazon S3 位置。`uri` 做為唯一識別碼，採用 s3://<bucket-name>/<path-to-file> 格式，並允許模型從指定的 Amazon S3 儲存貯體存取影像。助理訊息包含以下欄位：設為*助理*的 `role` 欄位；`content` 欄位，其中包含 `type` 欄位設為*文字*的陣列；以及內含助理所產生回應的 `text` 欄位。對話可以跨越多個交換，讓助理能夠維護內容並在整個過程中傳遞一致的回應。

範例格式

```
{
    "schemaVersion": "bedrock-conversation-2024",
    "system": [{
        "text": "You are a smart assistant that answers questions respectfully"
    }],
    "messages": [{
            "role": "user",
            "content": [{
                    "text": "What does the text in this image say?"
                },
                {
                    "image": {
                        "format": "png",
                        "source": {
                            "s3Location": {
                                "uri": "s3://your-bucket/your-path/your-image.png",
                                "bucketOwner": "your-aws-account-id"
                            }
                        }
                    }
                }
            ]
        },
        {
            "role": "assistant",
            "content": [{
                "text": "The text in the attached image says 'LOL'."
            }]
        },
        {
            "role": "user",
            "content": [{
                    "text": "What does the text in this image say?"
                }
            ]
        },
        {
            "role": "assistant",
            "content": [{
                "text": "The text in the attached image says 'LOL'."
            }]
        }
        
    ]
}
```

## 準備用於微調影像產生和嵌入模型的資料
<a name="preparing-image-generation-data"></a>

**注意**  
Amazon Nova 模型有不同的微調需求。若要微調這些模型，請遵循[微調 Amazon Nova 模型](https://docs.aws.amazon.com/nova/latest/userguide/customize-fine-tune.html)中的指示。

對於文字轉影像或影像轉嵌入模型，準備訓練資料集。不支援驗證資料集。每個 JSON 物件都是一個範例，範例中包含 `image-ref`、影像的 Amazon S3 URI，以及可能是影像提示的 `caption`。

影像必須是 JPEG 或 PNG 格式。

```
{"image-ref": "s3://bucket/path/to/image001.png", "caption": "<prompt text>"}
{"image-ref": "s3://bucket/path/to/image002.png", "caption": "<prompt text>"}{"image-ref": "s3://bucket/path/to/image003.png", "caption": "<prompt text>"}
```

以下是範例項目：

```
{"image-ref": "s3://amzn-s3-demo-bucket/my-pets/cat.png", "caption": "an orange cat with white spots"}
```

若要允許 Amazon Bedrock 存取影像檔案，請在主控台中，將類似於 [存取 S3 中訓練和驗證檔案以及寫入輸出檔案的許可](model-customization-iam-role.md#model-customization-iam-role-s3) 中的 IAM 政策新增到您設定的 Amazon Bedrock 模型自訂服務角色或自動為您設定的角色。您在訓練資料集中提供的 Amazon S3 路徑必須位於您在政策中指定的資料夾中。