View a markdown version of this page

準備 Amazon Nova 2 上的 SFT 資料 - Amazon Nova

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

準備 Amazon Nova 2 上的 SFT 資料

Amazon Nova 2 上的 SFT 支援文字、影像、影片和文件理解,以及工具呼叫,無論是否支援推理。此頁面說明為 Amazon Nova 2 Understanding 模型準備 SFT 訓練資料的限制條件、支援的格式和最佳實務。

提示

若要在開始訓練任務之前驗證資料集格式,請參閱 驗證工具

資料格式

Amazon Nova 2 SFT 資料使用與 Amazon Nova 1 相同的 Converse API 格式,並新增選用的推理內容欄位。

JSONL 訓練檔案中的每一行都是具有下列最上層欄位的 JSON 物件。展開區段以進一步了解:

必要. messages 欄位是一組訊息物件,每個物件都會在對話中定義轉彎。訊息物件包含下列欄位:

  • 角色 – 必要。定義訊息是來自 user(傳送至模型的提示) 還是 assistant(模型回應)。第一個轉彎必須是 user,最後一個轉彎必須是 assistant,而轉彎必須交替。

  • 內容 – 必要。此回合的內容區塊陣列。

content 欄位會映射至內容區塊的陣列。Amazon Nova 2 SFT 資料支援下列區塊:

text

指定文字內容的字串。支援 userassistant輪換。

以下顯示範例訊息物件,其content陣列僅包含text內容區塊:

{ "role": "user", "content": [ { "text": "string" } ] }
image

指定其格式和 S3 位置的影像物件。僅輪user流支援。

以下顯示範例訊息物件,其內容陣列僅包含影像內容區塊:

{ "role": "user", "content": [ { "image": { "format": "jpeg", "source": { "s3Location": { "uri": "s3://your-bucket/your-image.jpg", "bucketOwner": "account-id" } } } } ] }
video

指定其格式和 S3 位置的視訊物件。僅輪user流支援。

以下顯示範例訊息物件,其內容陣列僅包含影片內容區塊:

{ "role": "user", "content": [ { "video": { "format": "mp4", "source": { "s3Location": { "uri": "s3://your-bucket/your-video.mp4", "bucketOwner": "account-id" } } } } ] }
document

指定其格式和 S3 位置的文件物件。僅輪user流支援。

以下顯示範例訊息物件,其內容陣列僅包含文件內容區塊:

{ "role": "user", "content": [ { "document": { "format": "pdf", "source": { "s3Location": { "uri": "s3://your-bucket/your-document.pdf", "bucketOwner": "account-id" } } } } ] }
reasoningContent

推理追蹤物件。僅輪assistant流支援。僅支援以文字為基礎的推理;不支援以影像為基礎的推理內容。

以下顯示範例訊息物件,其內容陣列僅包含推理內容區塊:

{ "role": "assistant", "content": [ { "reasoningContent": { "reasoningText": { "text": "string" } } }, { "text": "final answer" } ] }
toolUse

工具調用物件。僅輪assistant流支援。每個對話的 toolUseId必須是唯一的,且name必須符合 中定義的工具toolConfig

以下顯示範例訊息物件,其內容陣列僅包含工具使用內容區塊:

{ "role": "assistant", "content": [ { "toolUse": { "toolUseId": "unique-id", "name": "tool-name", "input": { ... } } } ] }
toolResult

工具結果物件。僅輪user流支援。每個 toolUseId都必須參考前面的 toolUse,並且只能使用一次。內容只能是文字或 JSON。

以下顯示範例訊息物件,其內容陣列僅包含工具結果內容區塊:

{ "role": "user", "content": [ { "toolResult": { "toolUseId": "matching-id", "content": [ { "text": "result" } ] } } ] }

選用陣列,定義系統提示 — 模型有關應執行任務或應採用角色的指示或內容。在訓練和推論期間使用相同的系統提示,以獲得最佳結果。

"system": [ { "text": "You are a helpful assistant." } ]

選用物件,定義可供模型在對話期間使用的工具。每個工具都定義了其輸入參數的名稱、描述和 JSON 結構描述。

"toolConfig": { "tools": [ { "toolSpec": { "name": "tool-name", "description": "tool-description", "inputSchema": { "json": { "type": "object", "properties": { "param": { "type": "string", "description": "param-description" } }, "required": ["param"] } } } } ] }

必要. 識別結構描述版本的字串欄位。可以是任何字串值。

"schemaVersion": "bedrock-conversation-2024"

驗證您的資料

提交訓練任務之前,請驗證您的資料集,以及早發現格式化問題。如需可用的驗證工具,請參閱 驗證工具

範例輸入

以下是完整的範例 JSON 物件,示範如何合併不同模態的欄位和內容區塊。

Text-only (Nova 1.0 compatible)
{ "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" } ] } ] }
Image + text input
{ "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 input
{ "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" } ] } ] }
Document + text input
{ "schemaVersion": "bedrock-conversation-2024", "messages": [ { "role": "user", "content": [ { "text": "What are the ways in which a customer can experience issues during checkout on Amazon?" }, { "document": { "format": "pdf", "source": { "s3Location": { "uri": "s3://my-bucket-name/path/to/documents/customer_service_debugging.pdf", "bucketOwner": "123456789012" } } } } ] }, { "role": "assistant", "content": [ { "reasoningContent": { "reasoningText": { "text": "I need to find the relevant section in the document to answer the question." } } }, { "text": "Customers can experience issues with 1. Data entry, 2. Payment methods, 3. Connectivity while placing the order. Which one would you like to dive into?" } ] } ] }
Text with tool calling
{ "schemaVersion": "bedrock-conversation-2024", "system": [ { "text": "You are an expert in composing function calls." } ], "toolConfig": { "tools": [ { "toolSpec": { "name": "getItemAvailability", "description": "Retrieve whether an item is available in a given location", "inputSchema": { "json": { "type": "object", "properties": { "zipcode": { "type": "string", "description": "The zipcode of the location to check in" }, "quantity": { "type": "integer", "description": "The number of items to check availability for" }, "item_id": { "type": "string", "description": "The ASIN of item to check availability for" } }, "required": ["item_id", "zipcode"] } } } } ] }, "messages": [ { "role": "user", "content": [ { "text": "I need to check whether there are twenty pieces of the following item available. Here is the item ASIN on Amazon: id-123. Please check for the zipcode 94086" } ] }, { "role": "assistant", "content": [ { "reasoningContent": { "reasoningText": { "text": "The user wants to check how many pieces of the item with ASIN id-123 are available in the zipcode 94086" } } }, { "toolUse": { "toolUseId": "getItemAvailability_0", "name": "getItemAvailability", "input": { "zipcode": "94086", "quantity": 20, "item_id": "id-123" } } } ] }, { "role": "user", "content": [ { "toolResult": { "toolUseId": "getItemAvailability_0", "content": [ { "text": "[{\"name\": \"getItemAvailability\", \"results\": {\"availability\": true}}]" } ] } } ] }, { "role": "assistant", "content": [ { "text": "Yes, there are twenty pieces of item id-123 available at 94086. Would you like to place an order or know the total cost?" } ] } ] }
Text with reasoning
{ "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." } ] } ] }

支援的功能

下表比較跨 Nova 模型版本的 SFT 功能支援。

模型版本的 SFT 功能支援
功能 SFT on Nova 2.0
文字理解 Nova 2.0 Lite 支援。請參閱 一般/文字理解
影像理解 Nova 2.0 Lite 支援。請參閱 影像理解
影片理解 Nova 2.0 Lite 支援。請參閱 影片理解
理解文件 Nova 2.0 Lite 支援。請參閱 理解文件
工具呼叫 Nova 2.0 Lite 支援。請參閱 工具呼叫
推理 Nova 2.0 Lite 支援。請參閱 推理

一般/文字理解

本節摘要說明在 Amazon Nova 2 訓練資料上準備 SFT 的一般限制條件。

限制條件

一般資料集限制條件
限制條件 詳細資訊
資料集格式 JSONL (每行一個 JSON 物件)。檔案名稱只能包含英數字元、底線、連字號、斜線和點。
最小範例 8
範例上限 20k
內容長度 32k
資料集同質性 資料集無法混合不同的媒體模式。使用文字搭配影像、文字搭配影片,或文字搭配文件,但不是組合。
保留的關鍵字 User:Bot:Assistant:System:<image><video>[EOS]。 包含這些關鍵字的提示會導致訓練任務失敗。將它們替換為具有類似意義的不同關鍵字。

最佳實務

  • 微調的最低資料大小取決於任務 (即複雜或簡單),但我們建議您為希望模型學習的每個任務至少提供 200 個範例。

  • 我們建議您在訓練和推論期間以零樣本設定使用最佳化提示詞,以獲得最佳結果。

  • 優先考慮品質而非數量。數百個高品質、一致的範例通常優於數千個雜訊或矛盾的範例。

範例輸入

  • schemaVersion 可以是任何字串值

  • 支援的角色為 userassistant。(選用) system 回合可以是客戶提供的自訂系統提示詞。

  • 第一個回合 messages 應一律以 "role": "user" 開頭。最後一輪是機器人的回應,以 表示"role": "assistant"

{ "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" } ] } ] }

影像理解

SFT 支援訓練以映像為基礎的任務,讓您的模型了解如何分析和回應有關映像的問題。

限制條件

影像限制條件
限制條件 詳細資訊
支援的格式 PNG、JPEG、GIF、WebP
每個範例的影像上限 10
影像檔案大小上限 10 MB
資料集同質性 範例可以有影像和文字,但不能將影像與其他模態 (影片、文件) 結合。
S3 位置 image.source.s3Location.uri 必須與資料集位於相同的 Amazon S3 儲存貯體中。例如,如果您的資料集位於 s3://amzn-s3-demo-bucket/train/train.jsonl 中,則您的影像或影片必須位於 s3://amzn-s3-demo-bucket

最佳實務

  • 確保映像是高品質且與任務相關。

  • 提供涵蓋不同影像類型和問題格式的多樣化範例。

  • 包含參考影像內容特定層面的明確問題。

範例輸入

{ "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": [ { "text": "The highlighted country is New Zealand" } ] } ] }

影片理解

SFT 支援視訊型任務的訓練,讓您的模型了解如何分析和回應有關視訊內容的問題。

限制條件

影片限制條件
限制條件 詳細資訊
支援的格式 MOV、MKV、MP4、WebM
每個範例的影片數量上限 1
影片檔案大小上限 50 MB
最大視訊持續時間 15 分鐘
資料集同質性 範例可以有影片和文字,但無法將影片與其他模態 (影像、文件) 結合。
S3 位置 video.source.s3Location.uri 必須與資料集位於相同的 Amazon S3 儲存貯體中。例如,如果您的資料集位於 中s3://amzn-s3-demo-bucket/train/train.jsonl,則您的影片必須位於 s3://amzn-s3-demo-bucket

最佳實務

  • 保持影片簡潔,並專注於與您的任務相關的內容。

  • 確保影片品質足以讓模型擷取有意義的資訊。

  • 提供參考影片內容特定層面的明確問題。

  • 包含涵蓋不同影片類型和問題格式的多樣化範例。

範例輸入

{ "schemaVersion": "bedrock-conversation-2024", "messages": [ { "role": "user", "content": [ { "text": "What are the ways in which a customer can experience issues during checkout on Amazon?" }, { "video": { "format": "mp4", "source": { "s3Location": { "uri": "s3://my-bucket-name/path/to/videos/customer_service_debugging.mp4", "bucketOwner": "123456789012" } } } } ] }, { "role": "assistant", "content": [ { "text": "Customers can experience issues with 1. Data entry, 2. Payment methods, 3. Connectivity while placing the order. Which one would you like to dive into?" } ] } ] }

理解文件

SFT 支援訓練以文件為基礎的任務,讓您的模型了解如何分析和回應有關 PDF 文件的問題。

限制條件

文件限制條件
限制條件 詳細資訊
支援的格式 PDF
文件大小上限 10 MB
資料集同質性 範例可以有文件和文字,但不能將文件與其他形式 (影像、影片) 混合。
S3 位置 document.source.s3Location.uri 必須與資料集位於相同的 Amazon S3 儲存貯體中。例如,如果您的資料集位於 中s3://amzn-s3-demo-bucket/train/train.jsonl,則您的文件必須位於 s3://amzn-s3-demo-bucket

最佳實務

  • 確保文件格式清晰,且文字可擷取。

  • 提供涵蓋不同文件類型和問題格式的多樣化範例。

  • 包含推理內容,以協助模型學習文件分析模式。

範例輸入

{ "schemaVersion": "bedrock-conversation-2024", "messages": [ { "role": "user", "content": [ { "text": "What are the ways in which a customer can experience issues during checkout on Amazon?" }, { "document": { "format": "pdf", "source": { "s3Location": { "uri": "s3://my-bucket-name/path/to/documents/customer_service_debugging.pdf", "bucketOwner": "123456789012" } } } } ] }, { "role": "assistant", "content": [ { "text": "Customers can experience issues with 1. Data entry, 2. Payment methods, 3. Connectivity while placing the order. Which one would you like to dive into?" } ] } ] }

工具呼叫

SFT 支援工具呼叫模式的訓練模型,讓您的模型了解呼叫外部工具或函數的時機和方式。

限制條件

工具呼叫限制條件
限制條件 詳細資訊
支援的格式 ToolResult 內容的文字或 JSON
ToolUse 置放 ToolUse 只能以助理輪換顯示
ToolResult 置放 ToolResult 必須僅顯示在使用者轉彎中
inputSchema 格式 toolSpec 中的 inputSchema 必須是有效的 JSON 結構描述物件
toolUseId 比對 每個 ToolResult 必須參考上述助理 toolUseId中的有效ToolUse,每個toolUseId 在每次對話中只使用一次

最佳實務

  • 確保您的工具定義在所有訓練範例之間保持一致。

  • 此模型會從您提供的示範中學習工具叫用模式。

  • 包含何時使用每個工具以及何時不使用工具的各種範例。

範例輸入

{ "schemaVersion": "bedrock-conversation-2024", "system": [ { "text": "You are an expert in composing function calls." } ], "toolConfig": { "tools": [ { "toolSpec": { "name": "getItemAvailability", "description": "Retrieve whether an item is available in a given location", "inputSchema": { "json": { "type": "object", "properties": { "zipcode": { "type": "string", "description": "The zipcode of the location to check in" }, "quantity": { "type": "integer", "description": "The number of items to check availability for" }, "item_id": { "type": "string", "description": "The ASIN of item to check availability for" } }, "required": ["item_id", "zipcode"] } } } } ] }, "messages": [ { "role": "user", "content": [ { "text": "I need to check whether there are twenty pieces of the following item available. Here is the item ASIN on Amazon: id-123. Please check for the zipcode 94086" } ] }, { "role": "assistant", "content": [ { "toolUse": { "toolUseId": "getItemAvailability_0", "name": "getItemAvailability", "input": { "zipcode": "94086", "quantity": 20, "item_id": "id-123" } } } ] }, { "role": "user", "content": [ { "toolResult": { "toolUseId": "getItemAvailability_0", "content": [ { "text": "[{\"name\": \"getItemAvailability\", \"results\": {\"availability\": true}}]" } ] } } ] }, { "role": "assistant", "content": [ { "text": "Yes, there are twenty pieces of item id-123 available at 94086. Would you like to place an order or know the total cost?" } ] } ] }

推理

合理的內容 (也稱為chain-of-thought) 會在產生最終答案之前擷取模型的中繼思考步驟。

限制條件

原因限制
限制條件 詳細資訊
支援的格式 僅限文字。不支援以影像為基礎的推理內容。
配置 助理只會透過 reasoningContent 欄位轉彎。
格式化 使用純文字。除非任務特別要求,</thinking>否則請避免標記標籤,例如 <thinking>和 。

最佳實務

  • 高品質的推理內容應包括中繼想法、邏輯扣除、step-by-step問題解決方法,以及步驟和結論之間的明確關聯。

  • 您可以在多轉對話中reasoningContent跨多個助理轉彎納入 。

  • 如果您的資料集缺少推理追蹤,您可以使用像 Nova Premier 這樣的推理能力模型來建立它們。

範例輸入

{ "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." } ] } ] }

其他備註

如何計算損失:

  • 使用推理內容 – 訓練損失包括推理權杖和最終輸出權杖。

  • 沒有推理內容 – 僅根據最終輸出字符計算訓練損失。

當您的訓練資料具有推理權杖時,請在訓練組態reasoning_enabled: true中設定 ,您希望模型在產生最終輸出之前產生思維權杖,或者您需要改善複雜推理任務的效能。

reasoning_enabled: false 當您的訓練資料沒有推理權杖時設定 ,您要針對無法受益於明確推理步驟的直接任務進行訓練,或您想要最佳化速度並減少權杖用量時設定 。

reasoning_enabled = true 允許使用 在非合理資料集上訓練 Nova。不過,這樣做可能會導致模型失去其推理功能,因為 Nova 主要學習在不套用推理的情況下產生資料中呈現的回應。一般而言,在使用推理資料集時啟用訓練推理和推論,並在使用非合理資料集時停用兩者推理。

設計有效的訓練範例

您的訓練資料應該示範您希望模型展現的行為。SFT 會教導模型如何回應,而不是知道什麼。如果您發現自己建立訓練範例主要是為了注入事實知識 (例如,「錯誤碼 E-45 是什麼意思?」 答案為「E-45 表示感應器逾時」),請考慮 RAG 或提示工程是否可以達成相同的結果,而無需微調。

將來源資料轉換為對話格式時,請遵循下列原則:

  1. 從實際使用者查詢開始。寫入使用者轉彎,反映最終使用者在生產環境中實際提示模型的方式。避免不會反映實際使用模式的人工或過度簡化問題。

  2. 撰寫黃金標準助理回應。每個助理輪換應該是您希望模型產生的理想回應 — 在所有範例中,正確、格式正確且一致的色調和結構。

  3. 以策略方式使用系統提示。在系統轉彎中放置持久性指示,例如輸出格式、角色和網域內容。在訓練和推論期間使用相同的系統提示,以獲得最佳結果。

  4. 讓範例專注於每個範例的一個技能。如果您需要模型進行分類、回答問題和總結,請為每個技能建立單獨的範例集,而不是將多個技能結合在單一範例中。

  5. 優先考慮品質而非數量。數百個高品質、一致的範例通常優於數千個雜訊或矛盾的範例。在訓練之前刪除並檢閱您的資料。

常見的資料轉換模式

下列模式說明如何將常見的企業資料格式轉換為有效的 SFT 訓練範例。

模式 1:要分類或查詢的結構化記錄

當您的來源資料是具有 issuecause和 等欄位的記錄資料表或資料庫resolution時,請將每個記錄作為使用者問題框架,其中包含相關的輸入欄位和助理回應作為目標輸出欄位。

// train.jsonl { "schemaVersion": "bedrock-conversation-2024", "system": [ { "text": "You are a technical support assistant. Given an issue description, identify the most likely root cause and recommended resolution." } ], "messages": [ { "role": "user", "content": [ { "text": "A user reports: 'Application crashes on startup after the latest update.' What is the likely cause and resolution?" } ] }, { "role": "assistant", "content": [ { "text": "Cause: Incompatible configuration file from the previous version.\nResolution: Delete the local configuration cache and restart the application to regenerate default settings." } ] } ] }
模式 2:結構化問答的階層或分類資料

當您的來源資料是程式碼階層或分類,例如產品類別樹狀目錄或分類系統時, 會產生問題,要求模型導覽階層。在系統提示或使用者轉彎中包含分類內容。

// train.jsonl { "schemaVersion": "bedrock-conversation-2024", "system": [ { "text": "You are a product catalog assistant. Answer questions about product categories and classifications accurately." } ], "messages": [ { "role": "user", "content": [ { "text": "What top-level category does product code 'EL-4520' belong to, and what subcategories does it include?" } ] }, { "role": "assistant", "content": [ { "text": "Product code EL-4520 belongs to the Electronics category. It includes the subcategories: Audio Equipment, Portable Speakers, and Wireless Accessories." } ] } ] }
模式 3:教學對話方塊的程序文件

當您的來源資料包含標準操作程序、執行手冊或step-by-step指南時,請將程序轉換為任務導向問題。使用者詢問如何執行任務,助理會以一致的格式提供步驟。

// train.jsonl { "schemaVersion": "bedrock-conversation-2024", "system": [ { "text": "You are an IT operations assistant. Provide step-by-step instructions based on approved runbooks and standard operating procedures." } ], "messages": [ { "role": "user", "content": [ { "text": "How do I reset a user's multi-factor authentication when they have lost access to their device?" } ] }, { "role": "assistant", "content": [ { "text": "Follow these steps to reset a user's multi-factor authentication:\n1. Verify the user's identity using the approved verification procedure.\n2. Disable the existing MFA configuration in the identity management console.\n3. Generate a new temporary access code and send it to the user's verified email.\n4. Instruct the user to log in with the temporary code and re-enroll their new device.\n5. Confirm the new MFA device is working by requesting a test authentication.\n6. Document the reset in the support ticket." } ] } ] }
注意

在模式 1 和 2 中,如果事實內容 (例如程式碼、類別或解析度) 尚未存在於模型的預先訓練資料中,請考慮使用 RAG 在推論時間提供此資訊,而不是僅依賴 SFT 來記住它。SFT 最有效地教導模型回應格式和推理模式,而 RAG 會處理事實基礎。