本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
建立自訂指標的提示
使用 RAG 評估任務,您可以建立自己的指標,以更好地描述特定商業案例的模型效能。您可以為每個評估任務定義最多 10 個自訂指標。
若要建立自己的自訂評估指標,您需要提供下列項目:
-
包含供判斷模型使用的詳細說明的提示
-
您要用於自訂指標的評估工具模型
您也可以指定評分系統 (輸出結構描述),評估工具模型可用來對 RAG 系統的輸出進行評分。
下列各節說明如何在使用自訂指標時建立評估工具模型的提示,包括最佳實務。如果您使用 JSON 檔案建立指標,它們也會定義要使用的結構描述。
若要了解如何使用提示建立具有自訂指標的評估任務,請參閱 使用自訂指標建立僅擷取 RAG 評估任務 和 使用自訂指標建立擷取並產生 RAG 評估任務。
提示建構和最佳實務
建立自訂指標的提示時,您應該使用下列元素來建構提示:
-
角色定義 (選用) – 指示評估工具模型採用特定身分或角色
-
任務描述 – 提供有關評估任務的詳細說明
-
準則和標準 (選用) – 提供詳細的評分指導方針和評估標準
-
輸入變數 – 定義要評估的變數,例如提示和回應
依照清單中指定的順序,將這些元素包含在提示中。以下章節更詳細地描述這些元素。
角色定義
提供角色定義是選用的,但提供定義有助於建構評估。例如,如果您要建立指標來評估 RAG 系統最終輸出的散文風格,您可以考慮使用像是「撰寫導師」的角色。根據您的評估目標,「實際準確性檢驗員」或「主題專家」等角色也可能是適當的。
如果您選擇包含角色定義,它應該是您提示的第一個區段。以下範例顯示範例角色定義。
範例角色定義
You are a professional editor who is familiar with the requirements of commonly-used style manuals.
任務定義
任務定義是提示中最重要的區段,並定義您希望評估工具模型執行的任務。您的任務定義應提供有關評估任務的詳細說明 (建議至少 15 個字),並具體說明要專注於哪些方面以及如何建構評估。
如果您選擇包含任務定義,您的任務定義應該緊接在角色定義之後。
如需如何建構 LLM 提示的更多一般指引,請參閱 設計提示。
下列範例顯示指標的任務定義,著重於 RAG 系統回應遵守特定風格指南。
範例任務定義
You are provided a prompt and a response from a RAG system. The prompt asks the RAG system to follow the Chicago Manual of Style when generating its responses. Your task is to assess how closely the text in the response adheres to the style guide. Focus in particular on grammar, prose style, and citation requirements.
準則和標準
本節是選用的,可用於定義多個評估標準或提供指標的詳細評分指導方針。本節應在任務定義和輸入變數之間新增。下列範例顯示所提供範例任務定義中所指定任務的評估標準和評分指導方針。您可以在提示的此區段中一併包含這些類型的資訊或其中之一。
範例評估標準
When evaluating the response quality, consider the following: - Grammar: Does the grammar in the response follow the requirements of the style guide - Style consistency: Does the response maintain consistent capitalization, punctuation, and paragraph formatting - Citations: Does the response use the correct citation style for in-text citations and endnotes
範例評分指導方針
Please rate the quality of the response on the following scale: - Poor: Response includes errors in citation, grammar, or usage - Acceptable: Response includes only minor formatting errors - Good: Response meets all requirements of the style guide
當您建立使用 LLM 即評審的評估任務時,無論是在 AWS 管理主控台 中,或使用 AWS CLI,或其中一個 AWS SDK,您可以指定 Amazon Bedrock 的輸出結構描述,以對產生器模型的回應進行評分。請確定您為輸出結構描述指定的任何定義,都符合您在提示中定義的評分指導方針。例如,在上述範例中,您將輸出結構描述的定義指定為「不佳」、「可接受」和「良好」。如需定義輸出結構描述的更多指引,請參閱 指定輸出結構描述 (評分量表)。
輸入變數
提示的最後一個區段會指定評估工具模型執行評估所需的變數。請注意,您必須最後指定輸入變數;如果您在輸入變數之後的提示中提供進一步的指示,則評估工具模型可能無法正確評估您的指標。
您需要指定的最低輸入變數取決於您建立的評估任務類型;對於僅限擷取任務,您必須提供 {{context}},對於擷取並產生任務,您必須提供 {{prediction}}。在這兩種情況下,我們建議您也包含提供給產生器模型的提示 ({{prompt}})。下表定義您可以在提示中使用的變數,以及它們如何對應到提示資料集中的屬性。
| 輸入變數 | 定義 | 必要 (僅限擷取) | 必要 (擷取並產生) | 提示資料集屬性 |
|---|---|---|---|---|
{{prompt}} |
提供給 RAG 系統的提示 | 否 | 否 | "prompt" |
{{prediction}} |
回應產生器模型提供的回應 (僅適用於擷取並產生任務) | 否 | 是 | "output" -> "text" (僅適用於您提供自己的推論資料的任務) |
{{ground_truth}} |
提示的參考回答 | 否 | 否 | "referenceResponses" -> "content" -> "text" |
{{context}} |
為產生回應而收到的 RAG 段落 | 是 | 否 | "retrievalResults" -> "content" -> "text" |
{{reference_contexts}} |
預期被擷取的基本事實段落 | 否 | 否 | referenceContexts -> "content" -> "text" |
下列範例說明如何在提示中指定輸入變數。
範例輸入變數定義
Here is the actual task: Prompt: {{prompt}} Response: {{prediction}}
基於完整性,下列範例中提供了此使用案例的完整提示。完整提示的長度上限為 5,000 個字元。
範例自訂指標提示
You are a professional editor who is familiar with the requirements of commonly-used style manuals. You are provided a prompt and a response from a RAG system. The prompt asks the RAG system to follow the Chicago manual of style when generating its responses. Your task is to assess how closely the text in the response adheres to the style guide. Focus in particular on grammar, prose style, and citation requirements. When evaluating the response quality, consider the following: - Grammar: Does the grammar in the response follow the requirements of the style guide - Style consistency: Does the response maintain consistent capitalization, punctuation, and paragraph formatting - Citations: Does the response use the correct citation style for in-text citations and endnotes Please rate the quality of the response on the following scale: - Poor: Response includes errors in citation, grammar, or usage - Acceptable: Response includes only minor formatting errors - Good: Response meets all requirements of the style guide Here is the actual task: Prompt: {{prompt}} Response: {{prediction}}
指定輸出結構描述 (評分量表)
除了提示中的評估指導方針之外,當您使用自訂指標建立評估任務時,您可以透過指定輸出結構描述來定義指標的評分量表。此結構描述包含量表值及其對應的定義。量表的值可以是數值或字串,但不能是兩者的混合。
我們強烈建議您定義評分量表。如果您並未這麼做,Amazon Bedrock 可能無法正確剖析評估工具模型的輸出,以在主控台中以圖形顯示結果,或計算平均分數的計算。您可以在使用主控台建立指標時定義評分量表,或者如果您使用 AWS SDK 或 AWS CLI 建立指標,則可以使用 ratingScale 屬性。
當您定義評分量表時,Amazon Bedrock 會將結構化輸出指示新增至評估工具模型提示。由於結構化輸出的格式在評估工具模型之間不同,因此請務必分別定義評分量表,且不要將其包含在主要提示中。如果您在主控台中建立指標並定義評分量表,您可以看到最終提示,包括預覽文字區域中的結構化輸出指示。
為每個量表值提供定義時,請確定您在輸出結構描述定義中使用的定義完全符合您在提示中定義評分指導方針的方式。這些定義應該最多有五個字,且限制為 100 個字元。請避免在定義中使用冠詞 (「a」和「the」)。您可以在提示中使用說明文字,為評估工具模型提供更詳細的回應評分定義。
下表說明如何在提示中描述評分指導方針,以及如何在輸出結構描述中定義對應的量表定義。
| 提示評分指導方針 | 結構描述量表值 | 結構描述量表定義 |
|---|---|---|
- Poor: The response fails to meet the basic requirements of the prompt and contains significant errors and omissions |
0 |
Poor |
- Good: The response adequately meets the basic requirements of the prompt but may contain minor errors or omissions |
1 |
Good |
- Excellent: The response fully meets the prompt with comprehensive, accurate, and valuable information |
2 |
Excellent |
此範例使用量表的整數值,但您也可以使用字串。
若要了解如何在建立評估任務時指定結構描述,請參閱 使用自訂指標建立模型評估任務。
建立 JSON 檔案以建立自訂指標
當您在主控台中建立使用自訂指標的評估任務時,您可以選擇從定義指標的本機電腦上傳 JSON 檔案。如果您選擇使用 JSON 檔案來使用主控台建立自訂指標,則無法使用主控台 UI 中的文字區域來定義評分量表,因此您必須將其包含在 JSON 定義中。我們建議您在建立自訂指標時一律定義評分量表。
下列範例顯示用於建立自訂指標的 JSON 檔案格式,包括數值或字串評分量表,或無評分量表。在每個案例中,將完整的提示新增為 "instructions" 屬性中的字串。
當您使用一或多個自訂指標建立評估任務時,Amazon Bedrock 會將指標定義存放為您指定的輸出 S3 儲存貯體中的 JSON 檔案。您可以透過導覽至 s3:// 來存取這些檔案。S3-output-bucket-name/job-name/job-uuid/custom_metrics