選取您的 Cookie 偏好設定

我們使用提供自身網站和服務所需的基本 Cookie 和類似工具。我們使用效能 Cookie 收集匿名統計資料,以便了解客戶如何使用我們的網站並進行改進。基本 Cookie 無法停用,但可以按一下「自訂」或「拒絕」以拒絕效能 Cookie。

如果您同意,AWS 與經核准的第三方也會使用 Cookie 提供實用的網站功能、記住您的偏好設定,並顯示相關內容,包括相關廣告。若要接受或拒絕所有非必要 Cookie,請按一下「接受」或「拒絕」。若要進行更詳細的選擇,請按一下「自訂」。

啟動自訂實體偵測任務 (API)

焦點模式
啟動自訂實體偵測任務 (API) - Amazon Comprehend

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

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

您可以使用 API 來啟動和監控非同步分析任務,以進行自訂實體辨識。

若要使用 StartEntitiesDetectionJob 操作啟動自訂實體偵測任務,您需要提供 EntityRecognizerArn,這是訓練模型的 Amazon Resource Name (ARN)。您可以在 CreateEntityRecognizer 操作的回應中找到此 ARN。

使用 偵測自訂實體 AWS Command Line Interface

針對 Unix、Linux 和 macOS 環境使用以下範例。用於 Windows 時,請以插入號 (^) 取代每一行結尾處的 Unix 接續字元斜線 (\)。若要偵測文件集中的自訂實體,請使用下列請求語法:

aws comprehend start-entities-detection-job \ --entity-recognizer-arn "arn:aws:comprehend:region:account number:entity-recognizer/test-6" \ --job-name infer-1 \ --data-access-role-arn "arn:aws:iam::account number:role/service-role/AmazonComprehendServiceRole-role" \ --language-code en \ --input-data-config "S3Uri=s3://Bucket Name/Bucket Path" \ --output-data-config "S3Uri=s3://Bucket Name/Bucket Path/" \ --region region

Amazon Comprehend 會回應 JobID和 ,JobStatus並傳回您在請求中指定的 S3 儲存貯體中任務的輸出。

使用 偵測自訂實體 AWS SDK for Java

如需使用 Java 的 Amazon Comprehend 範例,請參閱 Amazon Comprehend Java 範例

使用 偵測自訂實體 AWS SDK for Python (Boto3)

此範例會建立自訂實體識別器、訓練模型,然後使用 在實體識別器任務中執行 AWS SDK for Python (Boto3)。

執行個體化適用於 Python 的 SDK。

import boto3 import uuid comprehend = boto3.client("comprehend", region_name="region")

建立實體識別符:

response = comprehend.create_entity_recognizer( RecognizerName="Recognizer-Name-Goes-Here-{}".format(str(uuid.uuid4())), LanguageCode="en", DataAccessRoleArn="Role ARN", InputDataConfig={ "EntityTypes": [ { "Type": "ENTITY_TYPE" } ], "Documents": { "S3Uri": "s3://Bucket Name/Bucket Path/documents" }, "Annotations": { "S3Uri": "s3://Bucket Name/Bucket Path/annotations" } } ) recognizer_arn = response["EntityRecognizerArn"]

列出所有辨識器:

response = comprehend.list_entity_recognizers()

等待實體辨識器達到 TRAINED 狀態:

while True: response = comprehend.describe_entity_recognizer( EntityRecognizerArn=recognizer_arn ) status = response["EntityRecognizerProperties"]["Status"] if "IN_ERROR" == status: sys.exit(1) if "TRAINED" == status: break time.sleep(10)

啟動自訂實體偵測任務:

response = comprehend.start_entities_detection_job( EntityRecognizerArn=recognizer_arn, JobName="Detection-Job-Name-{}".format(str(uuid.uuid4())), LanguageCode="en", DataAccessRoleArn="Role ARN", InputDataConfig={ "InputFormat": "ONE_DOC_PER_LINE", "S3Uri": "s3://Bucket Name/Bucket Path/documents" }, OutputDataConfig={ "S3Uri": "s3://Bucket Name/Bucket Path/output" } )

覆寫 PDF 檔案的 API 動作

對於映像檔案和 PDF 檔案,您可以使用 中的 DocumentReaderConfig 參數覆寫預設擷取動作InputDataConfig

下列範例會定義名為 myInputDataConfig.json 的 JSON 檔案來設定InputDataConfig值。它會DocumentReadConfig設定為對所有 PDF 檔案使用 Amazon Textract DetectDocumentText API。

"InputDataConfig": { "S3Uri": s3://Bucket Name/Bucket Path", "InputFormat": "ONE_DOC_PER_FILE", "DocumentReaderConfig": { "DocumentReadAction": "TEXTRACT_DETECT_DOCUMENT_TEXT", "DocumentReadMode": "FORCE_DOCUMENT_READ_ACTION" } }

StartEntitiesDetectionJob操作中,指定 myInputDataConfig.json 檔案做為 InputDataConfig 參數:

--input-data-config file://myInputDataConfig.json

如需DocumentReaderConfig參數的詳細資訊,請參閱 設定文字擷取選項

隱私權網站條款Cookie 偏好設定
© 2025, Amazon Web Services, Inc.或其附屬公司。保留所有權利。