

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

# 建立和管理工作者任務範本
<a name="a2i-instructions-overview"></a>

您可以透過建立*工作者任務範本*來為工作者建立任務使用者介面。工作者任務範本是一個 HTML 檔案，用來顯示您的輸入資料和指示，以協助工作者完成您的任務。

對於 Amazon Rekognition 或 Amazon Textract 任務類型，您可以使用圖形化使用者介面 (GUI) 自訂預先製作的工作者任務範本，並避免與 HTML 程式碼互動。對於此選項，請使用在[建立人工審核工作流程 (主控台)](a2i-create-flow-definition.md#a2i-create-human-review-console)中的指示以在 Amazon SageMaker AI 主控台中建立人工審核工作流程，並自訂工作者任務範本。使用這些指示建立範本後，範本就會出現在[增強版 AI 主控台](https://console.aws.amazon.com/a2i)的工作者任務範本頁面上。

如果您要為自訂任務類型建立人工審核工作流程，則必須使用 HTML 程式碼建立*自訂工作者任務範本*。如需更多詳細資訊，請參閱 [建立自訂工作者任務範本](a2i-custom-templates.md)。

如果您使用 HTML 建立範本，則必須使用此範本在 Amazon A2I 主控台中產生 Amazon A2I *人工任務使用者介面 Amazon Resource Name (ARN)*。此 ARN 的格式如下：`arn:aws:sagemaker:<aws-region>:<aws-account-number>:human-task-ui/<template-name>`。此 ARN 與工作者任務範本資源相關聯，您可以在一或多個人工審核工作流程 (流程定義) 中使用此資源。

使用在 [建立工作者任務範本](a2i-worker-template-console.md#a2i-create-worker-template-console) 中找到的後續指示或使用 [https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateHumanTaskUi.html](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateHumanTaskUi.html) API 作業，使用工作者任務範本產生人工任務使用者介面 ARN。

**Topics**
+ [建立和刪除工作者任務範本](a2i-worker-template-console.md)
+ [建立自訂工作者任務範本](a2i-custom-templates.md)
+ [建立良好的工作者指示](a2i-creating-good-instructions-guide.md)

# 建立和刪除工作者任務範本
<a name="a2i-worker-template-console"></a>

您可以使用工作者範本來自訂介面和指示，讓工作者在處理您的任務時看到。使用此頁面上的指示，在 Amazon SageMaker AI 主控台增強版 AI 區域中建立工作者任務範本。為 Amazon Textract 和 Amazon Rekognition 任務提供了一個入門範本。若要了解如何使用 HTML Crowd 元素來自訂範本，請參閱[建立自訂工作者任務範本](a2i-custom-templates.md)。

當您在 SageMaker AI 主控台的增強版 AI 區域的工作者任務範本頁面中建立工作者範本時，會產生工作者任務範本 ARN。當您使用 API 作業 [https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateFlowDefinition.html](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateFlowDefinition.html) 建立一個流程定義時，請使用這個 ARN 作為 `HumanTaskUiArn` 的輸入。在主控台的人工審核工作流程頁面上建立流程定義時，您可以選擇此範本。

如果您要為 Amazon Textract 或 Amazon Rekognition 任務類型建立工作者任務範本資源，則可以在工作者任務範本主控台頁面上預覽從範本產生的工作者使用者介面。您必須將[啟用工作者任務範本預覽](a2i-permissions-security.md#permissions-for-worker-task-templates-augmented-ai)中所述政策連接到用於預覽範本的 IAM 角色。

## 建立工作者任務範本
<a name="a2i-create-worker-template-console"></a>

您可以建立工作者任務範本，請使用 SageMaker AI 主控台和使用 SageMaker API 作業 [https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateHumanTaskUi.html](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateHumanTaskUi.html)。

**建立工作者任務範本 (主控台)**

1. 在 [https://console.aws.amazon.com/a2i/](https://console.aws.amazon.com/a2i) 開啟 Amazon A2I 主控台。

1. 在左側導覽窗格中的 **Amazon 增強版 AI**，選擇**工作者任務範本**。

1. 選擇**建立範本**。

1. 在**範本名稱**中，輸入唯一名稱。

1. (選用) 輸入 **IAM 角色**，授與 Amazon A2I 代表您呼叫服務所需的許可。

1. 在**範本類型**中，從下拉式清單中選擇範本類型。如果您要為 **Textract - 表單擷取**或 **Rekognition - 影像審核**任務建立範本，請選擇適當的選項。

1. 輸入自訂範本元素，如下所示：
   + 如果您選取 Amazon Textract 或 Amazon Rekognition 任務範本，**範本編輯器**中會自動填入可供您自訂的預設範本。
   + 如果您使用自訂範本，請在編輯器中輸入您預先定義的範本。

1. (選擇性) 若要完成此步驟，您必須提供具有讀取在**步驟 5** 中轉譯在使用者介面上之 Amazon S3 物件的權限的 IAM 角色 ARN。

   如果您正在為 Amazon Textract 或 Amazon Rekognition 建立範本，則只能預覽範本。

   選擇**查看預覽**來預覽工作者看到的介面和指示。這是互動式預覽。完成範例任務並選擇**提交** 後，您會看到剛才執行的任務所產生的輸出。

   如果您要為自訂任務類型建立工作者任務範本，則可以使用 `RenderUiTemplate` 預覽工作者任務使用者介面。如需詳細資訊，請參閱[預覽工作者任務範本](a2i-custom-templates.md#a2i-preview-your-custom-template)。

1. 當您對範例感到滿意時，請選擇**建立**。

建立範本之後，當您在主控台建立人工審核工作流程時，您可以選取該範本。您的範本也會出現在 SageMaker AI 主控台的 **Amazon 增強版 AI** 區段中的**工作者任務範本**之下。選擇您的範本以檢視其 ARN。使用 [https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateFlowDefinition.html](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateFlowDefinition.html) API 作業時，請使用此 ARN。

**使用工作者任務範本 (API) 建立工作者任務範本**  
若要使用 SageMaker API 作業 [https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateHumanTaskUi.html](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateHumanTaskUi.html) 產生工作者任務範本，請在 `HumanTaskUiName` 中指定使用者介面的名稱，然後在 `UiTemplate` 下的 `Content` 輸入您的 HTML 範本。查找有關支援此 API 作業的特定語言 SDK 的文件，請參閱 [https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateHumanTaskUi.html](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateHumanTaskUi.html) 的**另請參閱**部分。

## 刪除工作者任務範本
<a name="sms-delete-worker-task-template"></a>

一旦您已經建立工作者任務範本，您可以進行刪除，請使用 SageMaker AI 主控台或 SageMaker API 作業 [https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_DeleteHumanTaskUi.html](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_DeleteHumanTaskUi.html)。

當您刪除工作者任務範本時，您無法使用該範本建立的人工審核工作流程 (流程定義) 來啟動人工循環。任何已使用您刪除的工作者任務範本建立的人工循環都會繼續處理，直到完成為止，不會受到影響。

**刪除工作者任務範本 (主控台)**

1. 在 [https://console.aws.amazon.com/a2i/](https://console.aws.amazon.com/a2i) 開啟 Amazon A2I 主控台。

1. 在左側導覽窗格中的 Amazon 增強版 AI，選擇**工作者任務範本**。

1. 選取您要刪除的範本。

1. 選取**刪除**。

1. 出現一個模式以確認您的選擇。選取**刪除**。

**刪除工作者任務範本 (API)**  
若要使用 SageMaker API 作業 [https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_DeleteHumanTaskUi.html](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_DeleteHumanTaskUi.html) 刪除工作者任務範本，請在 `HumanTaskUiName` 中指定使用者介面的名稱。

# 建立自訂工作者任務範本
<a name="a2i-custom-templates"></a>

*Crowd HTML 元素*是 Web 元件，提供許多任務 Widget 和設計元素，可根據您想要詢問的問題而量身打造。您可以使用這些 Crowd 元素來建立自訂工作者範本，並將此範本與 Amazon 增強版 AI (Amazon A2I) 人工審核工作流程整合，以自訂工作者主控台和指示。

如需 Amazon A2I 使用者可用的所有 HTML crowd 元素的清單，請參閱[Crowd HTML 元素參考](sms-ui-template-reference.md)。針對範本的範例，請參閱 [AWS Github 儲存庫](https://github.com/aws-samples/amazon-a2i-sample-task-uis)，其中包含超過 60 個範例自訂任務範本。

## 在本機開發範本
<a name="developing-templates-locally"></a>

在主控台測試範本處理傳入資料的方式時，您可以將下列程式碼新增至 HTML 檔案頂端，在瀏覽器中測試範本 HTML 和自訂元素的外觀和風格。

```
<script src="https://assets.crowd.aws/crowd-html-elements.js"></script>
```

此作業會載入必要的程式碼來轉譯自訂 HTML 元素。如果您想要以您偏好的編輯器 (而不是主控台) 來開發範本外觀和風格，請使用此程式碼。

此程式碼不會剖析變數。在本機開發時，您可能使用範例內容來取代。

## 使用外部資產
<a name="a2i-custom-template-using-external-assets"></a>

Amazon 增強版 AI 自訂範本可讓您嵌入外部指令碼和樣式表。例如，下列標題會將位於 `https://www.example.com/my-enhancement-styles.css` 的 `text/css` 樣式表名稱 `stylesheet` 內嵌至自訂範本。

**Example**  

```
<script src="https://www.example.com/my-enhancment-script.js"></script>
<link rel="stylesheet" type="text/css" href="https://www.example.com/my-enhancement-styles.css">
```

如果發生錯誤，請確保您的原始伺服器傳送資產的正確 MIME 類型和編碼標題。

例如，遠端指令碼的 MIME 和編碼類型為 `application/javascript;CHARSET=UTF-8`。

遠端樣式表的 MIME 和編碼類型為 `text/css;CHARSET=UTF-8`。

## 追蹤您的變數
<a name="a2i-custom-template-step2-UI-vars"></a>

建立自訂範本時，您必須在其中新增變數，以表示資料片段，這些資料片段可能會依任務或工作者而有所不同。如果您從其中一個範例範本開始，請確定您知道該範本已使用的變數。

例如，對於將增強版 AI 人工審核循環與 Amazon Textract 文字審核任務整合的自訂範本，使用 `{{ task.input.selectedAiServiceResponse.blocks }}` 取得初始值輸入資料。對於 Amazon 增強版 AI (Amazon A2I) 與 Amazon Rekognition 整合，則是使用 `{{ task.input.selectedAiServiceResponse.moderationLabels }}`。對於自訂任務類型，您需要決定任務類型的輸入參數。使用 `{{ task.input.customInputValuesForStartHumanLoop}}`，其中指定 `customInputValuesForStartHumanLoop`。

## Amazon Textract 的自訂範本範例
<a name="a2i-custom-templates-textract-sample"></a>

所有自訂範本都以 `<crowd-form> </crowd-form>` 元素開始和結束。如同標準 HTML `<form>` 元素，所有表單程式碼都應該放置於這些元素間。

對於 Amazon Textract 文件分析任務，請使用 `<crowd-textract-analyze-document>` 元素。它使用以下屬性：
+ `src` – 指定要註釋的影像檔案 URL。
+ `initialValue` – 針對工作者使用者介面中找到的屬性設定初始值。
+ `blockTypes` (必要) – 決定工作者可以執行的分析類型。目前僅支援 `KEY_VALUE_SET`。
+ `keys` (必要) - 指定工作者可新增的新索引鍵和相關文字值。
+ `no-key-edit` (必要) - 防止工作者編輯經由 `initialValue` 傳遞的註釋索引鍵。
+ `no-geometry-edit` - 防止工作者編輯經由 `initialValue` 傳遞的註釋多邊形。

對於 `<crowd-textract-analyze-document>` 元素的子系，您必須有兩個區域。您可以在這些區域中使用任意 HTML 和 CSS 元素。
+ `<full-instructions>` – 工具中**檢視完整說明**連結提供的說明。這可以保留空白，但我們建議您提供完整的指示，以獲得更好的結果。
+ `<short-instructions>` – 在工具側邊欄中顯示的任務簡短描述。這可以保留空白，但我們建議您提供完整的指示，以獲得更好的結果。

 Amazon Textract 範本看起來與下列類似。

**Example**  

```
<script src="https://assets.crowd.aws/crowd-html-elements.js"></script>
{% capture s3_uri %}http://s3.amazonaws.com/{{ task.input.aiServiceRequest.document.s3Object.bucket }}/{{ task.input.aiServiceRequest.document.s3Object.name }}{% endcapture %}

<crowd-form>
  <crowd-textract-analyze-document
    src="{{ s3_uri | grant_read_access }}"
    initial-value="{{ task.input.selectedAiServiceResponse.blocks }}"
    header="Review the key-value pairs listed on the right and correct them if they don't match the following document."
    no-key-edit
    no-geometry-edit
    keys="{{ task.input.humanLoopContext.importantFormKeys }}"
    block-types="['KEY_VALUE_SET']"
  >
    <short-instructions header="Instructions">
      <style>
        .instructions {
          white-space: pre-wrap;
        }
        .instructionsImage {
          display: inline-block;
          max-width: 100%;
        }
      </style>
      <p class='instructions'>Choose a key-value block to highlight the corresponding key-value pair in the document.

If it is a valid key-value pair, review the content for the value. If the content is incorrect, correct it.

The text of the value is incorrect, correct it.
<img class='instructionsImage' src="https://example-site/correct-value-text.png" />

A wrong value is identified, correct it.
<img class='instructionsImage' src="https://example-site/correct-value.png" />

If it is not a valid key-value relationship, choose No.
<img class='instructionsImage' src="https://example-site/not-a-key-value-pair.png" />

If you can’t find the key in the document, choose Key not found.
<img class='instructionsImage' src="https://example-site/key-is-not-found.png" />

If the content of a field is empty, choose Value is blank.
<img class='instructionsImage' src="https://example-site/value-is-blank.png" />

<b>Examples</b>
Key and value are often displayed next to or below to each other.

Key and value displayed in one line.
<img class='instructionsImage' src="https://example-site/sample-key-value-pair-1.png" />

Key and value displayed in two lines.
<img class='instructionsImage' src="https://example-site/sample-key-value-pair-2.png" />

If the content of the value has multiple lines, enter all the text without a line break. Include all value text even if it extends beyond the highlight box.
<img class='instructionsImage' src="https://assets.crowd.aws/images/a2i-console/multiple-lines.png" /></p>
    </short-instructions>

    <full-instructions header="Instructions"></full-instructions>
  </crowd-textract-analyze-document>
</crowd-form>
```

## Amazon Rekognition 的自訂範本範例
<a name="a2i-custom-templates-rekognition-sample"></a>

所有自訂範本都以 `<crowd-form> </crowd-form>` 元素開始和結束。如同標準 HTML `<form>` 元素，所有表單程式碼都應該放置於這些元素間。對於 Amazon Rekognition 自訂任務範本，請使用 `<crowd-rekognition-detect-moderation-labels>` 元素。此元素支援下列屬性：
+ `categories` - 字串陣列*或*物件陣列，其中每個物件都有一個 `name` 欄位。
  + 如果以物件形式傳入類別，則情況如下：
    + 顯示的類別是 `name` 欄位的值。
    + 傳回的答案包含所選任何類別的*完整*物件。
  + 如果以字串形式傳入類別，則情況如下：
    + 傳回的答案是所選全部字串的陣列。
+ `exclusion-category` – 您可以設定這個屬性，在使用者介面中的類別下建立按鈕。當使用者選擇此按鈕，所有類別將取消選取並停用。如果工作者再次選擇按鈕，您可以重新讓使用者選擇類別。如果工作者在您選取按鈕後，選取**提交**按鈕來提交任務，該任務將會傳回空陣列。

對於 `<crowd-rekognition-detect-moderation-labels>` 元素的子系，您必須有兩個區域。
+ `<full-instructions>` – 工具中**檢視完整說明**連結提供的說明。這可以保留空白，但我們建議您提供完整的指示，以獲得更好的結果。
+ `<short-instructions>` – 在工具側邊欄中顯示的任務簡短描述。這可以保留空白，但我們建議您提供完整的指示，以獲得更好的結果。

使用這些元素的範本看起來與下列類似。

```
<script src="https://assets.crowd.aws/crowd-html-elements.js"></script>
{% capture s3_uri %}http://s3.amazonaws.com/{{ task.input.aiServiceRequest.image.s3Object.bucket }}/{{ task.input.aiServiceRequest.image.s3Object.name }}{% endcapture %}

<crowd-form>
  <crowd-rekognition-detect-moderation-labels
    categories='[
      {% for label in task.input.selectedAiServiceResponse.moderationLabels %}
        {
          name: "{{ label.name }}",
          parentName: "{{ label.parentName }}",
        },
      {% endfor %}
    ]'
    src="{{ s3_uri | grant_read_access }}"
    header="Review the image and choose all applicable categories."
  >
    <short-instructions header="Instructions">
      <style>
        .instructions {
          white-space: pre-wrap;
        }
      </style>
      <p class='instructions'>Review the image and choose all applicable categories.
If no categories apply, choose None.

<b>Nudity</b>
Visuals depicting nude male or female person or persons

<b>Graphic Male Nudity</b>
Visuals depicting full frontal male nudity, often close ups

<b>Graphic Female Nudity</b>
Visuals depicting full frontal female nudity, often close ups

<b>Sexual Activity</b>
Visuals depicting various types of explicit sexual activities and pornography

<b>Illustrated Nudity or Sexual Activity</b>
Visuals depicting animated or drawn sexual activity, nudity, or pornography

<b>Adult Toys</b>
Visuals depicting adult toys, often in a marketing context

<b>Female Swimwear or Underwear</b>
Visuals depicting female person wearing only swimwear or underwear

<b>Male Swimwear Or Underwear</b>
Visuals depicting male person wearing only swimwear or underwear

<b>Partial Nudity</b>
Visuals depicting covered up nudity, for example using hands or pose

<b>Revealing Clothes</b>
Visuals depicting revealing clothes and poses, such as deep cut dresses

<b>Graphic Violence or Gore</b>
Visuals depicting prominent blood or bloody injuries

<b>Physical Violence</b>
Visuals depicting violent physical assault, such as kicking or punching

<b>Weapon Violence</b>
Visuals depicting violence using weapons like firearms or blades, such as shooting

<b>Weapons</b>
Visuals depicting weapons like firearms and blades

<b>Self Injury</b>
Visuals depicting self-inflicted cutting on the body, typically in distinctive patterns using sharp objects

<b>Emaciated Bodies</b>
Visuals depicting extremely malnourished human bodies

<b>Corpses</b>
Visuals depicting human dead bodies

<b>Hanging</b>
Visuals depicting death by hanging</p>
    </short-instructions>

    <full-instructions header="Instructions"></full-instructions>
  </crowd-rekognition-detect-moderation-labels>
</crowd-form>
```

## 透過 Liquid 新增自動化
<a name="a2i-custom-templates-step2-automate"></a>

自訂範本系統使用 [Liquid](https://shopify.github.io/liquid/) 進行自動化。*Liquid* 是開放原始碼內嵌標記語言。如需詳細資訊及文件，請前往 [Liquid 首頁](https://shopify.github.io/liquid/)。

在 Liquid 中，單邊大括號和百分比符號之間的文字是指示，或執行類似控制流程或迭代之作業的*標記*。雙邊大括號之間的文字是變數，或輸出變數值的*物件*。下列清單包含兩種類型的 Liquid 標記，您可能會發現這些標記對於自動化範本輸入資料處理很有用。如果您選取下列其中一種標記類型，系統會將您重新導向至 Liquid 文件。
+ [控制流程](https://shopify.github.io/liquid/tags/control-flow/)：包括程式設計邏輯運算子例如 `if/else`、`unless` 和 `case/when`。
+ [迭代](https://shopify.github.io/liquid/tags/iteration/)：可讓您使用 for 循環之類的陳述式重複執行程式碼區塊。

  例如，下列程式碼範例將示範如何使用 Liquid `for` 標記建立 `for` 循環。此範例會循環瀏覽 Amazon Rekognition [https://docs.aws.amazon.com/rekognition/latest/dg/API_ModerationLabel.html](https://docs.aws.amazon.com/rekognition/latest/dg/API_ModerationLabel.html) 傳回的資料，並顯示 `moderationLabels` 屬性 `name` 及 `parentName`，供工作者審核：

  ```
   {% for label in task.input.selectedAiServiceResponse.moderationLabels %}
      {
        name: &quot;{{ label.name }}&quot;,
        parentName: &quot;{{ label.parentName }}&quot;,
      },
   {% endfor %}
  ```

### 使用變數篩選條件
<a name="a2i-custom-templates-step2-automate-filters"></a>

除了標準 [Liquid 篩選條件](https://shopify.github.io/liquid/filters/abs/)和動作外，Amazon 增強版 AI (Amazon A2I) 也提供幾個額外的篩選條件。在變數名稱後面加上管線 (`|`) 字元，然後指定篩選條件名稱，即可套用篩選條件。若要串連篩選條件，請使用以下格式。

**Example**  

```
{{ <content> | <filter> | <filter> }}
```

#### 自動逸出和明確逸出
<a name="a2i-custom-templates-step2-automate-filters-autoescape"></a>

根據預設，輸入都經過 HTML 逸出，以避免變數文字和 HTML 之間產生混淆。您可以明確新增 `escape` 篩選條件，讓讀取範本來源的人明白逸出正在進行。

#### escape\$1once
<a name="a2i-custom-templates-step2-automate-escapeonce"></a>

`escape_once` 可確保如果您已逸出程式碼，則不會再次逸出。例如，為了確保 `&amp;` 不會變成 `&amp;amp;`。

#### skip\$1autoescape
<a name="a2i-custom-templates-step2-automate-skipautoescape"></a>

`skip_autoescape` 當您的內容預定用做 HTML 時會有很幫助。例如，邊界框的完整說明中可能有幾段文字和一些影像。

**注意**  
請謹慎使用 `skip_autoescape`。範本中的最佳實務是避免使用 `skip_autoescape` 來傳遞功能性程式碼或標記，除非您非常確定您可以嚴格控制傳遞的內容。如果您傳遞使用者輸入，可能會讓工作者遭受跨網站指令碼攻擊。

#### to\$1json
<a name="a2i-custom-templates-step2-automate-tojson"></a>

`to_json` 會將您提供給 JavaScript 物件標記法 (JSON) 的資料進行編碼。如果你提供物件，它會將該物件序列化。

#### grant\$1read\$1access
<a name="a2i-custom-templates-step2-automate-grantreadaccess"></a>

`grant_read_access` 會接受 Amazon Simple Storage Service (Amazon S3) URI 並將其編碼為 HTTPS URL，含有該資源的短期存取憑證。這能夠將存放在 S3 儲存貯體中的照片、音訊或影片物件顯示給工作者，這些物件在其他情況下無法公開存取。

#### s3\$1presign
<a name="a2i-custom-templates-step2-automate-s3"></a>

 `s3_presign` 篩選條件的運作方式與 `grant_read_access` 篩選條件相同。`s3_presign` 採用 Amazon S3 URI，並將其編碼為具該資源短期存取字符的 HTTPS URL。這能夠將存放在 S3 儲存貯體中的照片、音訊或影片物件顯示給工作者，這些物件在其他情況下無法公開存取。

**Example 變數篩選條件的範例**  
輸入  

```
auto-escape: {{ "Have you read 'James & the Giant Peach'?" }}
explicit escape: {{ "Have you read 'James & the Giant Peach'?" | escape }}
explicit escape_once: {{ "Have you read 'James &amp; the Giant Peach'?" | escape_once }}
skip_autoescape: {{ "Have you read 'James & the Giant Peach'?" | skip_autoescape }}
to_json: {{ jsObject | to_json }}                
grant_read_access: {{ "s3://amzn-s3-demo-bucket/myphoto.png" | grant_read_access }}
s3_presign: {{ "s3://amzn-s3-demo-bucket/myphoto.png" | s3_presign }}
```

**Example**  
Output  

```
auto-escape: Have you read &#39;James &amp; the Giant Peach&#39;?
explicit escape: Have you read &#39;James &amp; the Giant Peach&#39;?
explicit escape_once: Have you read &#39;James &amp; the Giant Peach&#39;?
skip_autoescape: Have you read 'James & the Giant Peach'?
to_json: { "point_number": 8, "coords": [ 59, 76 ] }
grant_read_access: https://s3.amazonaws.com/amzn-s3-demo-bucket/myphoto.png?<access token and other params>
s3_presign: https://s3.amazonaws.com/amzn-s3-demo-bucket/myphoto.png?<access token and other params>
```

**Example 自動化分類範本的範例。**  
若要將這個簡單的文字分類範例自動化，請包括 Liquid 標記 `{{ task.input.source }}`。此範例使用 [crowd-classifier](sms-ui-template-crowd-classifier.md) 元素。  

```
<script src="https://assets.crowd.aws/crowd-html-elements.js"></script>
<crowd-form>
  <crowd-classifier 
    name="tweetFeeling"
    categories="['positive', 'negative', 'neutral', 'cannot determine']"
    header="Which term best describes this tweet?" 
  >
    <classification-target>
       {{ task.input.source }}
    </classification-target>

    <full-instructions header="Analyzing a sentiment">
      Try to determine the feeling the author 
      of the tweet is trying to express. 
      If none seems to match, choose "other."
    </full-instructions>

    <short-instructions>
      Pick the term that best describes the sentiment 
      of the tweet. 
    </short-instructions>

  </crowd-classifier>
</crowd-form>
```

## 預覽工作者任務範本
<a name="a2i-preview-your-custom-template"></a>

若要預覽自訂工作者任務範本，請使用 SageMaker AI `RenderUiTemplate` 作業。您可以搭配 AWS CLI 或偏好的 AWS SDK 使用 `RenderUiTemplate`操作。有關此 API 作業支援的特定語言 SDK 的文件，請參閱 [https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_RenderUiTemplate.html](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_RenderUiTemplate.html) 的[https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_RenderUiTemplate.html#API_RenderUiTemplate_SeeAlso](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_RenderUiTemplate.html#API_RenderUiTemplate_SeeAlso) 部分。

**先決條件**

若要預覽工作者任務範本，您使用`RoleArn`的 AWS Identity and Access Management (IAM) 角色 Amazon Resource Name (ARN) 或 ，必須具有存取範本所用 S3 物件的許可。若要了解如何設定角色或使用者，請參閱[啟用工作者任務範本預覽](a2i-permissions-security.md#permissions-for-worker-task-templates-augmented-ai)。

**若要使用 `RenderUiTemplate` 作業預覽工作者任務範本：**

1. 為 **`RoleArn`** 角色提供附加的必要政策以預覽自訂範本。

1. 在 **`Task`** 的 **`Input`** 參數中，提供 JSON 物件，其中包含範本中定義之變數的值。這些是替換 `task.input.source` 變數的變數。例如，如果您在範本中定義 task.input.text 變數，則可以在 JSON 物件中提供變數做為 `text`: `sample text`。

1. 在 **`UiTemplate`** 的 **`Content`** 參數中，插入您的範本。

設定 `RenderUiTemplate` 完成後，請使用您偏好的軟體開發套件或 AWS CLI 提交請求來轉譯範本。如果您請求成功，回應會包含 [https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_RenderUiTemplate.html#API_RenderUiTemplate_ResponseSyntax](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_RenderUiTemplate.html#API_RenderUiTemplate_ResponseSyntax)，此為可轉譯工作者使用者介面之 HTML 的 Liquid 範本。

**重要**  
若要預覽範本，您需要具有許可的 IAM 角色，以讀取在使用者介面上轉譯的 Amazon S3 物件。如需您可以連接至 IAM 角色以授與這些許可的範例政策，請參閱[啟用工作者任務範本預覽](a2i-permissions-security.md#permissions-for-worker-task-templates-augmented-ai)。

# 建立良好的工作者指示
<a name="a2i-creating-good-instructions-guide"></a>

為人工審核工作建立良好的指示，可以提高工作者完成任務的準確性。您可以修改在建立人工審核工作流程時主控台所提供的預設指示，或者，您可以使用主控台建立自訂工作者範本，再將指示包含在此範本中。在工作者完成其標籤任務的使用者介面頁面上，工作者會看到這些指示。

## 建立良好的工作者指示
<a name="a2i-good-instructions-console"></a>

Amazon 增強版 AI 主控台上有三種指示：
+ **任務描述** – 描述應該提供任務的簡潔說明。
+ **指示** – 這些指示顯示在工作者完成任務的同一個網頁上。這些指示應該提供簡單的參考，向工作者顯示完成任務的正確方法。
+ **其他指示** – 當工作者選擇**檢視完整指示**，出現的對話方塊中會顯示這些指示。我們建議您提供完成任務的詳細說明，並包含幾個範例來顯示極端案例和標籤物件時的其他困難情況。

## 將範例影像新增到您的指示
<a name="sms-using-s3-images"></a>

影像為您的工作者提供有用的範例。若要將可公開存取的影像新增到您的指示，請執行以下作業：

1. 在指示編輯器中將游標移到應該放置影像的位置。

1. 選擇編輯器工具列中的影像圖示。

1. 輸入影像的 URL。

如果指示影像位於不可公開存取的 S3 儲存貯體中，請執行以下作業：
+ 對於影像 URL，請輸入：`{{ 'https://s3.amazonaws.com/your-bucket-name/image-file-name' | grant_read_access }}`。

這樣會轉譯影像 URL 並附加短期、一次性存取碼，讓工作者的瀏覽器可以顯示影像。指示編輯器中會顯示斷裂的影像圖示，但預覽工具時會在轉譯預覽中顯示影像。如需 `grand_read_access` 元素的詳細資訊，請參閱[s3\$1presigngrant\$1read\$1accesss3\$1presign](a2i-custom-templates.md#a2i-custom-templates-step2-automate-grantreadaccess)。