

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

# 名前付きエンティティ認識を使用してテキスト情報を抽出する
<a name="sms-named-entity-recg"></a>

非構造化テキストから情報を抽出し、事前定義されたカテゴリに分類するには、Amazon SageMaker Ground Truth の固有表現認識 (NER) のラベル付けタスクを使用します。従来、NER はテキストデータを調べて、*名前付きエンティティ*と呼ばれる名詞句を見つけ、それぞれを「person (人)」、「organization (組織)」、「brand (ブランド)」などのラベルで分類します。このタスクの対象をテキストのより長いスパンのラベル付けまで広げて、指定した定義済みのラベルでそれらのシーケンスを分類できます。Amazon SageMaker AI コンソールの Ground Truth セクションまたは [https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateLabelingJob.html](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateLabelingJob.html) オペレーションを使用して、名前付きエンティティ認識ラベル付けジョブを作成できます。

固有表現認識のラベル付けジョブを使用すると、ワーカーは大きなテキストブロック内の特定の単語やフレーズにラベルを適用します。ラベルを選択し、カーソルを使用してラベルの適用先のテキストの部分を強調表示することで、ラベルを適用します。Ground Truth の固有表現認識ツールは、単一のハイライトに対して、重複する注釈、コンテキスト内ラベル選択、マルチラベル選択をサポートします。また、ワーカーはキーボードを使用してラベルをすばやく選択できます。

**重要**  
入力マニフェストファイルを手動で作成する場合は、`"source"` を使用してラベル付けするテキストを指定します。詳細については、「[入力データ](sms-data-input.md)」を参照してください。

## 固有表現認識ラベル付けジョブの作成 (コンソール)
<a name="sms-creating-ner-console"></a>

SageMaker AI コンソールで固有表現認識ラベルリングジョブを作成する方法については、「[ラベル付けジョブの作成 (コンソール)](sms-create-labeling-job-console.md)」で手順を説明しています。ステップ 10 で、 **[Task category]** (タスクカテゴリ) ドロップダウンメニューから **[Text]** (テキスト) を選択し、**[Named entity recognition]** (固有表現認識) タスクタイプを指定します。

Ground Truth には、ラベル付けタスク用の次のようなワーカー UI が用意されています。コンソールでラベル付けジョブを作成するときは、ワーカーがジョブを実行できる手順と、ワーカーが選択できるラベルを指定します。

![\[SageMaker AI コンソールで名前付きエンティティ認識ラベル付けジョブを作成する画面の GIF。\]](http://docs.aws.amazon.com/ja_jp/sagemaker/latest/dg/images/sms/gifs/nertool.gif)


## 固有表現認識ラベル付けジョブ (API) の作成
<a name="sms-creating-ner-api"></a>

固有表現認識ラベル付けジョブを作成するには、SageMaker API オペレーション `CreateLabelingJob` を使用します。この API は、すべての AWS SDKsに対してこのオペレーションを定義します。このオペレーションでサポートされている言語固有の SDK のリストを確認するには、[https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateLabelingJob.html](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateLabelingJob.html) の「**以下の資料も参照してください**」セクションを確認してください。

リクエストを設定する際には、「[ラベル付けジョブを作成 (API)](sms-create-labeling-job-api.md)」の指示に従ったうえで、以下のことを実行してください。
+ このタスクタイプの注釈前 Lambda 関数は `PRE-NamedEntityRecognition` で終わります。リージョンの注釈前 Lambda ARN を検索するには、「[PreHumanTaskLambdaArn](https://docs.aws.amazon.com/sagemaker/latest/dg/API_HumanTaskConfig.html#SageMaker-Type-HumanTaskConfig-PreHumanTaskLambdaArn)」 を参照してください。
+ このタスクタイプの注釈統合 Lambda 関数は `ACS-NamedEntityRecognition` で終わります。リージョンの注釈統合 Lambda ARN を確認するには、「[AnnotationConsolidationLambdaArn](https://docs.aws.amazon.com/sagemaker/latest/dg/API_AnnotationConsolidationConfig.html#SageMaker-Type-AnnotationConsolidationConfig-AnnotationConsolidationLambdaArn)」を参照してください。
+ `[HumanTaskUiArn](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_UiConfig.html#sagemaker-Type-UiConfig-HumanTaskUiArn)` には以下の ARN が必要です。

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

  `aws-region` を、ラベル付けジョブを作成するために使用している AWS のリージョンに置き換えます。例えば、ラベル付けジョブを米国西部 (北カリフォルニア) で作成する場合は、`us-west-1` を使用します。
+ `instructions` パラメータを使用して、ラベルカテゴリの設定ファイルにワーカー向け指示書を指定します。`shortInstruction` と `fullInstruction` のフィールドには、文字列または HTML マークアップ言語を使用できます。詳細については、[ラベルカテゴリ設定ファイルにワーカー向け指示書を指定する](#worker-instructions-ner)を参照してください。

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

以下は、米国東部 (バージニア北部) リージョンでラベル付けジョブを作成する [AWS Python SDK (Boto3) リクエスト](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/sagemaker.html#SageMaker.Client.create_labeling_job)の例です。赤色のすべてのパラメータを仕様とリソースに置き換えます。

```
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'
        },
    ]
)
```

### ラベルカテゴリ設定ファイルにワーカー向け指示書を指定する
<a name="worker-instructions-ner"></a>

`CreateLabelingJob` の `LabelCategoryConfigS3Uri` パラメータで特定するラベルカテゴリ設定ファイルで、ワーカー向け指示書を指定する必要があります。これらの指示を使用して、ワーカーが実行するタスクの詳細を提示し、ツールを効率的に使用できるようにします。

`instructions` パラメータの `shortInstruction` と `fullInstruction` をそれぞれ使用して、短い指示書と長い指示書を指定します。これらの指示書タイプの詳細については、「[指示書ページの作成](sms-creating-instruction-pages.md)」を参照してください。

以下は、固有表現認識ラベル付けジョブに使用できる指示を含むラベルカテゴリ設定ファイルの例です。

```
{
  "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>"
  }
}
```

## 固有表現認識出力データ
<a name="sms-ner-output-data"></a>

固有表現認識ラベル付けジョブを作成すると、出力データは、APIを使用するときに `S3OutputPath` パラメータで指定された Amazon S3 バケット、またはコンソールの **[Job overview]** (ジョブの概要)セクションの **[Output dataset location]** (出力データセットの場所) フィールドに配置されます。

Ground Truth によって生成される出力マニフェストファイルと、Ground Truth が出力データを保存するために使用するファイル構造の詳細については、「[ラベル付けジョブの出力データ](sms-data-output.md)」を参照してください。