

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

# 文字分類 - TensorFlow
<a name="text-classification-tensorflow"></a>

Amazon SageMaker AI 文字分類-TensorFlow 演算法是一種監督式學習演算法，可支援使用 [TensorFlow 中心](https://tfhub.dev/)中許多預先訓練的模型進行轉移學習。即使無法提供大量文字資料，您也可以使用轉移學習來微調自己的資料集上其中一個可用的預先訓練模型。文字分類演算法需要一個文字字串作為輸入，並針對每個類別標籤輸出一個機率。訓練資料集必須採用 CSV 格式。此頁面包含 Amazon EC2 執行個體推薦服務和文字分類 - TensorFlow 範例筆記本的相關資訊。

**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 Hub 模型](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 內建演算法。下一節描述如何將文字分類 - TensorFlow 搭配 SageMaker AI Python SDK 使用。如需如何從 Amazon SageMaker Studio Classic 使用者介面使用文字分類 - TensorFlow 的資訊，請參閱[SageMaker JumpStart 預先訓練模型](studio-jumpstart.md)。

文字分類 - TensorFlow 演算法支援使用任何相容預先訓練的 TensorFlow 模型進行轉移學習。如需有關所有可用之預先訓練模型的清單，請參閱[TensorFlow Hub 模型](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 Hub 預先下載並儲存在 Amazon S3 儲存貯體中，以便訓練任務可以在網路隔離中執行。使用這些預先產生的模型訓練成品，來建構 SageMaker AI 估算器。

首先，檢索 Docker 映像 URI，訓練指令碼 URI 和預先訓練的模型 URI。然後，視需要變更超參數。您可以使用 `hyperparameters.retrieve_default` 查看所有可用超參數及其預設數值的 Python 字典。如需詳細資訊，請參閱[文字分類 - 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 演算法進行轉移學習的更多相關資訊，請參閱 [JumpStart - 文字分類](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 Hub 模型中列入的每個預先訓練模型，皆可針對由具有任何類別數量之文字句子組成的任何資料集進行微調。預先訓練的模型會將分類層連接到文字內嵌項目模型，並將層參數初始化為隨機值。分類層的輸出維度是基於在輸入資料中偵測到的類別數量來決定。

請注意如何格式化您的訓練資料，以輸入至文字分類 - TensorFlow模型。
+ **訓練資料輸入格式：**包含 `data.csv` 檔案的目錄。首欄的每一列應具有介於 0 和類別數量之間的整數類別標籤。第二欄的每一列應具有對應的文字資料。

以下為輸入 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 演算法使用增量訓練的更多資訊，請參閱 [JumpStart - 文字分類簡介](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 模型會針對每個請求處理單一字串，而且只輸出一行。以下為 JSON 格式回應的範例：

```
accept: application/json;verbose

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

如果將 `accept` 設定為 `application/json`，則模型僅輸出機率。

## 文字分類 - 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 演算法進行轉移學習的更多相關資訊，請參閱 [JumpStart - 文字分類簡介](https://github.com/aws/amazon-sagemaker-examples/blob/main/introduction_to_amazon_algorithms/jumpstart_text_classification/Amazon_JumpStart_Text_Classification.ipynb)筆記本。

如需如何建立並存取 Jupyter 筆記本執行個體以用來執行 SageMaker AI 中範例的指示，請參閱[Amazon SageMaker 筆記本執行個體](nbi.md)。建立並開啟筆記本執行個體後，請選擇 **SageMaker AI 範例**索引標籤，查看所有 SageMaker AI 範例清單。若要開啟筆記本，請選擇其**使用**標籤，然後選擇**建立複本**。

# 文字分類 - TensorFlow 的運作方式
<a name="text-classification-tensorflow-HowItWorks"></a>

文字分類 - TensorFlow 演算法會將文字分類為其中一個輸出類別標籤。對於文字分類來說，[BERT](https://arxiv.org/pdf/1810.04805.pdf) 等深度學習網路為高度準確。還有在大型文字資料集上進行訓練的深度學習網路 (例如 TextNet)，該網路具有超過 1100 萬個文字，大約有 11,000 個類別。使用 TextNet 資料訓練網路之後，您可以在具有特定焦點的資料集上微調網路，以執行更多特定的文字分類任務。Amazon SageMaker AI 文字分類 - TensorFlow 演算法支援在 TensorFlow Hub 中提供的許多預先訓練模型上進行轉移學習。

根據訓練資料中的類別標籤數量，文字分類層會連接到您選擇的預先訓練 TensorFlow 模型。分類層由一個退出層、一密集層以及具有 2 規範正規化的完全已連線的層組成，並以隨機權重初始化。您可以變更退出層的退出率超參數值，以及密集層的 L2 正規化因素。

您可以微調整個網路 (包含預先訓練的模型)，或僅微調新訓練資料的頂部分類層。使用這種轉移學習方法，可以使用較小的資料集進行訓練。

# TensorFlow Hub 模型
<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 Hub 連結](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 Hub 連結](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 Hub 連結](https://tfhub.dev/tensorflow/bert_multi_cased_L-12_H-768_A-12/3) | 
|  小型 BERT L-2\$1H-128\$1A-2  | `tensorflow-tc-small-bert-bert-en-uncased-L-2-H-128-A-2` | [TensorFlow Hub 連結](https://tfhub.dev/tensorflow/small_bert/bert_en_uncased_L-2_H-128_A-2/1) | 
|  小型 BERT L-2\$1H-256\$1A-4 | `tensorflow-tc-small-bert-bert-en-uncased-L-2-H-256-A-4` | [TensorFlow Hub 連結](https://tfhub.dev/tensorflow/small_bert/bert_en_uncased_L-2_H-256_A-4/1) | 
|  小型 BERT L-2\$1H-512\$1A-8  | `tensorflow-tc-small-bert-bert-en-uncased-L-2-H-512-A-8` | [TensorFlow Hub 連結](https://tfhub.dev/tensorflow/small_bert/bert_en_uncased_L-2_H-512_A-8/1) | 
|  小型 BERT L-2\$1H-768\$1A-12  | `tensorflow-tc-small-bert-bert-en-uncased-L-2-H-768-A-12` | [TensorFlow Hub 連結](https://tfhub.dev/tensorflow/small_bert/bert_en_uncased_L-2_H-768_A-12/1) | 
|  小型 BERT L-4\$1H-128\$1A-2  | `tensorflow-tc-small-bert-bert-en-uncased-L-4-H-128-A-2` | [TensorFlow Hub 連結](https://tfhub.dev/tensorflow/small_bert/bert_en_uncased_L-4_H-128_A-2/1) | 
|  小型 BERT L-4\$1H-256\$1A-4  | `tensorflow-tc-small-bert-bert-en-uncased-L-4-H-256-A-4` | [TensorFlow Hub 連結](https://tfhub.dev/tensorflow/small_bert/bert_en_uncased_L-4_H-256_A-4/1) | 
|  小型 BERT L-4\$1H-512\$1A-8  | `tensorflow-tc-small-bert-bert-en-uncased-L-4-H-512-A-8` | [TensorFlow Hub 連結](https://tfhub.dev/tensorflow/small_bert/bert_en_uncased_L-4_H-512_A-8/1) | 
|  小型 BERT L-4\$1H-768\$1A-12  | `tensorflow-tc-small-bert-bert-en-uncased-L-4-H-768-A-12` | [TensorFlow Hub 連結](https://tfhub.dev/tensorflow/small_bert/bert_en_uncased_L-4_H-768_A-12/1) | 
|  小型 BERT L-6\$1H-128\$1A-2  | `tensorflow-tc-small-bert-bert-en-uncased-L-6-H-128-A-2` | [TensorFlow Hub 連結](https://tfhub.dev/tensorflow/small_bert/bert_en_uncased_L-6_H-128_A-2/1) | 
|  小型 BERT L-6\$1H-256\$1A-4  | `tensorflow-tc-small-bert-bert-en-uncased-L-6-H-256-A-4` | [TensorFlow Hub 連結](https://tfhub.dev/tensorflow/small_bert/bert_en_uncased_L-6_H-256_A-4/1) | 
|  小型 BERT L-6\$1H-512\$1A-8  | `tensorflow-tc-small-bert-bert-en-uncased-L-6-H-512-A-8` | [TensorFlow Hub 連結](https://tfhub.dev/tensorflow/small_bert/bert_en_uncased_L-6_H-512_A-8/1) | 
|  小型 BERT L-6\$1H-768\$1A-12  | `tensorflow-tc-small-bert-bert-en-uncased-L-6-H-768-A-12` | [TensorFlow Hub 連結](https://tfhub.dev/tensorflow/small_bert/bert_en_uncased_L-6_H-768_A-12/1) | 
|  小型 BERT L-8\$1H-128\$1A-2  | `tensorflow-tc-small-bert-bert-en-uncased-L-8-H-128-A-2` | [TensorFlow Hub 連結](https://tfhub.dev/tensorflow/small_bert/bert_en_uncased_L-8_H-128_A-2/1) | 
|  小型 BERT L-8\$1H-256\$1A-4  | `tensorflow-tc-small-bert-bert-en-uncased-L-8-H-256-A-4` | [TensorFlow Hub 連結](https://tfhub.dev/tensorflow/small_bert/bert_en_uncased_L-8_H-256_A-4/1) | 
|  小型 BERT L-8\$1H-512\$1A-8  | `tensorflow-tc-small-bert-bert-en-uncased-L-8-H-512-A-8` | [TensorFlow Hub 連結](https://tfhub.dev/tensorflow/small_bert/bert_en_uncased_L-8_H-512_A-8/1) | 
|  小型 BERT L-8\$1H-768\$1A-12  | `tensorflow-tc-small-bert-bert-en-uncased-L-8-H-768-A-12` | [TensorFlow Hub 連結](https://tfhub.dev/tensorflow/small_bert/bert_en_uncased_L-8_H-768_A-12/1) | 
|  小型 BERT L-10\$1H-128\$1A-2  | `tensorflow-tc-small-bert-bert-en-uncased-L-10-H-128-A-2` | [TensorFlow Hub 連結](https://tfhub.dev/tensorflow/small_bert/bert_en_uncased_L-10_H-128_A-2/1) | 
|  小型 BERT L-10\$1H-256\$1A-4  | `tensorflow-tc-small-bert-bert-en-uncased-L-10-H-256-A-4` | [TensorFlow Hub 連結](https://tfhub.dev/tensorflow/small_bert/bert_en_uncased_L-10_H-256_A-4/1) | 
|  小型 BERT L-10\$1H-512\$1A-8  | `tensorflow-tc-small-bert-bert-en-uncased-L-10-H-512-A-8` | [TensorFlow Hub 連結](https://tfhub.dev/tensorflow/small_bert/bert_en_uncased_L-10_H-512_A-8/1) | 
|  小型 BERT L-10\$1H-768\$1A-12  | `tensorflow-tc-small-bert-bert-en-uncased-L-10-H-768-A-12` | [TensorFlow Hub 連結](https://tfhub.dev/tensorflow/small_bert/bert_en_uncased_L-10_H-768_A-12/1) | 
|  小型 L-12\$1H-128\$1A-2  | `tensorflow-tc-small-bert-bert-en-uncased-L-12-H-128-A-2` | [TensorFlow Hub 連結](https://tfhub.dev/tensorflow/small_bert/bert_en_uncased_L-12_H-128_A-2/1) | 
|  小型 BERT L-12\$1H-256\$1A-4  | `tensorflow-tc-small-bert-bert-en-uncased-L-12-H-256-A-4` | [TensorFlow Hub 連結](https://tfhub.dev/tensorflow/small_bert/bert_en_uncased_L-12_H-256_A-4/1) | 
|  小型 BERT L-12\$1H-512\$1A-8  | `tensorflow-tc-small-bert-bert-en-uncased-L-12-H-512-A-8` | [TensorFlow Hub 連結](https://tfhub.dev/tensorflow/small_bert/bert_en_uncased_L-12_H-512_A-8/1) | 
|  小型 BERT L-12\$1H-768\$1A-12  | `tensorflow-tc-small-bert-bert-en-uncased-L-12-H-768-A-12` | [TensorFlow Hub 連結](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 Hub 連結](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 Hub 連結](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 Hub 連結](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 Hub 連結](https://tfhub.dev/tensorflow/bert_en_wwm_cased_L-24_H-1024_A-16/3) | 
|  ALBERT Base  | `tensorflow-tc-albert-en-base` | [TensorFlow Hub 連結](https://tfhub.dev/tensorflow/albert_en_base/2) | 
|  ELECTRA Small\$1\$1  | `tensorflow-tc-electra-small-1` | [TensorFlow Hub 連結](https://tfhub.dev/google/electra_small/2) | 
|  ELECTRA Base  | `tensorflow-tc-electra-base-1` | [TensorFlow Hub 連結](https://tfhub.dev/google/electra_base/2) | 
|  BERT Base Wikipedia and BooksCorpus  | `tensorflow-tc-experts-bert-wiki-books-1` | [TensorFlow Hub 連結](https://tfhub.dev/google/experts/bert/wiki_books/2) | 
|  BERT Base MEDLINE/PubMed  | `tensorflow-tc-experts-bert-pubmed-1` | [TensorFlow Hub 連結](https://tfhub.dev/google/experts/bert/pubmed/2) | 
|  Talking Heads Base  | `tensorflow-tc-talking-heads-base` | [TensorFlow Hub 連結](https://tfhub.dev/tensorflow/talkheads_ggelu_bert_en_base/1) | 
|  Talking Heads Large  | `tensorflow-tc-talking-heads-large` | [TensorFlow Hub 連結](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)。


| 參數名稱 | Description | 
| --- | --- | 
| batch\$1size |  訓練的批次大小。以多個 GPU 在執行個體進行訓練時，會在整個 GPU 中使用此批次大小。 有效值：正整數。 預設值：`32`。  | 
| beta\$11 |  `"adam"` 和 `"adamw"` 最佳化工具的 beta1。代表第一時間預估的指數衰減率。若是其他最佳化工具則忽略。 有效值：浮動、範圍：[`0.0`,`1.0`]。 預設值：`0.9`。  | 
| beta\$12 |  `"adam"` 和 `"adamw"` 最佳化工具的 beta2。代表第二時間預估的指數衰減率。若是其他最佳化工具則忽略。 有效值：浮動、範圍：[`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 |  訓練 epoch 的數量。 有效值：正整數。 預設值：`10`。  | 
| epsilon |  用於 `"adam"`、`"rmsprop"`、`"adadelta"` 和 `"adagrad"` 最佳化工具的 epsilon。通常會設定為較小值，避免要將該值除以 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 文件中的[最佳化工具](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 演算法所運算的指標。


| 指標名稱 | Description | 最佳化方向 | 正則表達式 | 
| --- | --- | --- | --- | 
| 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'] | 