

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

# Amazon 增強版 AI 中，適用於 JSON 結構描述的人工循環啟動條件
<a name="a2i-human-fallback-conditions-json-schema"></a>

`HumanLoopActivationConditions` 是 [https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateFlowDefinition.html](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateFlowDefinition.html) API 的輸入參數。此參數是 JSON 格式化字串。JSON 模型可以根據建立人工循環所需的條件建模，以根據整合式 AI 服務 API (例如 `Rekognition.DetectModerationLabels` 或 `Textract.AnalyzeDocument`) 的回應來評估這些條件。這種回應被稱為*推論*。例如，Amazon Rekognition 會傳送審核標籤推論，其中具有相關可信度分數。在此範例中，推論是模型對影像適當標籤的最佳估計值。對於 Amazon Textract，推論是根據文字區塊 (*鍵值對*) 之間的關聯 (例如在表單中 `Name:` 與 `Sue` 之間的關聯)，以及文字區塊內或*字詞區塊*的內容 (例如 '名稱')。

以下是 JSON 的結構描述。在最上層，`HumanLoopActivationConditions` 具有 `Conditions` 這個 JSON 陣列。此陣列的每個成員都是獨立條件，如果評估為 `true`，會使 Amazon A2I 建立一個人工循環。每個這種獨立條件可以是簡單條件或複雜條件。簡單條件具有以下屬性：
+ `ConditionType`：此屬性識別條件的類型。與 Amazon A2I 整合的每個 AWS AI 服務 API，都定義其自己一組允許的 `ConditionTypes`。
  + Rekognition `DetectModerationLabels` - 此 API 支援 `ModerationLabelConfidenceCheck` 以及 `Sampling` `ConditionType`值。
  + Textract `AnalyzeDocument` - 此 API 支援`ImportantFormKeyConfidenceCheck`、`MissingImportantFormKey`、和 `Sampling` `ConditionType` 值。
+ `ConditionParameters` – 這是將條件參數化的 JSON 物件。此物件允許的屬性集取決於 `ConditionType` 的值。每個 `ConditionType` 定義自己的一組 `ConditionParameters`。

`Conditions` 陣列的成員可以將複雜條件建模。作法是使用 `And` 和 `Or` 邏輯運算子，以邏輯方式將簡單條件連接起來，並使基本簡單條件巢狀化。最多支援兩層巢狀。

```
{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "definitions": {
        "Condition": {
            "type": "object",
            "properties": {
                "ConditionType": {
                    "type": "string"
                },
                "ConditionParameters": {
                    "type": "object"
                }
            },
            "required": [
                "ConditionType"
            ]
        },
        "OrConditionArray": {
            "type": "object",
            "properties": {
                "Or": {
                    "type": "array",
                    "minItems": 2,
                    "items": {
                        "$ref": "#/definitions/ComplexCondition"
                    }
                }
            }
        },
        "AndConditionArray": {
            "type": "object",
            "properties": {
                "And": {
                    "type": "array",
                    "minItems": 2,
                    "items": {
                        "$ref": "#/definitions/ComplexCondition"
                    }
                }
            }
        },
        "ComplexCondition": {
            "anyOf": [
                {
                    "$ref": "#/definitions/Condition"
                },
                {
                    "$ref": "#/definitions/OrConditionArray"
                },
                {
                    "$ref": "#/definitions/AndConditionArray"
                }
            ]
        }
    },
    "type": "object",
    "properties": {
        "Conditions": {
            "type": "array",
            "items": {
                "$ref": "#/definitions/ComplexCondition"
            }
        }
    }
}
```

**注意**  
與自訂任務類型整合的人工審核工作流程，沒有人工循環啟動條件。自訂任務類型的 `HumanLoopActivationConditions` 參數已停用。

**Topics**
+ [使用人工循環啟動條件 JSON 結構描述與 Amazon Textract](a2i-json-humantaskactivationconditions-textract-example.md)
+ [使用人工循環啟動條件 JSON 結構描述與 Amazon Rekognition](a2i-json-humantaskactivationconditions-rekognition-example.md)