具名實體辨識 - Amazon SageMaker

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

具名實體辨識

若要從非結構化文字擷取資訊並將其分類為預先定義的類別,請使用 Amazon SageMaker Ground Truth 命名實體辨識 (NER) 標籤任務。傳統上,NER包括篩選文字資料以找出名詞詞語 (稱為具名實體),並使用標籤 (例如「人員」、「組織」或「品牌」) 對每個詞組進行分類。您可以將此任務擴大為標籤較長的文字範圍,並使用您指定的預先定義標籤來分類那些文字序列。

在獲派具名實體辨識標籤工作時,工作者會將您的標籤套用到較大文字區塊內的特定文字或片語。他們會選擇標籤,然後使用游標反白套用標籤的文字部分,以套用該標籤。Ground Truth 具名實體辨識工具支援重疊註釋、內容標籤選取,以及單一強調顯示多標籤選取。此外,工作者可以使用鍵盤快速選取標籤。

您可以使用 Amazon SageMaker 主控台的「Ground Truth」區段或作業建立具名實體辨識標籤任CreateLabelingJob務。

重要

如果您手動建立輸入資訊清單檔案,請使用 "source" 來識別您要標籤的文字。如需詳細資訊,請參閱輸入資料

建立具名實體辨識標籤工作 (主控台)

您可以按照說明建立標記任務 (主控台)了解如何在 SageMaker 主控台中建立具名實體辨識標籤工作。在步驟 10 中,從任務類別下拉式清單中選擇文字,然後選擇具名實體辨識作為任務類型。

Ground Truth 提供類似下列標籤任務的工作者使用者介面。使用主控台建立標籤工作時,您可以指定指示以協助工作者完成工作,以及工作者可以選擇的標籤。

Gif 顯示瞭如何在 SageMaker 控制台中創建命名實體識別標籤工作。

建立具名實體辨識標籤 Job (API)

若要使用作業建立具名實體辨識標籤工 SageMaker API作CreateLabelingJob。這API定義了所有的這個操作 AWS SDKs。若要查看此作業SDKs支援的特定語言清單,請檢閱的〈請參閱〉一節。CreateLabelingJob

設定請求時,請遵循建立標記任務 (API)上的指示並執行下列動作:

  • 此任務類型的註釋前 Lambda 函式會以 PRE-NamedEntityRecognition 結尾。若要尋找您區域的預先註ARN解 Lambda,請參閱PreHumanTaskLambdaArn

  • 此任務類型的註釋合併 Lambda 函式會以 ACS-NamedEntityRecognition 結尾。若要尋找ARN適用於您區域的註釋合併 Lambda,請參閱。AnnotationConsolidationLambdaArn

  • 您必須提供以下ARN資料HumanTaskUiArn

    arn:aws:sagemaker:aws-region:394669845002:human-task-ui/NamedEntityRecognition

    以您用來建立標籤工作的AWS區域取aws-region代。例如,在美國西部 (北加州) 中建立標籤工作時使用 us-west-1

  • 使用 instructions 參數在標籤類別組態檔案中提供工作者指示。您可以在shortInstructionfullInstruction欄位中使用字串或HTML標記語言。如需詳細資訊,請參閱在標籤類別組態檔案中提供工作者指示

    "instructions": {"shortInstruction":"<h1>Add header</h1><p>Add Instructions</p>", "fullInstruction":"<p>Add additional instructions.</p>"}

以下是在美國東部 SDK(維吉尼亞北部) 區域建立標籤工作的AWS Python (Boto3) 請求範例。所有以紅色標示的參數都應該用您的規格和資源加以取代。

response = client.create_labeling_job( LabelingJobName='example-ner-labeling-job', LabelAttributeName='label', InputConfig={ 'DataSource': { 'S3DataSource': { 'ManifestS3Uri': 's3://bucket/path/manifest-with-input-data.json' } }, 'DataAttributes': { 'ContentClassifiers': [ 'FreeOfPersonallyIdentifiableInformation'|'FreeOfAdultContent', ] } }, OutputConfig={ 'S3OutputPath': 's3://bucket/path/file-to-store-output-data', 'KmsKeyId': 'string' }, RoleArn='arn:aws:iam::*:role/*', LabelCategoryConfigS3Uri='s3://bucket/path/label-categories.json', StoppingConditions={ 'MaxHumanLabeledObjectCount': 123, 'MaxPercentageOfInputDatasetLabeled': 123 }, HumanTaskConfig={ 'WorkteamArn': 'arn:aws:sagemaker:region:*:workteam/private-crowd/*', 'UiConfig': { 'HumanTaskUiArn': 'arn:aws:sagemaker:us-east-1:394669845002:human-task-ui/NamedEntityRecognition' }, 'PreHumanTaskLambdaArn': 'arn:aws:lambda:us-east-1:432418664414:function:PRE-NamedEntityRecognition', 'TaskKeywords': [ 'Named entity Recognition', ], 'TaskTitle': 'Named entity Recognition task', 'TaskDescription': 'Apply the labels provided to specific words or phrases within the larger text block.', 'NumberOfHumanWorkersPerDataObject': 1, 'TaskTimeLimitInSeconds': 28800, 'TaskAvailabilityLifetimeInSeconds': 864000, 'MaxConcurrentTaskCount': 1000, 'AnnotationConsolidationConfig': { 'AnnotationConsolidationLambdaArn': 'arn:aws:lambda:us-east-1:432418664414:function:ACS-NamedEntityRecognition' }, Tags=[ { 'Key': 'string', 'Value': 'string' }, ] )

在標籤類別組態檔案中提供工作者指示

您必須在使用 CreateLabelingJob 中的 LabelCategoryConfigS3Uri 參數識別的標籤類別組態檔案中提供工作者指示。您可以使用這些指示來提供您希望工作者執行的任務詳細資訊,並協助他們有效率地使用工具。

您可以分別使用 instructions 參數中的 shortInstructionfullInstruction 提供簡短指示和詳細指示。若要深入了解這些指示類型,請參閱建立說明頁面

以下是標籤類別組態檔案的範例,其中包含可用於具名實體辨識標籤工作的指示。

{ "document-version": "2018-11-28", "labels": [ { "label": "label1", "shortDisplayName": "L1" }, { "label": "label2", "shortDisplayName": "L2" }, { "label": "label3", "shortDisplayName": "L3" }, { "label": "label4", "shortDisplayName": "L4" }, { "label": "label5", "shortDisplayName": "L5" } ], "instructions": { "shortInstruction": "<p>Enter description of the labels that workers have to choose from</p><br><p>Add examples to help workers understand the label</p>", "fullInstruction": "<ol> <li><strong>Read</strong> the text carefully.</li> <li><strong>Highlight</strong> words, phrases, or sections of the text.</li> <li><strong>Choose</strong> the label that best matches what you have highlighted.</li> <li>To <strong>change</strong> a label, choose highlighted text and select a new label.</li> <li>To <strong>remove</strong> a label from highlighted text, choose the X next to the abbreviated label name on the highlighted text.</li> <li>You can select all of a previously highlighted text, but not a portion of it.</li> </ol>" } }

具名實體辨識輸出資料

建立具名實體辨識標籤 Job 務後,您的輸出資料將位於使用主控台「任務概觀」區段的「輸出資料集位置」欄位中API或時,您的輸出資料將位S3OutputPath參數中指定的 Amazon S3 儲存貯體中。

若要進一步了解 Ground Truth 產生的輸出資訊清單檔案,以及 Ground Truth 用來儲存輸出資料的檔案結構,請參閱輸出資料