

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 准备用于微调模型的数据
<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模型的信息，请参阅[Fine-tuning Amazon Nova模型](https://docs.aws.amazon.com/nova/latest/userguide/customize-fine-tune.html)。

## 支持的微调模式
<a name="model-customization-data-support"></a>

以下各节描述了每个模型支持的不同微调功能，这些功能按其输入和输出模式进行组织。有关微调Amazon Nova模型的信息，请参阅[Fine-tuning Amazon Nova模型](https://docs.aws.amazon.com/nova/latest/userguide/customize-fine-tune.html)。

**Text-to-Text  ** 模型

Text-to-Text 可以针对各种基于文本的任务对模型进行微调，包括对话和非对话应用程序。有关为微调 Text-to-Text 模型准备数据的信息，请参见[准备用于微调文本转文本模型的数据](#preparing-text-data)。

以下非对话式模型已针对汇总、翻译和问答等任务进行了优化：
+ Amazon Titan Text G1 - Express
+ Amazon Titan Text G1 - Lite
+ Amazon Titan Text 高级版
+ 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 操作的更多信息，请参阅[使用匡威 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 视觉（Converse API 格式）
+ Meta Llama 3.2 90B Instruct 视觉（Converse API 格式）
+ Meta Llama 3.3 70B 视觉指令（Converse API 格式）

**Text-Image-to-Text & m Text-to-Image odel** s

以下模型支持对图像生成和文本-图像处理进行微调。这些模型根据文本输入处理或生成图像，或根据文本输入和图像输入生成文本。有关为微调 Text-Image-to-Text 和 Text-to-Image 模型模型准备数据的信息，请参阅[准备用于微调图像和文本处理模型的数据](#preparing-image-text-data)。
+ Amazon Titan Image Generator G1 V1
+ Meta Llama 3.2 11B Instruct 视觉
+ Meta Llama 3.2 90B Instruct 视觉
+ Meta Llama 3.3 70B 视觉指令

**Image-to-Embeddings**

以下模型支持对分类和检索等任务进行微调。这些模型从图像输入中生成数值表示（嵌入）。有关为微调 Image-to-Embeddings 模型准备数据的信息，请参见[准备用于微调图像生成模型和嵌入模型的数据](#preparing-image-generation-data)。
+ Amazon Titan Multimodal Embeddings G1
+ Amazon Titan Image Generator G1 V1

## 训练数据集和验证数据集的模型要求
<a name="model-training-validation-requirements"></a>

以下各部分列出了模型的训练数据集和验证数据集的要求。有关Amazon Nova模型的数据集约束的信息，请参阅[Fine-tuning Amazon Nova模型](https://docs.aws.amazon.com/nova/latest/userguide/customize-fine-tune.html)。

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


****  

| 说明 | 最大值 (Fine-tuning) | 
| --- | --- | 
| 批次大小为 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>


****  

| 说明 | 最大值 (Fine-tuning) | 
| --- | --- | 
| 批次大小为 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>


****  

| 说明 | 最大值 (Fine-tuning) | 
| --- | --- | 
| 批次大小为 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>


****  

| 说明 | 最小值 (Fine-tuning) | 最大值 (Fine-tuning) | 
| --- | --- | --- | 
| 训练样本中的文本提示长度，以字符为单位 | 3 | 1024 | 
| 训练数据集中的记录数 | 5 | 10000 | 
| 输入图像大小 | 0 | 50 MB | 
| 输入图像的高度（以像素为单位） | 512 | 4,096 | 
| 输入图像的宽度（以像素为单位） | 512 | 4,096 | 
| 输入图像总像素数 | 0 | 12,582,912 | 
| 输入图像纵横比 | 1:4 | 4:1 | 

### Amazon Titan 多模态嵌入 G1
<a name="quotas-cm-titan-mm-embed"></a>


****  

| 说明 | 最小值 (Fine-tuning) | 最大值 (Fine-tuning) | 
| --- | --- | --- | 
| 训练样本中的文本提示长度，以字符为单位 | 0 | 2,560 | 
| 训练数据集中的记录数 | 1000 | 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>


****  

| 说明 | 最小值 (Fine-tuning) | 最大值 (Fine-tuning) | 
| --- | --- | --- | 
| 输入令牌数 | 0 | 16000 | 
| 输出令牌数 | 0 | 16000 | 
| 数据集中每个样本的字符配额 | 0 | 词元配额 x 6（估算值） | 
| 输入词元数与输出词元数之和 | 0 | 16000 | 
| 训练记录数与验证记录数之和 | 100 | 10000（可通过服务配额进行调整） | 

### 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`。图像会转换为约 1601 到 6404 个词元，具体取决于其大小。


****  

| 说明 | 最小值 (Fine-tuning) | 最大值 (Fine-tuning) | 
| --- | --- | --- | 
| 输入词元数与输出词元数之和 | 0 | 16000（对于 Meta Llama 3.2 90B)，为 10000） | 
| 训练记录数与验证记录数之和 | 100 | 10000（可通过服务配额进行调整） | 
| 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>


****  

| 说明 | 最小值 (Fine-tuning) | 最大值 (Fine-tuning) | 
| --- | --- | --- | 
| 输入词元数与输出词元数之和 | 0 | 16000 | 
| 训练记录数与验证记录数之和 | 100 | 10000（可通过服务配额进行调整） | 

### Cohere命令
<a name="quotas-cm-cohere-command"></a>


****  

| 说明 | 最大值 (Fine-tuning) | 
| --- | --- | 
| 输入令牌数 | 4,096 | 
| 输出令牌数 | 2,048 | 
| 数据集中每个样本的字符配额 | 词元配额 x 6（估算值） | 
| 训练数据集中的记录数 | 10000 | 
| 验证数据集中的记录数 | 1000 | 

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


****  

| 说明 | 最大值 (Fine-tuning) | 
| --- | --- | 
| 最小记录数 | 32 | 
| 最大训练记录数 | 10000 | 
| 最大验证记录数 | 1000 | 
| 最大记录总数 | 10000（可通过服务配额进行调整） | 
| 最大词元数 | 32000 | 
| 最大训练数据集大小 | 10 GB | 
| 最大验证数据集大小 | 1 GB | 

## 准备用于微调文本转文本模型的数据
<a name="preparing-text-data"></a>

**注意**  
有关微调Amazon Nova模型的信息，请参阅[Fine-tuning Amazon Nova模型](https://docs.aws.amazon.com/nova/latest/userguide/customize-fine-tune.html)。

在微调文本转文本模型时，每个 JSON 对象均为一个包含结构化字段的示例，这些字段旨在指导模型根据提供的文本提示来生成所需的文本输出。数据格式因使用案例（主要分为非对话式使用案例型和对话式使用案例）而异。

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

Non-conversational 任务涉及为给定输入生成单个输出。每个数据集示例均包括一个带输入文本的 `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使用匡威 API（已移动）](conversation-inference-call.md)。有关 Converse API 操作的更多信息，请参阅[使用匡威 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 ]

Single-turn 对话任务涉及孤立的交流，在这种交换中，模型仅根据当前用户的输入生成响应，而不考虑先前的上下文。每个数据集示例均使用一个消息数组，其中交替使用 `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 ]

Multi-turn 对话任务涉及延长的对话，在这种对话中，模型必须生成响应，同时保留先前交流的背景。此格式能够捕获交互式任务的动态特性，例如客户支持或复杂的讨论。

格式

```
{"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模型的信息，请参阅[Fine-tuning 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 路径必须位于您在策略中指定的文件夹中。

**Single-turn 对话**

在单回合对话中，每个 JSON 对象均由一条用户消息和一条助手消息组成。用户消息包含一个设置为 *user* 的角色字段和一个包含数组的 *content* 字段，数组中的 `type` 字段（*text* 或 *image*）描述了输入模态。对于文本输入，`content` 字段包含一个 `text` 字段，该字段包含用户的问题或提示。对于图像输入，`content` 字段指定图像 `format`（例如，*jpeg*、*png*），其 `source` 包含一个指向图像的 Amazon S3 位置的 `uri`。`uri` 表示存储在 Amazon S3 存储桶中的图像的唯一路径，其格式通常为 `s3://<bucket-name>/<path-to-file>`。助手消息包括一个设置为 *assistant* 的 `role` 字段和一个包含数组的 `content` 字段，此数组中的 `type` 字段设置为 *text*，`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'."
            }]
        }
    ]
}
```

**Multi-turn 对话**

在多回合对话中，每个 JSON 对象均包含一系列角色交替的消息，其中用户消息与助手消息的结构保持一致，以实现连贯的交互。用户消息包括一个设置为 *user* 的 `role` 字段和一个描述输入模态的 `content` 字段。对于文本输入，`content` 字段中有一个包含用户的问题或后续信息的 `text` 字段，而对于图像输入，该字段指定图像 `format` 及其 `source`（其中包含一个指向图像的 Amazon S3 位置的 `uri`）。`uri` 用作格式为 s3://<bucket-name>/<path-to-file> 的唯一标识符，并且可让模型访问指定的 Amazon S3 存储桶中的对象。助手消息包括一个设置为 *assistant* 的 `role` 字段和一个包含数组的 `content` 字段，此数组中的 `type` 字段设置为 *text*，`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 模型具有不同的微调要求。要对这些模型进行微调，请按照[Fine-tuning Amazon Nova模型](https://docs.aws.amazon.com/nova/latest/userguide/customize-fine-tune.html)中的说明进行操作。

对于文本转图像或图像转嵌入模型，请准备训练数据集。不支持验证数据集。每个 JSON 对象都是一个样本，其中包含 `image-ref`（图像的 Amazon S3 URI）和 `caption`（可作为图像的提示）。

图片必须采用 JPEG 或 PNG 格式并符合以下要求：
+ **尺寸**-每边必须介于 512 到 4,096 像素之间。
+ **纵横比**-介于 1:4 和 4:1 之间。
+ **总像素** — 不得超过 12,582,912（大约 3,547 x 3,547）。
+ **文件大小**-每张图片不得超过 50 MB。
+ **字幕长度**-介于 3 到 1,024 个字符之间。

有关限制条件的完整列表，请参阅[Amazon Titan Image Generator G1 V1](#quotas-cm-titan-image)。

```
{"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 路径必须位于您在策略中指定的文件夹中。