

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

# 准备用于微调模型的数据
<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)。

**Text-to-Text  ** 模型

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 消息格式，并包含系统、用户和助手消息。有关示例，请参阅 [为微调 text-to-text模型准备数据](#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 视觉（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模型准备数据的信息，请参见[准备用于微调图像生成模型和嵌入模型的数据](#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 高级版
<a name="quotas-cm-titan-premier"></a>


****  

| 说明 | 最大值（微调） | 
| --- | --- | 
| 批次大小为 1 时输入和输出令牌数总和 | 4,096 | 
| 批次大小为 2、3 或 4 时输入和输出令牌数总和 | 不适用 | 
| 数据集中每个样本的字符配额 | 词元配额 x 6（估算值） | 
| 训练数据集文件大小 | 1 GB | 
| 验证数据集文件大小 | 100 MB | 

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


****  

| 说明 | 最大值（微调） | 
| --- | --- | 
| 批次大小为 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>


****  

| 说明 | 最大值（微调） | 
| --- | --- | 
| 批次大小为 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>


****  

| 说明 | 最小值（微调） | 最大值（微调） | 
| --- | --- | --- | 
| 训练样本中的文本提示长度，以字符为单位 | 3 | 1024 | 
| 训练数据集中的记录数 | 5 | 10000 | 
| 输入图像大小 | 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>


****  

| 说明 | 最小值（微调） | 最大值（微调） | 
| --- | --- | --- | 
| 训练样本中的文本提示长度，以字符为单位 | 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>


****  

| 说明 | 最小值（微调） | 最大值（微调） | 
| --- | --- | --- | 
| 输入令牌数 | 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`。为了估算这些模型微调期间的 image-to-token转化率，你可以使用这个公式作为近似值：。`Tokens = min(2, max(Height // 560, 1)) * min(2, max(Width // 560, 1)) * 1601`图像会转换为约 1601 到 6404 个词元，具体取决于其大小。


****  

| 说明 | 最小值（微调） | 最大值（微调） | 
| --- | --- | --- | 
| 输入词元数与输出词元数之和 | 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>


****  

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

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


****  

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

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


****  

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

## 为微调 text-to-text模型准备数据
<a name="preparing-text-data"></a>

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

对于微调 text-to-text模型，每个 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)。

对于微调 image-text-to-text模型，每个 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 对象均由一条用户消息和一条助手消息组成。用户消息包含一个设置为 *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'."
            }]
        }
    ]
}
```

**多回合对话**

在多回合对话中，每个 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 模型具有不同的微调要求。要微调这些模型，请按照[微调 Amazon Nova 模型](https://docs.aws.amazon.com/nova/latest/userguide/customize-fine-tune.html)中的说明进行操作。

对于 text-to-image我们的 image-to-embedding模型，请准备训练数据集。不支持验证数据集。每个 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 路径必须位于您在策略中指定的文件夹中。