ステップ 5: ハイパーパラメータを調整する
コレクションでコンテンツを整理 必要に応じて、コンテンツの保存と分類を行います。
モデルを定義してトレーニングするために、多くのハイパーパラメータを選択する必要がありました。直感、例、おすすめの方法を参考にしました。ただし、最初にハイパーパラメータ値を選択しても、最適な結果が得られない可能性があります。これは、トレーニングの出発点にすぎない。すべての問題は異なります。これらのハイパーパラメータを調整すると、モデルの絞り込みを行い、発生している問題の特異性をより適切に再現できます。使用したハイパーパラメータのいくつかと、それらの調整の意味を見てみましょう。
モデルのレイヤ数: ニューラル ネットワークのレイヤ数は、その複雑さの指標です。この値を選択する際は注意が必要です。レイヤが多すぎると、モデルがトレーニング データに関して大量の情報を学習し、過学習の原因となります。レイヤが少なすぎると、モデルの学習能力が制限され、適合不足を引き起こす可能性があります。テキスト分類データセットについては、1 レイヤ、2 レイヤ、3 レイヤの MLP をテストしました。2 レイヤモデルのモデルはうまく機能しており、場合によっては 3 レイヤモデルよりも優れたパフォーマンスを発揮します。同様に、4 層と 6 層で sepCNN を試したところ、4 層モデルの性能が良好でした。
レイヤあたりのユニット数: レイヤのユニットは、レイヤが実行する変換の情報を保持する必要があります。最初のレイヤでは、これは特徴の数によって決まります。後続のレイヤでユニット数は、前のレイヤで表現を展開または縮小するかどうかによって異なります。レイヤ間の情報損失を最小限に抑えるようにしてください。[8, 16, 32, 64]
の範囲の単位を試しましたが、32/64 単位がうまく機能しました。
ドロップアウト率: ドロップアウト レイヤは、モデルで正則化に使用されます。過学習の対策として、破棄する入力の割合を定義します。推奨範囲: 0.2 ~ 0.5。
学習率: イテレーション間でニューラル ネットワークの重みが変化する頻度です。学習率が高いと重みが大きく変動し、最適な値を見つけられないことがあります。学習率は低くても問題ありませんが、収束にさらに反復処理が必要になります。最初は 1e-4 から始めることをおすすめします。トレーニングが非常に遅い場合は、この値を増やします。モデルが学習していない場合は、学習率を下げてみてください。
spCNN モデルに固有の、調整したハイパーパラメータは他にもあります。
カーネルサイズ: 畳み込みウィンドウのサイズ。推奨値: 3 または 5。
埋め込みディメンション: 単語のエンベディングを表すために使用するディメンションの数。つまり、各単語ベクトルのサイズです。推奨値: 50 ~ 300。Google のテストでは、事前トレーニング済みのエンベディング レイヤで、200 次元の GloVe エンベディングを使用しました。
これらのハイパーパラメータを試し、何が最適かを確かめてください。ユースケースに最適なパフォーマンスのハイパーパラメータを選択したら、モデルをデプロイできます。
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2025-07-27 UTC。
[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["必要な情報がない","missingTheInformationINeed","thumb-down"],["複雑すぎる / 手順が多すぎる","tooComplicatedTooManySteps","thumb-down"],["最新ではない","outOfDate","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["サンプル / コードに問題がある","samplesCodeIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 2025-07-27 UTC。"],[[["\u003cp\u003eInitial hyperparameter choices provide a starting point for model training, but further tuning is crucial to optimize performance for specific text classification problems.\u003c/p\u003e\n"],["\u003cp\u003eThe number of layers in a neural network impacts its complexity, with two-layer MLPs and four-layer sepCNNs showing promising results in text classification.\u003c/p\u003e\n"],["\u003cp\u003eKey hyperparameters to adjust include the number of units per layer (32 or 64 performed well), dropout rate (0.2-0.5 recommended), and learning rate (start low and adjust based on training progress).\u003c/p\u003e\n"],["\u003cp\u003eFor sepCNN models, optimizing kernel size (3 or 5) and embedding dimensions (50-300) further enhances performance.\u003c/p\u003e\n"],["\u003cp\u003eExperimenting with different hyperparameter combinations is essential to achieve the best model performance for your specific use case before deployment.\u003c/p\u003e\n"]]],[],null,["We had to choose a number of hyperparameters for defining and training the\nmodel. We relied on intuition, examples and best practice recommendations. Our\nfirst choice of hyperparameter values, however, may not yield the best results.\nIt only gives us a good starting point for training. Every problem is different\nand tuning these hyperparameters will help refine our model to better represent\nthe particularities of the problem at hand. Let's take a look at some of the\nhyperparameters we used and what it means to tune them:\n\n- **Number of layers in the model** : The number of layers in a neural network is\n an indicator of its complexity. We must be careful in choosing this value. Too\n many layers will allow the model to learn too much information about the\n training data, causing overfitting. Too few layers can limit the model's\n learning ability, causing underfitting. For text classification datasets, we\n experimented with one, two, and three-layer MLPs. Models with two layers\n performed well, and in some cases better than three-layer models. Similarly, we\n tried [sepCNN](https://developers.google.com/machine-learning/glossary?utm_source=DevSite&utm_campaign=Text-Class-Guide&utm_medium=referral&utm_content=glossary&utm_term=sepCNN#depthwise-separable-convolutional-neural-network-sepcnn)s\n with four and six layers, and the four-layer models performed well.\n\n- **Number of units per layer** : The units in a layer must hold the information\n for the transformation that a layer performs. For the first layer, this is\n driven by the number of features. In subsequent layers, the number of units\n depends on the choice of expanding or contracting the representation from the\n previous layer. Try to minimize the information loss between layers. We tried\n unit values in the range `[8, 16, 32, 64]`, and 32/64 units worked well.\n\n- **Dropout rate** : Dropout layers are used in the model for\n [regularization](https://developers.google.com/machine-learning/glossary/?utm_source=DevSite&utm_campaign=Text-Class-Guide&utm_medium=referral&utm_content=glossary&utm_term=dropout-regularization#dropout_regularization).\n They define the fraction of input to drop as a precaution for overfitting.\n Recommended range: 0.2--0.5.\n\n- **Learning rate**: This is the rate at which the neural network weights change\n between iterations. A large learning rate may cause large swings in the weights,\n and we may never find their optimal values. A low learning rate is good, but the\n model will take more iterations to converge. It is a good idea to start low, say\n at 1e-4. If the training is very slow, increase this value. If your model is not\n learning, try decreasing learning rate.\n\nThere are couple of additional hyperparameters we tuned that are specific to our\nsepCNN model:\n\n1. **Kernel size**: The size of the convolution window. Recommended values: 3 or\n 5.\n\n2. **Embedding dimensions**: The number of dimensions we want to use to represent\n word embeddings---i.e., the size of each word vector. Recommended values: 50--300.\n In our experiments, we used GloVe embeddings with 200 dimensions with a pre-\n trained embedding layer.\n\nPlay around with these hyperparameters and see what works best. Once you have\nchosen the best-performing hyperparameters for your use case, your model is\nready to be deployed."]]