

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

# 创建和管理工作人员任务模板
<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 控制台中自定义工作人员任务模板。使用这些说明创建模板后，该模板将显示在 [Augmented AI 控制台](https://console.aws.amazon.com/a2i)的工作人员任务页面上。

如果您在为自定义任务类型创建人工审核工作流，则必须使用 HTML 代码创建*自定义工作人员任务模板*。有关更多信息，请参阅 [创建自定义工作人员模板](a2i-custom-templates.md)。

如果您使用 HTML 创建模板，则必须使用此模板在 Amazon A2I 控制台中生成 *Amazon A2I 人工任务 UI Amazon 资源名称 (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 操作来生成工作人员任务 UI 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)。

在 AI 控制台增强型 AI 区域的工作人员任务模板页面中创建工作人员模板时，会生成工作人员任务模板 ARN。 SageMaker 在使用 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 任务类型创建工作人员任务模板资源，则可以在工作人员任务模板控制台页面上预览从模板生成的工作人员 UI。您必须将[启用工作人员任务模板预览](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. 打开 Amazon A2I 控制台，网址为。[https://console.aws.amazon.com/a2i/](https://console.aws.amazon.com/a2i)

1. 在左侧导航窗格中的 **Amazon Augmented AI** 下，选择**工作人员任务模板**。

1. 选择**创建模板**。

1. 在 **Template name (模板名称)** 中，输入一个唯一名称。

1. （可选）输入一个 **IAM 角色**，该角色向 Amazon A2I 授予代表您调用服务所需的权限。

1. 在**模板类型**中，从下拉菜单中选择模板类型。如果要为 **Textract-form extraction (Textract 表单提取)** 或 **Rekognition -image moderation (Rekognition 图像监管)** 任务创建模板，请选择适当的选项。

1. 输入您的自定义模板元素，如下所示：
   + 如果您已选择 Amazon Textract 或 Amazon Rekognition 任务模板，则**模板编辑器**将自动填充可自定义的默认模板。
   + 如果您使用的是自定义模板，请在编辑器中输入预定义的模板。

1. （可选）要完成此步骤，您必须向 IAM 角色 ARN 提供读取在**步骤 5** 中的用户界面上呈现的 Amazon S3 对象的权限。

   只能在为 Amazon Textract 或 Amazon Rekognition 创建模板时预览模板。

   选择**查看预览**可预览工作人员将看到的界面和说明。这是一个交互式预览。在完成示例任务并选择 **Submit (提交)** 后，您将看到刚刚执行的任务所生成的输出。

   如果要为自定义任务类型创建工作人员任务模板，您可以使用 `RenderUiTemplate` 预览工作人员任务 UI。有关更多信息，请参阅 [预览工作人员任务模板](a2i-custom-templates.md#a2i-preview-your-custom-template)。

1. 如果您对模板感到满意，请选择 **Create (创建)**。

创建模板后，您可以在控制台中创建人工审核工作流时选择该模板。您的模板还会显示在 A **I 控制台的 Amazon** Agumented SageMaker 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。

**使用工作人员任务模板创建工作人员任务模板 (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`然后在`Content`下方输入您的 HTML 模板`UiTemplate`。在的 “**另请参阅**” 部分中查找支持 SDKs 此 API 操作的特定语言的文档。[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. 打开 Amazon A2I 控制台，网址为。[https://console.aws.amazon.com/a2i/](https://console.aws.amazon.com/a2i)

1. 在左侧导航窗格中的 Amazon Augmented 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 组件，您可以根据您要提出的问题定制这些组件。您可以使用这些 crowd 元素创建自定义工作人员模板，并将其与 Amazon Augmented 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 Augmented 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>

构建自定义模板时，您必须向其中添加变量，用于表示可能在不同任务之间或者在不同工作人员之间更改的数据片段。如果您以其中一个示例模板开始，您需要确保您知道它已经使用的变量。

例如，对于将 Amazon AI 人工审核循环与 Amazon Textract 文本审核任务集成的自定义模板，使用 `{{ task.input.selectedAiServiceResponse.blocks }}` 作为初始值输入数据。对于将 Amazon Augmented AI (Amazon A2I) 与 Amazon Rekognition，请使用 `{{ task.input.selectedAiServiceResponse.moderationLabels }}`。对于自定义任务类型，您需要确定任务类型的输入参数。使用指定了 `customInputValuesForStartHumanLoop` 的 `{{ task.input.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` – 为工作人员 UI 中的属性设置初始值。
+ `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` – 通过设置此属性，您可以在 UI 中的类别下创建一个按钮。当用户选择按钮时，将取消选择并禁用所有类别。如果工作人员再次选择该按钮，您将重新允许用户选择类别。如果工作人员在您按下按钮之后，通过选择**提交**按钮提交任务，则该任务将返回一个空数组。

对于 `<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 Augmented 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>

当您的内容要用作 HTML 时，`skip_autoescape` 很有用。例如，您可能在边界框的完整说明中有一些文本段落和一些图像。

**注意**  
请谨慎使用 `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 网址并将其编码为 HTTPS 网址（具有针对此资源的短期访问令牌）。这样，就可以向工作人员显示存储在 S3 存储桶中但原本无法公开访问的照片、音频或视频对象。

**Example 变量筛选器示例**  
Input  

```
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>

要预览自定义工作人员任务模板，请使用 A SageMaker I `RenderUiTemplate` 操作。您可以将该`RenderUiTemplate`操作与 AWS CLI 或您的首选 AWS SDK 一起使用。有关此 API 操作所支持语言 SDKs 的文档，请参阅的[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)部分[https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_RenderUiTemplate.html](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_RenderUiTemplate.html)。

**先决条件**

要预览您的工作任务模板，您使用的 AWS Identity and Access Management (IAM) 角色 Amazon 资源名称 (ARN) 或`RoleArn`，必须有权访问该模板使用的 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` 之后，请使用首选的 SDK 或 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)，这是一个呈现工作人员 UI 的 HTML 的 Liquid 模板。

**重要**  
要预览模板，您需要有权读取在用户界面上呈现的 Amazon S3 对象的 IAM 角色。有关可附加到 IAM 角色以授予这些权限的示例策略，请参阅[启用工作人员任务模板预览](a2i-permissions-security.md#permissions-for-worker-task-templates-augmented-ai)。

# 创建良好的工作人员说明
<a name="a2i-creating-good-instructions-guide"></a>

为人工审核作业创建良好的说明可提高工作人员完成任务的准确性。您可以在创建人工审核工作流时修改控制台中提供的默认说明，也可以使用控制台创建自定义工作人员模板并在此模板中包含您的说明。这些说明将显示在工作人员在其中完成标记任务的 UI 页面上。

## 创建良好的工作人员说明
<a name="a2i-good-instructions-console"></a>

Amazon Augmented 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)。