

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

# テキスト分類によってテキストを分類する (マルチラベル)
<a name="sms-text-classification-multilabel"></a>

記事とテキストを複数の定義済みカテゴリに分類するには、マルチラベルのテキスト分類タスクタイプを使用します。例えば、このタスクの種類を使用して、テキストで伝えられる複数の感情を識別できます。以下のセクションでは、コンソールと API からマルチラベルテキスト分類タスクを作成する方法について説明します。

マルチラベルのテキスト分類タスクで作業する場合、ワーカーは適用可能なすべてのラベルを選択するべきですが、少なくとも 1 つは必ず選択する必要があります。このタスクタイプを使用してジョブを作成する場合、最大 50 のラベルカテゴリを指定できます。

Amazon SageMaker Ground Truth には、どのラベルも適用されない場合のための「none」カテゴリがありません。ワーカーにこのオプションを提供するには、マルチラベルのテキスト分類ジョブを作成する際に「none」または「other」に似たラベルを含めます。

ワーカーがドキュメントまたはテキスト選択ごとに 1 つのラベルを選択するように制限するには、[テキスト分類によってテキストを分類する (単一ラベル)](sms-text-classification.md) タスクタイプを使用します。

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

## マルチラベルのテキスト分類のラベル付けジョブを作成する (コンソール)
<a name="sms-creating-multilabel-text-classification-console"></a>

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

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

![Amazon SageMaker AI コンソールでマルチラベルのテキスト分類ラベル付けジョブを作成する方法を示す GIF。](http://docs.aws.amazon.com/ja_jp/sagemaker/latest/dg/images/sms/gifs/multi-label-text.gif)


## マルチラベルのテキスト分類ラベル付けジョブ (API) を作成する
<a name="sms-creating-multilabel-text-classification-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-TextMultiClassMultiLabel` で終わります。リージョンの注釈前 Lambda ARN を検索するには、「[PreHumanTaskLambdaArn](https://docs.aws.amazon.com/sagemaker/latest/dg/API_HumanTaskConfig.html#SageMaker-Type-HumanTaskConfig-PreHumanTaskLambdaArn)」 を参照してください。
+ このタスクタイプの注釈統合 Lambda 関数は `ACS-TextMultiClassMultiLabel` で終わります。リージョンの注釈統合 Lambda ARN を確認するには、「[AnnotationConsolidationLambdaArn](https://docs.aws.amazon.com/sagemaker/latest/dg/API_AnnotationConsolidationConfig.html#SageMaker-Type-AnnotationConsolidationConfig-AnnotationConsolidationLambdaArn)」を参照してください。

以下は、米国東部 (バージニア北部) リージョンでラベル付けジョブを作成する [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-multi-label-text-classification-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': {
            'UiTemplateS3Uri': {{'s3://bucket/path/custom-worker-task-template.html'}}
        },
        'PreHumanTaskLambdaArn': 'arn:aws:lambda::function:PRE-TextMultiClassMultiLabel,
        'TaskKeywords': [
            {{'Text Classification'}},
        ],
        'TaskTitle': {{'Multi-label text classification task'}},
        'TaskDescription': {{'Select all labels that apply to the text shown'}},
        'NumberOfHumanWorkersPerDataObject': {{123}},
        'TaskTimeLimitInSeconds': {{123}},
        'TaskAvailabilityLifetimeInSeconds': {{123}},
        'MaxConcurrentTaskCount': {{123}},
        'AnnotationConsolidationConfig': {
            'AnnotationConsolidationLambdaArn': 'arn:aws:lambda:{{us-east-1:432418664414}}:function:ACS-TextMultiClassMultiLabel'
        },
    Tags=[
        {
            'Key': {{'string'}},
            'Value': {{'string'
}}        },
    ]
)
```

### マルチラベルのテキスト分類用のテンプレートを作成する
<a name="custom-template-multi-label-text-classification"></a>

API を使用してラベル付けジョブを作成する場合は、`UiTemplateS3Uri` でワーカータスクテンプレートを指定する必要があります。次のテンプレートをコピーして変更します。[https://docs.aws.amazon.com/sagemaker/latest/dg/sms-creating-instruction-pages.html#sms-creating-quick-instructions](https://docs.aws.amazon.com/sagemaker/latest/dg/sms-creating-instruction-pages.html#sms-creating-quick-instructions)、[https://docs.aws.amazon.com/sagemaker/latest/dg/sms-creating-instruction-pages.html#sms-creating-full-instructions](https://docs.aws.amazon.com/sagemaker/latest/dg/sms-creating-instruction-pages.html#sms-creating-full-instructions)、`header` のみ変更します。

このテンプレートを S3 にアップロードし、このファイルの S3 URI を `UiTemplateS3Uri` で指定します。

```
<script src="https://assets.crowd.aws/crowd-html-elements.js"></script>
<crowd-form>
  <crowd-classifier-multi-select
    name="crowd-classifier-multi-select"
    categories="{{ task.input.labels | to_json | escape }}"
    header="Please identify all classes in the below text"
  >
    <classification-target style="white-space: pre-wrap">
      {{ task.input.taskObject }}
    </classification-target>
    <full-instructions header="Classifier instructions">
      <ol><li><strong>Read</strong> the text carefully.</li>
      <li><strong>Read</strong> the examples to understand more about the options.</li>
      <li><strong>Choose</strong> the appropriate labels that best suit the text.</li></ol>
    </full-instructions>
    <short-instructions>
      <p>Enter description of the labels that workers have to choose from</p>
      <p><br></p>
      <p><br></p><p>Add examples to help workers understand the label</p>
      <p><br></p><p><br></p><p><br></p><p><br></p><p><br></p>
    </short-instructions>
  </crowd-classifier-multi-select>
  </crowd-form>
```

カスタムテンプレートを作成する方法については、「[カスタムラベル付けワークフロー](sms-custom-templates.md)」を参照してください。

## マルチラベルのテキスト分類出力データ
<a name="sms-text-classification-multi-select-output-data"></a>

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

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

マルチラベルのテキスト分類ラベル付けジョブの出力マニフェストファイルの例については、「[マルチラベル分類ジョブの出力](sms-data-output.md#sms-output-multi-label-classification)」を参照してください。