

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

# テキスト分類 - TensorFlow
<a name="text-classification-tensorflow"></a>

Amazon SageMaker AI テキスト分類 - TensorFlow アルゴリズムは、[TensorFlow ハブ](https://tfhub.dev/)の多くの事前トレーニング済みモデルによる転移学習をサポートする教師あり学習アルゴリズムです。大量のテキストデータが使用可能でない場合でも、転移学習を使用して、使用可能な事前トレーニング済みモデルのいずれかを独自のデータセットで微調整できます。テキスト分類アルゴリズムは、テキスト文字列を入力として受け取り、各クラスラベルの確率を出力します。トレーニングデータセットは CSV 形式である必要があります。このページには、テキスト分類 - TensorFlow の Amazon EC2 インスタンスに関する推奨事項とサンプルノートブックについての情報が含まれています。

**Topics**
+ [SageMaker AI テキスト分類の使用方法 - TensorFlow アルゴリズム](text-classification-tensorflow-how-to-use.md)
+ [テキスト分類 - TensorFlow アルゴリズムの入出力インターフェイス](text-classification-tensorflow-inputoutput.md)
+ [テキスト分類 - TensorFlow アルゴリズムの Amazon EC2 インスタンスの推奨事項](#text-classification-tensorflow-instances)
+ [テキスト分類 - TensorFlow サンプルノートブック](#text-classification-tensorflow-sample-notebooks)
+ [テキスト分類 - TensorFlow の仕組み](text-classification-tensorflow-HowItWorks.md)
+ [TensorFlow ハブモデル](text-classification-tensorflow-Models.md)
+ [テキスト分類 - TensorFlow ハイパーパラメータ](text-classification-tensorflow-Hyperparameter.md)
+ [テキスト分類 - TensorFlow モデルの調整](text-classification-tensorflow-tuning.md)

# SageMaker AI テキスト分類の使用方法 - TensorFlow アルゴリズム
<a name="text-classification-tensorflow-how-to-use"></a>

テキスト分類 - TensorFlow は Amazon SageMaker AI の組み込みアルゴリズムとして使用できます。次のセクションでは、SageMaker AI Python SDK でテキスト分類 - TensorFlow を使用する方法について説明します。Amazon SageMaker Studio Classic UI からテキスト分類 - TensorFlow を使用する方法については、「[SageMaker JumpStart の事前トレーニング済みモデル](studio-jumpstart.md)」を参照してください。

テキスト分類 - TensorFlow アルゴリズムは、互換性のある事前トレーニング済み TensorFlow モデルのいずれかを使用した転移学習をサポートしています。使用可能なすべての事前トレーニング済みモデルのリストについては、「[TensorFlow ハブモデル](text-classification-tensorflow-Models.md)」を参照してください。すべての事前トレーニング済みモデルには一意の `model_id` があります。次の例では、BERT Base Uncased (`model_id`: `tensorflow-tc-bert-en-uncased-L-12-H-768-A-12-2`) を使用してカスタムデータセットを微調整しています。事前トレーニング済みモデルはすべて TensorFlow ハブ から事前にダウンロードされ、Amazon S3 バケットに保存されているため、トレーニングジョブはネットワーク分離状態で実行できます。事前に生成されたこれらのモデルトレーニングアーティファクトを使用して SageMaker AI 推定器を構築します。

まず、Docker イメージ URI、トレーニングスクリプト URI、および事前トレーニング済みのモデル URI を取得します。次に、必要に応じてハイパーパラメータを変更します。使用可能なすべてのハイパーパラメータとそのデフォルト値の Python ディクショナリは、`hyperparameters.retrieve_default` で確認できます。詳細については、「[テキスト分類 - TensorFlow ハイパーパラメータ](text-classification-tensorflow-Hyperparameter.md)」を参照してください。これらの値を使用して SageMaker AI 推定器を構築します。

**注記**  
デフォルトのハイパーパラメータ値はモデルによって異なります。例えば、モデルが大きいほど、既定のバッチサイズは小さくなります。

この例では、肯定的および否定的な映画レビューを含む [https://www.tensorflow.org/datasets/catalog/glue#gluesst2](https://www.tensorflow.org/datasets/catalog/glue#gluesst2) データセットを使用しています。データセットを事前にダウンロードして、Amazon S3 で使用できるようにしてあります。モデルを微調整するには、トレーニングデータセットの Amazon S3 の場所を使用して `.fit` を呼び出します。ノートブックで使用する S3 バケットは、それにアクセスするノートブックインスタンスと同じ AWS リージョンに存在する必要があります。

```
from sagemaker import image_uris, model_uris, script_uris, hyperparameters
from sagemaker.estimator import Estimator

model_id, model_version = "tensorflow-tc-bert-en-uncased-L-12-H-768-A-12-2", "*"
training_instance_type = "ml.p3.2xlarge"

# Retrieve the Docker image
train_image_uri = image_uris.retrieve(model_id=model_id,model_version=model_version,image_scope="training",instance_type=training_instance_type,region=None,framework=None)

# Retrieve the training script
train_source_uri = script_uris.retrieve(model_id=model_id, model_version=model_version, script_scope="training")

# Retrieve the pretrained model tarball for transfer learning
train_model_uri = model_uris.retrieve(model_id=model_id, model_version=model_version, model_scope="training")

# Retrieve the default hyperparameters for fine-tuning the model
hyperparameters = hyperparameters.retrieve_default(model_id=model_id, model_version=model_version)

# [Optional] Override default hyperparameters with custom values
hyperparameters["epochs"] = "5"

# Sample training data is available in this bucket
training_data_bucket = f"jumpstart-cache-prod-{aws_region}"
training_data_prefix = "training-datasets/SST2/"

training_dataset_s3_path = f"s3://{training_data_bucket}/{training_data_prefix}"

output_bucket = sess.default_bucket()
output_prefix = "jumpstart-example-tc-training"
s3_output_location = f"s3://{output_bucket}/{output_prefix}/output"

# Create an Estimator instance
tf_tc_estimator = Estimator(
    role=aws_role,
    image_uri=train_image_uri,
    source_dir=train_source_uri,
    model_uri=train_model_uri,
    entry_point="transfer_learning.py",
    instance_count=1,
    instance_type=training_instance_type,
    max_run=360000,
    hyperparameters=hyperparameters,
    output_path=s3_output_location,
)

# Launch a training job
tf_tc_estimator.fit({"training": training_dataset_s3_path}, logs=True)
```

カスタムデータセットの転移学習に SageMaker テキスト分類 - TensorFlow アルゴリズムを使用する方法の詳細については、「[Introduction to JumpStart - Text Classification](https://github.com/aws/amazon-sagemaker-examples/blob/main/introduction_to_amazon_algorithms/jumpstart_text_classification/Amazon_JumpStart_Text_Classification.ipynb)」ノートブックを参照してください。

# テキスト分類 - TensorFlow アルゴリズムの入出力インターフェイス
<a name="text-classification-tensorflow-inputoutput"></a>

TensorFlow ハブモデルに一覧表示されている事前トレーニング済みモデルはそれぞれ、任意の数のクラスを持つテキスト文で構成されるデータセットに合わせて微調整できます。事前トレーニング済みモデルは分類レイヤーをテキスト埋め込みモデルにアタッチし、レイヤーパラメータをランダム値に初期化します。分類レイヤーの出力次元は、入力データで検出されたクラスの数に基づいて決定されます。

テキスト分類 - TensorFlow モデルに入力するトレーニングデータをフォーマットする方法にご注意ください。
+ **トレーニングデータの入力形式:** `data.csv` ファイルを含むディレクトリ。最初の列の各行は、0 からクラス数の間の整数のクラスラベルを含んでいる必要があります。2 列目の各行は、対応するテキストデータを含んでいる必要があります。

入力 CSV ファイルの例を次に示します。ファイルにはヘッダーを含めないことにご注意ください。ファイルは、次のようなパスの Amazon S3 バケットでホストされている必要があります。`s3://bucket_name/input_directory/`。末尾の `/` は必須であることにご注意ください。

```
|   |  |
|---|---|
|0 |hide new secretions from the parental units|
|0 |contains no wit , only labored gags|
|1 |that loves its characters and communicates something rather beautiful about human nature|
|...|...|
```

## 段階的トレーニング
<a name="text-classification-tensorflow-incremental-training"></a>

以前に SageMaker AI でトレーニングしたモデルのアーティファクトを使用して、新しいモデルのトレーニングをシードできます。段階的トレーニングでは、同じモデルまたは類似のデータを使用して新しいモデルをトレーニングする際のトレーニング時間が短縮されます。

**注記**  
SageMaker AI テキスト分類 - TensorFlow モデルは、SageMaker AI でトレーニングされた別のテキスト分類 - TensorFlow モデルを使用してのみシードできます。

一連のクラスが同じままである限り、任意のデータセットを段階的トレーニングに使用できます。段階的トレーニングのステップは微調整のステップと同様ですが、事前トレーニング済みモデルから始める代わりに、既存の微調整済みモデルから始めます。

SageMaker AI テキスト分類 - TensorFlow アルゴリズムを使用した段階的トレーニングの使用の詳細については、「[Introduction to JumpStart - Text Classification](https://github.com/aws/amazon-sagemaker-examples/blob/main/introduction_to_amazon_algorithms/jumpstart_text_classification/Amazon_JumpStart_Text_Classification.ipynb)」サンプルノートブックを参照してください。

## テキスト分類 - TensorFlow アルゴリズムによる推論
<a name="text-classification-tensorflow-inference"></a>

TensorFlow テキスト分類トレーニングの結果として生じる微調整済みモデルを推論のためにホストすることができます。推論用の未加工テキストの形式はすべて、コンテンツタイプ `application/x-text` でなければなりません。

推論を実行すると、確率値、すべてのクラスのクラスラベル、および確率が最も高いクラスインデックスに対応する予測ラベルが JSON 形式にエンコードされて得られます。テキスト分類 - TensorFlow モデルは、リクエストごとに単一の文字列を処理し、1 行だけを出力します。JSON 形式のレスポンスの例を次に示します。

```
accept: application/json;verbose

{"probabilities": [prob_0, prob_1, prob_2, ...],
"labels": [label_0, label_1, label_2, ...],
"predicted_label": predicted_label}
```

`application/json` に `accept` が設定されている場合、モデルは確率のみを出力します。

## テキスト分類 - TensorFlow アルゴリズムの Amazon EC2 インスタンスの推奨事項
<a name="text-classification-tensorflow-instances"></a>

テキスト分類 - TensorFlow アルゴリズムは、次を含むすべてのトレーニング用 CPU および GPU インスタンスをサポートします。
+ `ml.p2.xlarge`
+ `ml.p2.16xlarge`
+ `ml.p3.2xlarge`
+ `ml.p3.16xlarge`
+ `ml.g4dn.xlarge`
+ `ml.g4dn.16.xlarge`
+ `ml.g5.xlarge`
+ `ml.g5.48xlarge`

大きなバッチサイズのトレーニングにはメモリが多い GPU インスタンスをお勧めします。CPU (M5 など) インスタンスと GPU (P2、P3、G4Dn、または G5) インスタンスの両方を推論に使用できます。 AWS リージョン間の SageMaker トレーニングインスタンスと推論インスタンスの包括的なリストについては、[Amazon SageMakerの料金](https://aws.amazon.com/sagemaker/pricing/)」を参照してください。

## テキスト分類 - TensorFlow サンプルノートブック
<a name="text-classification-tensorflow-sample-notebooks"></a>

カスタムデータセットの転移学習に SageMaker AI テキスト分類 - TensorFlow アルゴリズムを使用する方法の詳細については、「[Introduction to JumpStart - Text Classification](https://github.com/aws/amazon-sagemaker-examples/blob/main/introduction_to_amazon_algorithms/jumpstart_text_classification/Amazon_JumpStart_Text_Classification.ipynb)」ノートブックを参照してください。

SageMaker AI でサンプルを実行するために使用できる Jupyter ノートブックインスタンスを作成してアクセスする方法の詳細については、「[Amazon SageMaker ノートブックインスタンス](nbi.md)」を参照してください。ノートブックインスタンスを作成して開いた後、**[SageMaker AI サンプル]** タブを選択して、すべての SageMaker AI サンプルのリストを表示します。ノートブックを開くには、その [**Use (使用)**] タブを選択し、[**Create copy (コピーを作成)**] を選択します。

# テキスト分類 - TensorFlow の仕組み
<a name="text-classification-tensorflow-HowItWorks"></a>

テキスト分類 - TensorFlow アルゴリズムは、テキストを受け取り、1 つの出力クラスラベルに分類します。テキスト分類において [BERT](https://arxiv.org/pdf/1810.04805.pdf) などの深層学習ネットワークは高精度です。また、TextNet など、大規模なテキストデータセットでトレーニングされた深層学習ネットワークもあり、約 11,000 のカテゴリで 1,100 万以上のテキストが格納されています。TextNet データでネットワークをトレーニングした後、特定のフォーカスを持つデータセットでネットワークを微調整し、より具体的なテキスト分類タスクを実行できます。Amazon SageMaker AI テキスト分類 - TensorFlow アルゴリズムは、TensorFlow ハブで使用可能な多くの事前トレーニング済みモデルでの転移学習をサポートします。

トレーニングデータ内のクラスラベルの数に応じて、選択した事前トレーニング済み TensorFlow モデルにテキスト分類レイヤーがアタッチされます。分類レイヤーは、ドロップアウトレイヤー、高密度レイヤー、2 ノルム正則化による全結合レイヤーで構成され、ランダムな重みで初期化されます。ドロップアウトレイヤーのドロップアウト率のハイパーパラメータ値と高密度レイヤーの L2 正則化係数は変更することができます。

ネットワーク全体 (事前トレーニング済みモデルを含む) の微調整、または新しいトレーニングデータの最上位の分類レイヤーだけの微調整のいずれかを実行できます。この転移学習の方法を使用すると、より小さなデータセットでのトレーニングが可能になります。

# TensorFlow ハブモデル
<a name="text-classification-tensorflow-Models"></a>

テキスト分類 - TensorFlow アルゴリズムによる転移学習には、次の事前トレーニング済みモデルが使用可能です。

次のモデルは、指定するデータセットにより、サイズ、モデルパラメータの数、トレーニング時間、および推定レイテンシーが大きく異なります。ユースケースに最適なモデルは、微調整するデータセットの複雑さや、トレーニング時間、推論レイテンシー、またはモデルの精度に関する要件によって異なります。


| モデル名 | `model_id` | ソース | 
| --- | --- | --- | 
|  BERT Base Uncased  | `tensorflow-tc-bert-en-uncased-L-12-H-768-A-12-2` | [TensorFlow ハブリンク](https://tfhub.dev/tensorflow/bert_en_uncased_L-12_H-768_A-12/3) | 
|  BERT Base Cased  | `tensorflow-tc-bert-en-cased-L-12-H-768-A-12-2` | [TensorFlow ハブリンク](https://tfhub.dev/tensorflow/bert_en_cased_L-12_H-768_A-12/3) | 
|  BERT Base Multilingual Cased  | `tensorflow-tc-bert-multi-cased-L-12-H-768-A-12-2` | [TensorFlow ハブリンク](https://tfhub.dev/tensorflow/bert_multi_cased_L-12_H-768_A-12/3) | 
|  Small BERT L-2\$1H-128\$1A-2  | `tensorflow-tc-small-bert-bert-en-uncased-L-2-H-128-A-2` | [TensorFlow ハブリンク](https://tfhub.dev/tensorflow/small_bert/bert_en_uncased_L-2_H-128_A-2/1) | 
|  Small BERT L-2\$1H-256\$1A-4 | `tensorflow-tc-small-bert-bert-en-uncased-L-2-H-256-A-4` | [TensorFlow ハブリンク](https://tfhub.dev/tensorflow/small_bert/bert_en_uncased_L-2_H-256_A-4/1) | 
|  Small BERT L-2\$1H-512\$1A-8  | `tensorflow-tc-small-bert-bert-en-uncased-L-2-H-512-A-8` | [TensorFlow ハブリンク](https://tfhub.dev/tensorflow/small_bert/bert_en_uncased_L-2_H-512_A-8/1) | 
|  Small BERT L-2\$1H-768\$1A-12  | `tensorflow-tc-small-bert-bert-en-uncased-L-2-H-768-A-12` | [TensorFlow ハブリンク](https://tfhub.dev/tensorflow/small_bert/bert_en_uncased_L-2_H-768_A-12/1) | 
|  Small BERT L-4\$1H-128\$1A-2  | `tensorflow-tc-small-bert-bert-en-uncased-L-4-H-128-A-2` | [TensorFlow ハブリンク](https://tfhub.dev/tensorflow/small_bert/bert_en_uncased_L-4_H-128_A-2/1) | 
|  Small BERT L-4\$1H-256\$1A-4  | `tensorflow-tc-small-bert-bert-en-uncased-L-4-H-256-A-4` | [TensorFlow ハブリンク](https://tfhub.dev/tensorflow/small_bert/bert_en_uncased_L-4_H-256_A-4/1) | 
|  Small BERT L-4\$1H-512\$1A-8  | `tensorflow-tc-small-bert-bert-en-uncased-L-4-H-512-A-8` | [TensorFlow ハブリンク](https://tfhub.dev/tensorflow/small_bert/bert_en_uncased_L-4_H-512_A-8/1) | 
|  Small BERT L-4\$1H-768\$1A-12  | `tensorflow-tc-small-bert-bert-en-uncased-L-4-H-768-A-12` | [TensorFlow ハブリンク](https://tfhub.dev/tensorflow/small_bert/bert_en_uncased_L-4_H-768_A-12/1) | 
|  Small BERT L-6\$1H-128\$1A-2  | `tensorflow-tc-small-bert-bert-en-uncased-L-6-H-128-A-2` | [TensorFlow ハブリンク](https://tfhub.dev/tensorflow/small_bert/bert_en_uncased_L-6_H-128_A-2/1) | 
|  Small BERT L-6\$1H-256\$1A-4  | `tensorflow-tc-small-bert-bert-en-uncased-L-6-H-256-A-4` | [TensorFlow ハブリンク](https://tfhub.dev/tensorflow/small_bert/bert_en_uncased_L-6_H-256_A-4/1) | 
|  Small BERT L-6\$1H-512\$1A-8  | `tensorflow-tc-small-bert-bert-en-uncased-L-6-H-512-A-8` | [TensorFlow ハブリンク](https://tfhub.dev/tensorflow/small_bert/bert_en_uncased_L-6_H-512_A-8/1) | 
|  Small BERT L-6\$1H-768\$1A-12  | `tensorflow-tc-small-bert-bert-en-uncased-L-6-H-768-A-12` | [TensorFlow ハブリンク](https://tfhub.dev/tensorflow/small_bert/bert_en_uncased_L-6_H-768_A-12/1) | 
|  Small BERT L-8\$1H-128\$1A-2  | `tensorflow-tc-small-bert-bert-en-uncased-L-8-H-128-A-2` | [TensorFlow ハブリンク](https://tfhub.dev/tensorflow/small_bert/bert_en_uncased_L-8_H-128_A-2/1) | 
|  Small BERT L-8\$1H-256\$1A-4  | `tensorflow-tc-small-bert-bert-en-uncased-L-8-H-256-A-4` | [TensorFlow ハブリンク](https://tfhub.dev/tensorflow/small_bert/bert_en_uncased_L-8_H-256_A-4/1) | 
|  Small BERT L-8\$1H-512\$1A-8  | `tensorflow-tc-small-bert-bert-en-uncased-L-8-H-512-A-8` | [TensorFlow ハブリンク](https://tfhub.dev/tensorflow/small_bert/bert_en_uncased_L-8_H-512_A-8/1) | 
|  Small BERT L-8\$1H-768\$1A-12  | `tensorflow-tc-small-bert-bert-en-uncased-L-8-H-768-A-12` | [TensorFlow ハブリンク](https://tfhub.dev/tensorflow/small_bert/bert_en_uncased_L-8_H-768_A-12/1) | 
|  Small BERT L-10\$1H-128\$1A-2  | `tensorflow-tc-small-bert-bert-en-uncased-L-10-H-128-A-2` | [TensorFlow ハブリンク](https://tfhub.dev/tensorflow/small_bert/bert_en_uncased_L-10_H-128_A-2/1) | 
|  Small BERT L-10\$1H-256\$1A-4  | `tensorflow-tc-small-bert-bert-en-uncased-L-10-H-256-A-4` | [TensorFlow ハブリンク](https://tfhub.dev/tensorflow/small_bert/bert_en_uncased_L-10_H-256_A-4/1) | 
|  Small BERT L-10\$1H-512\$1A-8  | `tensorflow-tc-small-bert-bert-en-uncased-L-10-H-512-A-8` | [TensorFlow ハブリンク](https://tfhub.dev/tensorflow/small_bert/bert_en_uncased_L-10_H-512_A-8/1) | 
|  Small BERT L-10\$1H-768\$1A-12  | `tensorflow-tc-small-bert-bert-en-uncased-L-10-H-768-A-12` | [TensorFlow ハブリンク](https://tfhub.dev/tensorflow/small_bert/bert_en_uncased_L-10_H-768_A-12/1) | 
|  Small BERT L-12\$1H-128\$1A-2  | `tensorflow-tc-small-bert-bert-en-uncased-L-12-H-128-A-2` | [TensorFlow ハブリンク](https://tfhub.dev/tensorflow/small_bert/bert_en_uncased_L-12_H-128_A-2/1) | 
|  Small BERT L-12\$1H-256\$1A-4  | `tensorflow-tc-small-bert-bert-en-uncased-L-12-H-256-A-4` | [TensorFlow ハブリンク](https://tfhub.dev/tensorflow/small_bert/bert_en_uncased_L-12_H-256_A-4/1) | 
|  Small BERT L-12\$1H-512\$1A-8  | `tensorflow-tc-small-bert-bert-en-uncased-L-12-H-512-A-8` | [TensorFlow ハブリンク](https://tfhub.dev/tensorflow/small_bert/bert_en_uncased_L-12_H-512_A-8/1) | 
|  Small BERT L-12\$1H-768\$1A-12  | `tensorflow-tc-small-bert-bert-en-uncased-L-12-H-768-A-12` | [TensorFlow ハブリンク](https://tfhub.dev/tensorflow/small_bert/bert_en_uncased_L-12_H-768_A-12/1) | 
|  BERT Large Uncased  | `tensorflow-tc-bert-en-uncased-L-24-H-1024-A-16-2` | [TensorFlow ハブリンク](https://tfhub.dev/tensorflow/bert_en_uncased_L-24_H-1024_A-16/3) | 
|  BERT Large Cased  | `tensorflow-tc-bert-en-cased-L-24-H-1024-A-16-2` | [TensorFlow ハブリンク](https://tfhub.dev/tensorflow/bert_en_cased_L-24_H-1024_A-16/3) | 
|  BERT Large Uncased Whole Word Masking  | `tensorflow-tc-bert-en-wwm-uncased-L-24-H-1024-A-16-2` | [TensorFlow ハブリンク](https://tfhub.dev/tensorflow/bert_en_wwm_uncased_L-24_H-1024_A-16/3) | 
|  BERT Large Cased Whole Word Masking  | `tensorflow-tc-bert-en-wwm-cased-L-24-H-1024-A-16-2` | [TensorFlow ハブリンク](https://tfhub.dev/tensorflow/bert_en_wwm_cased_L-24_H-1024_A-16/3) | 
|  ALBERT Base  | `tensorflow-tc-albert-en-base` | [TensorFlow ハブリンク](https://tfhub.dev/tensorflow/albert_en_base/2) | 
|  ELECTRA Small\$1\$1  | `tensorflow-tc-electra-small-1` | [TensorFlow ハブリンク](https://tfhub.dev/google/electra_small/2) | 
|  ELECTRA Base  | `tensorflow-tc-electra-base-1` | [TensorFlow ハブリンク](https://tfhub.dev/google/electra_base/2) | 
|  BERT Base Wikipedia and BooksCorpus  | `tensorflow-tc-experts-bert-wiki-books-1` | [TensorFlow ハブリンク](https://tfhub.dev/google/experts/bert/wiki_books/2) | 
|  BERT Base MEDLINE/PubMed  | `tensorflow-tc-experts-bert-pubmed-1` | [TensorFlow ハブリンク](https://tfhub.dev/google/experts/bert/pubmed/2) | 
|  トラッキングヘッド Base  | `tensorflow-tc-talking-heads-base` | [TensorFlow ハブリンク](https://tfhub.dev/tensorflow/talkheads_ggelu_bert_en_base/1) | 
|  トラッキングヘッド Large  | `tensorflow-tc-talking-heads-large` | [TensorFlow ハブリンク](https://tfhub.dev/tensorflow/talkheads_ggelu_bert_en_large/1) | 

# テキスト分類 - TensorFlow ハイパーパラメータ
<a name="text-classification-tensorflow-Hyperparameter"></a>

ハイパーパラメータは、機械学習モデルが学習を開始する前に設定されるパラメータです。Amazon SageMaker AI 組み込みオブジェクト検出 - TensorFlow アルゴリズムでは、次のハイパーパラメータがサポートされています。ハイパーパラメータのチューニングに関する詳細ついては、「[テキスト分類 - TensorFlow モデルの調整](text-classification-tensorflow-tuning.md)」を参照してください。


| Parameter Name | 説明 | 
| --- | --- | 
| batch\$1size |  トレーニングのバッチサイズ。複数の GPU を使用するインスタンスのトレーニングでは、このバッチサイズは GPU 間で使用されます。 有効な値: 正の整数。 デフォルト値: `32`。  | 
| beta\$11 |  `"adam"` および `"adamw"` オプティマイザの beta1。最初のモーメントの見積もりの指数関数的減衰率を表します。他のオプティマイザでは無視されます。 有効な値: 浮動小数点数、範囲: [`0.0`, `1.0`]。 デフォルト値: `0.9`。  | 
| beta\$12 |  `"adam"` および `"adamw"` オプティマイザの beta2。2 番目のモーメントの見積もりの指数関数的減衰率を表します。他のオプティマイザでは無視されます。 有効な値: 浮動小数点数、範囲: [`0.0`, `1.0`]。 デフォルト値: `0.999`。  | 
| dropout\$1rate | 最上位の分類レイヤーのドロップアウトレイヤーのドロップアウト率。`reinitialize_top_layer` が `"True"` に設定されている場合にのみ使用されます。 有効な値: 浮動小数点数、範囲: [`0.0`, `1.0`]。 デフォルト値: `0.2` | 
| early\$1stopping |  `"True"` に設定すると、トレーニング中に早期停止ロジックを使用します。`"False"` の場合、早期停止は使用されません。 有効な値: 文字列、(`"True"` または `"False"`) のいずれか。 デフォルト値: `"False"`。  | 
| early\$1stopping\$1min\$1delta | 改善と認定するのに必要な最小変化。early\$1stopping\$1min\$1delta の値より小さな絶対変化は、改善とは認定されません。early\$1stopping が "True" に設定されている場合にのみ使用されます。有効な値: 浮動小数点数、範囲: [`0.0`, `1.0`]。デフォルト値: `0.0`。 | 
| early\$1stopping\$1patience |  改善なしでトレーニングを継続できるエポック数。`early_stopping` が `"True"` に設定されている場合にのみ使用されます。 有効な値: 正の整数。 デフォルト値: `5`。  | 
| epochs |  トレーニングエポックの数。 有効な値: 正の整数。 デフォルト値: `10`。  | 
| epsilon |  `"adam"`、`"rmsprop"`、`"adadelta"`、および `"adagrad"` オプティマイザのイプシロン。通常は、0 で除算されないように小さな値を設定します。他のオプティマイザでは無視されます。 有効な値: 浮動小数点数、範囲: [`0.0`, `1.0`]。 デフォルト値: `1e-7`。  | 
| initial\$1accumulator\$1value |  アキュムレータの開始値、または `"adagrad"` オプティマイザのパラメータごとのモーメンタム値。他のオプティマイザでは無視されます。 有効な値: 浮動小数点数、範囲: [`0.0`, `1.0`]。 デフォルト値: `0.0001`。  | 
| learning\$1rate | オプティマイザの学習レート。有効な値: 浮動小数点数、範囲: [`0.0`, `1.0`]。デフォルト値: `0.001`。 | 
| momentum |  `"sgd"` および `"nesterov"` オプティマイザのモーメンタム。他のオプティマイザでは無視されます。 有効な値: 浮動小数点数、範囲: [`0.0`, `1.0`]。 デフォルト値: `0.9`。  | 
| optimizer |  オプティマイザのタイプ。詳細については、TensorFlow ドキュメントの「[Optimizers](https://www.tensorflow.org/api_docs/python/tf/keras/optimizers)」を参照してください。 有効な値: 文字列、(`"adamw"`、`"adam"`、`"sgd"`、`"nesterov"`、`"rmsprop"`、` "adagrad"`、`"adadelta"`) のいずれか。 デフォルト値: `"adam"`。  | 
| regularizers\$1l2 |  分類レイヤーの高密度レイヤーの L2 正則化係数。`reinitialize_top_layer` が `"True"` に設定されている場合にのみ使用されます。 有効な値: 浮動小数点数、範囲: [`0.0`, `1.0`]。 デフォルト値: `0.0001`。  | 
| reinitialize\$1top\$1layer |  `"Auto"` に設定すると、微調整時に最上位の分類レイヤーパラメータが再初期化されます。段階的トレーニングの場合、`"True"` に設定されない限り、最上位の分類レイヤーのパラメータは再初期化されません。 有効な値: 文字列、(`"Auto"`、`"True"`、または `"False"`) のいずれかです。 デフォルト値: `"Auto"`。  | 
| rho |  `"adadelta"` および `"rmsprop"` オプティマイザの勾配の割引係数。他のオプティマイザでは無視されます。 有効な値: 浮動小数点数、範囲: [`0.0`, `1.0`]。 デフォルト値: `0.95`。  | 
| train\$1only\$1on\$1top\$1layer |  `"True"` の場合、最上位の分類レイヤーパラメータのみ微調整されます。`"False"` の場合、すべてのモデルパラメータが微調整されます。 有効な値: 文字列、(`"True"` または `"False"`) のいずれか。 デフォルト値: `"False"`。  | 
| validation\$1split\$1ratio |  ランダムに分割して検証データを作成するトレーニングデータの割合。検証データが `validation` チャネルを介して提供されていない場合にのみ使用されます。 有効な値: 浮動小数点数、範囲: [`0.0`, `1.0`]。 デフォルト値: `0.2`。  | 
| warmup\$1steps\$1fraction |  ウォームアップとして学習レートが 0 から初期学習レートに増加する勾配更新ステップの合計数の割合。`adamw` オプティマイザでのみ使用されます。 有効な値: 浮動小数点数、範囲: [`0.0`, `1.0`]。 デフォルト値: `0.1`。  | 

# テキスト分類 - TensorFlow モデルの調整
<a name="text-classification-tensorflow-tuning"></a>

*自動モデル調整*は、ハイパーパラメータ調整とも呼ばれ、データセットのさまざまなハイパーパラメータをテストする多数のジョブを実行して、モデルの最適なバージョンを見つけます。調整可能なハイパーパラメータ、それぞれの値の範囲、および目標メトリクスを選択します。アルゴリズムが計算するメトリクスから目標メトリクスを選択します。自動モデル調整は、選択されたハイパーパラメータを検索して、目標メトリクスを最適化するモデルになる値の組み合わせを見つけます。

モデル調整の詳細については、「[SageMaker AI の自動モデルチューニング](automatic-model-tuning.md)」を参照してください。

## テキスト分類 - TensorFlow アルゴリズムによって計算されたメトリクス
<a name="text-classification-tensorflow-metrics"></a>

次の表を参照して、テキスト分類 - TensorFlow アルゴリズムによって計算されるメトリクスを確認してください。


| メトリクス名 | 説明 | 最適化の方向 | 正規表現パターン | 
| --- | --- | --- | --- | 
| validation:accuracy | 実行された予測の総数に対する正しい予測の数の比率。 | 最大化 | `val_accuracy=([0-9\\.]+)` | 

## 調整可能なテキスト分類 - TensorFlow ハイパーパラメータ
<a name="text-classification-tensorflow-tunable-hyperparameters"></a>

次のハイパーパラメータを使用してテキスト分類モデルを調整します。テキスト分類の目標メトリクスに最も大きな影響を与えるハイパーパラメータは、`batch_size`、`learning_rate`、および `optimizer` です。選択した `optimizer` に基づいて、`momentum`、`regularizers_l2`、`beta_1`、`beta_2`、および `eps` などのオプティマイザ関連のハイパーパラメータを調整します。例えば、`adamw` または `adam` が `optimizer` である場合にのみ `beta_1` と `beta_2` を使用します。

各 `optimizer` で使用されるハイパーパラメータの詳細については、「[テキスト分類 - TensorFlow ハイパーパラメータ](text-classification-tensorflow-Hyperparameter.md)」を参照してください。


| パラメータ名 | パラメータタイプ | 推奨範囲 | 
| --- | --- | --- | 
| batch\$1size | IntegerParameterRanges | MinValue: 4, MaxValue: 128 | 
| beta\$11 | ContinuousParameterRanges | MinValue: 1e-6、MaxValue: 0.999 | 
| beta\$12 | ContinuousParameterRanges | MinValue: 1e-6、MaxValue: 0.999 | 
| eps | ContinuousParameterRanges | MinValue: 1e-8、MaxValue: 1.0 | 
| learning\$1rate | ContinuousParameterRanges | MinValue: 1e-6、MaxValue: 0.5 | 
| momentum | ContinuousParameterRanges | MinValue: 0.0、MaxValue: 0.999 | 
| optimizer | CategoricalParameterRanges | ['adamw', 'adam', 'sgd', 'rmsprop', 'nesterov', 'adagrad', 'adadelta'] | 
| regularizers\$1l2 | ContinuousParameterRanges | MinValue: 0.0、MaxValue: 0.999 | 
| train\$1only\$1on\$1top\$1layer | CategoricalParameterRanges | ['True', 'False'] | 