

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

# 自訂實體辨識 (API) 的即時分析
<a name="detecting-cer-real-time-api"></a>

您可以使用 Amazon Comprehend API 搭配自訂模型執行即時分析。首先，您會建立端點來執行即時分析。建立端點之後，您會執行即時分析。

如需佈建端點輸送量和相關成本的資訊，請參閱 [使用 Amazon Comprehend 端點](using-endpoints.md)。

**Topics**
+ [建立用於自訂實體偵測的端點](#detecting-cer-real-time-create-endpoint-api)
+ [執行即時自訂實體偵測](#detecting-cer-real-time-run)

## 建立用於自訂實體偵測的端點
<a name="detecting-cer-real-time-create-endpoint-api"></a>

如需與端點相關的成本資訊，請參閱 [使用 Amazon Comprehend 端點](using-endpoints.md)。

### 使用 建立端點 AWS CLI
<a name="detecting-cer-real-time-create-endpoint-examples"></a>

若要使用 建立端點 AWS CLI，請使用 `create-endpoint`命令：

```
$ aws comprehend create-endpoint \
> --desired-inference-units number of inference units \
> --endpoint-name endpoint name \
> --model-arn arn:aws:comprehend:region:account-id:model/example \
> --tags Key=Key,Value=Value
```

如果您的命令成功，Amazon Comprehend 會以端點 ARN 回應：

```
{
   "EndpointArn": "Arn"
}
```

如需此命令、其參數引數及其輸出的詳細資訊，請參閱《 AWS CLI 命令參考[https://docs.aws.amazon.com/cli/latest/reference/comprehend/create-endpoint.html](https://docs.aws.amazon.com/cli/latest/reference/comprehend/create-endpoint.html)》中的 。

## 執行即時自訂實體偵測
<a name="detecting-cer-real-time-run"></a>

為自訂實體辨識器模型建立端點之後，您可以使用端點來執行 [DetectEntities](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_DetectEntities.html) API 操作。您可以使用 `text`或 `bytes` 參數提供文字輸入。使用 `bytes` 參數輸入其他輸入類型。

對於影像檔案和 PDF 檔案，您可以使用 `DocumentReaderConfig` 參數覆寫預設的文字擷取動作。如需詳細資訊，請參閱[設定文字擷取選項](idp-set-textract-options.md)。

### 使用 偵測文字中的實體 AWS CLI
<a name="detecting-cer-real-time-run-cli1"></a>

若要偵測文字中的自訂實體，請使用 `text` 參數中的輸入文字執行 `detect-entities`命令。

**Example ：使用 CLI 偵測輸入文字中的實體**  

```
$ aws comprehend detect-entities \
> --endpoint-arn arn \
> --language-code en \
> --text  "Andy Jassy is the CEO of Amazon."
```
如果您的命令成功，Amazon Comprehend 會回應分析。對於 Amazon Comprehend 偵測到的每個實體，它提供實體類型、文字、位置和可信度分數。

### 使用 偵測半結構化文件中的實體 AWS CLI
<a name="detecting-cer-real-time-run-cli2"></a>

若要偵測 PDF、Word 或映像檔中的自訂實體，請在 `bytes` 參數中使用輸入檔案執行 `detect-entities`命令。

**Example ：使用 CLI 偵測映像檔案中的實體**  
此範例說明如何使用 base64 編碼影像位元組`fileb`的選項傳入影像檔案。如需詳細資訊，請參閱 AWS Command Line Interface 《 使用者指南》中的[二進位大型物件](https://docs.aws.amazon.com/cli/latest/userguide/cli-usage-parameters-types.html#parameter-type-blob)。  
此範例也會傳入名為 的 JSON 檔案，`config.json`以設定文字擷取選項。  

```
$ aws comprehend detect-entities \
> --endpoint-arn arn \
> --language-code en \
> --bytes fileb://image1.jpg   \
> --document-reader-config file://config.json
```
**config.json** 檔案包含下列內容。  

```
 {
    "DocumentReadMode": "FORCE_DOCUMENT_READ_ACTION",
    "DocumentReadAction": "TEXTRACT_DETECT_DOCUMENT_TEXT"    
 }
```

如需命令語法的詳細資訊，請參閱《*Amazon Comprehend API 參考*》中的 [DetectEntities](https://docs.aws.amazon.com/comprehend/latest/APIReference/API_DetectEntities.html)。