通过监督微调对Amazon Nova模型进行微调 - Amazon Bedrock

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

通过监督微调对Amazon Nova模型进行微调

Amazon Nova2.0 SFT 数据使用与 Amazon Nova 1.0 相同的 Converse API 格式,但增加了可选的推理内容字段。有关完整的格式规范,请参阅ReasoningContentBlockConverse API 架构

支持的功能:

  • 输入类型-用户内容块中的文本、图像或视频

  • 助手内容 — 纯文字回复和推理内容

  • 数据集构成-必须是同质的。选择以下选项之一:纯文字转弯、文字+图像转弯或文字+视频转弯

重要

您不能在同一个数据集中或在不同的回合中混合图像和视频。

目前的局限性:

  • 工具用法-尽管输入格式支持使用工具,但 Amazon Nova 2.0 SFT 目前不支持使用工具。添加工具部分可能会导致您的任务失败。

  • 多模态推理内容 — 尽管 Converse 格式支持基于图像的推理内容,但 2.0 SFT 不支持此内容。Amazon Nova

  • 验证集-用户界面可能支持提供验证集,但在 SFT 训练期间不支持提供验证集。

支持的媒体格式:

  • 图片 — PNG、JPEG、GIF

  • 视频 — MOV、MKV、 MP4

数据格式示例

Text-only

此示例显示了与 Amazon Nova 1.0 兼容的基本纯文本格式。

{ "schemaVersion": "bedrock-conversation-2024", "system": [ { "text": "You are a digital assistant with a friendly personality" } ], "messages": [ { "role": "user", "content": [ { "text": "What country is right next to Australia?" } ] }, { "role": "assistant", "content": [ { "text": "The closest country is New Zealand" } ] } ] }
Text with reasoning

此示例显示了带有 Amazon Nova 2.0 可选推理内容的文本。

{ "schemaVersion": "bedrock-conversation-2024", "system": [ { "text": "You are a digital assistant with a friendly personality" } ], "messages": [ { "role": "user", "content": [ { "text": "What country is right next to Australia?" } ] }, { "role": "assistant", "content": [ { "reasoningContent": { "reasoningText": { "text": "I need to use my world knowledge of geography to answer this question" } } }, { "text": "The closest country to Australia is New Zealand, located to the southeast across the Tasman Sea." } ] } ] }
注意

当前,内部reasoningText仅支持reasoningContent。多模态推理内容尚不可用。

Image + text

此示例说明如何在文本中包含图像输入。

{ "schemaVersion": "bedrock-conversation-2024", "system": [ { "text": "You are a helpful assistant." } ], "messages": [ { "role": "user", "content": [ { "image": { "format": "jpeg", "source": { "s3Location": { "uri": "s3://your-bucket/your-path/your-image.jpg", "bucketOwner": "your-aws-account-id" } } } }, { "text": "Which country is highlighted in the image?" } ] }, { "role": "assistant", "content": [ { "reasoningContent": { "reasoningText": { "text": "I will determine the highlighted country by examining its location on the map and using my geographical knowledge" } } }, { "text": "The highlighted country is New Zealand" } ] } ] }
Video + text

此示例说明如何在文本中加入视频输入。

{ "schemaVersion": "bedrock-conversation-2024", "system": [ { "text": "You are a helpful assistant." } ], "messages": [ { "role": "user", "content": [ { "video": { "format": "mp4", "source": { "s3Location": { "uri": "s3://your-bucket/your-path/your-video.mp4", "bucketOwner": "your-aws-account-id" } } } }, { "text": "What is shown in this video?" } ] }, { "role": "assistant", "content": [ { "reasoningContent": { "reasoningText": { "text": "I will analyze the video content to identify key elements" } } }, { "text": "The video shows a map with New Zealand highlighted" } ] } ] }

推理内容

推理内容(也称为 chain-of-thought)在生成最终答案之前捕捉模型的中间思维步骤。assistant反过来,使用该reasoningContent字段来包含这些推理痕迹。

损失是如何计算的:

  • 包含推理内容 — 训练损失包括推理代币和最终输出标记

  • 不含推理内容 — 训练损失仅根据最终输出代币计算

何时启用推理模式:reasoning_enabled: true在训练配置中设置您希望模型在生成最终输出之前生成思维标记,或者需要提高复杂推理任务的性能。设置reasoning_enabled: false当你在训练那些无法从明确的推理步骤中受益的简单任务时。

注意

无论您的训练数据是否包含推理内容,您都可以启用推理模式。但是,建议在训练数据中加入推理轨迹,这样模型就可以从这些示例中吸取教训并提高推理质量。

格式指南:

  • 对推理内容使用纯文本。

  • 除非您的任务特别要求,</thinking>否则请避免使用<thinking>和之类的标记标记。

  • 确保推理内容清晰且与问题解决过程相关。

有效的推理内容应包括:

  • 中间思考和分析

  • 逻辑推断和推理步骤

  • Step-by-step 解决问题的方法

  • 步骤和结论之间的明确联系

如果你的数据集缺少推理轨迹,你可以使用像 Nova Premier 这样的具有推理功能的模型来创建它们。向模型提供您的输入输出对,并捕获其推理过程以构建推理增强数据集。

数据集准备指南

下表提供了准备训练数据集的指南。

数据集准备指南
指南 说明
尺寸和质量
  • 建议大小:2,000-10,000 个样本

  • 最低样本数:200

  • 优先考虑质量而不是数量。确保示例准确且注释良好。

  • 数据集应密切反映您的生产用例。

多元化

包括执行以下操作的不同示例:

  • 涵盖预期输入的全部范围

  • 代表不同的难度等级

  • 包括边缘案例和变体

  • 防止过度拟合到狭窄的图案

输出格式

在助手响应中明确指定所需的输出格式。示例包括 JSON 结构、表格、CSV 格式或特定于您的应用程序的自定义格式。

多回合对话
  • 损失仅在助手回合中计算,不计算用户回合。

  • 每个助手回复的格式都应正确。

  • 在对话回合中保持一致性。

质量清单
  • 足够的数据集大小(2,000-10,000 个样本)

  • 涵盖所有用例的多样化示例

  • 清晰、一致的输出格式

  • 准确的标签和注释

  • 生产场景的代表

  • 没有矛盾或模棱两可之处