本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
主題建模的非同步分析
若要判斷文件集中的主題,請使用 StartTopicsDetectionJob 啟動非同步任務。您可以監控以英文或西班牙文撰寫之文件中的主題。
開始之前
開始之前,請確定您已:
-
輸入和輸出儲存貯體 - 識別您要用於輸入和輸出的 Amazon S3 儲存貯體。儲存貯體必須與您呼叫的 API 位於相同的區域。
-
IAM 服務角色 - 您必須具有 IAM 服務角色,具有存取輸入和輸出儲存貯體的許可。如需詳細資訊,請參閱非同步操作所需的角色型許可。
使用 AWS Command Line Interface
下列範例示範搭配 使用 StartTopicsDetectionJob操作 AWS CLI
此範例格式適用於 Unix、Linux 和 macOS。用於 Windows 時,請以插入號 (^) 取代每一行結尾處的 Unix 接續字元斜線 (\)。
aws comprehend start-topics-detection-job \ --number-of-topicstopics to return\ --job-name "job name" \ --regionregion\ --cli-input-json file://path to JSON input file
針對 參數,cli-input-json您提供包含請求資料的 JSON 檔案路徑,如下列範例所示。
{ "InputDataConfig": { "S3Uri": "s3://input bucket/input path", "InputFormat": "ONE_DOC_PER_FILE" }, "OutputDataConfig": { "S3Uri": "s3://output bucket/output path" }, "DataAccessRoleArn": "arn:aws:iam::account ID:role/data access role" }
如果啟動主題偵測任務的請求成功,您將收到下列回應:
{
"JobStatus": "SUBMITTED",
"JobId": "job ID"
}
使用 ListTopicsDetectionJobs 操作來查看您已提交的主題偵測任務清單。此清單包含您使用的輸入和輸出位置,以及每個偵測任務狀態的相關資訊。此範例格式適用於 Unix、Linux 和 macOS。用於 Windows 時,請以插入號 (^) 取代每一行結尾處的 Unix 接續字元斜線 (\)。
aws comprehend list-topics-detection-jobs \--region
您會得到類似以下內容的 JSON 來回應:
{
"TopicsDetectionJobPropertiesList": [
{
"InputDataConfig": {
"S3Uri": "s3://input bucket/input path",
"InputFormat": "ONE_DOC_PER_LINE"
},
"NumberOfTopics": topics to return,
"JobId": "job ID",
"JobStatus": "COMPLETED",
"JobName": "job name",
"SubmitTime": timestamp,
"OutputDataConfig": {
"S3Uri": "s3://output bucket/output path"
},
"EndTime": timestamp
},
{
"InputDataConfig": {
"S3Uri": "s3://input bucket/input path",
"InputFormat": "ONE_DOC_PER_LINE"
},
"NumberOfTopics": topics to return,
"JobId": "job ID",
"JobStatus": "RUNNING",
"JobName": "job name",
"SubmitTime": timestamp,
"OutputDataConfig": {
"S3Uri": "s3://output bucket/output path"
}
}
]
}
您可以使用 DescribeTopicsDetectionJob 操作來取得現有任務的狀態。此範例格式適用於 Unix、Linux 和 macOS。用於 Windows 時,請以插入號 (^) 取代每一行結尾處的 Unix 接續字元斜線 (\)。
aws comprehend describe-topics-detection-job --job-idjob ID
您將會收到下列 JSON 的回應:
{
"TopicsDetectionJobProperties": {
"InputDataConfig": {
"S3Uri": "s3://input bucket/input path",
"InputFormat": "ONE_DOC_PER_LINE"
},
"NumberOfTopics": topics to return,
"JobId": "job ID",
"JobStatus": "COMPLETED",
"JobName": "job name",
"SubmitTime": timestamp,
"OutputDataConfig": {
"S3Uri": "s3://output bucket/ouput path"
},
"EndTime": timestamp
}
}
使用適用於 Python 的 SDK 或 適用於 .NET 的 SDK
如需如何啟動主題建模任務的 SDK 範例,請參閱 StartTopicsDetectionJob 搭配 AWS SDK 或 CLI 使用。