ニューラル ネットワーク: インタラクティブな演習
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
以下のインタラクティブな演習では、Terraform の内部動作について詳しく見ていきます。
生成します。まず、パラメータとハイパーパラメータが
ネットワークの予測に影響します次に、学習した内容を活用して、
ニューラル ネットワークです。
演習 1
次のウィジェットは、以下の構成でニューラル ネットワークをセットアップしています。
- 値
0.00
、0.00
、0.00
を含む 3 つのニューロンを持つ入力レイヤ
- 4 つのニューロンを持つ隠れ層
- 1 個のニューロンを持つ出力層
- ReLU 活性化関数を適用:
出力ノードは、すべての隠れ層ノードと
ネットワークの初期設定を確認します(注: ▶️ または
>| ボタンなど)をクリックし、ウィジェットの下でタスクを完了します。
タスク 1
ニューラル ネットワーク モデルに入力される 3 つの特徴量の値はすべて
0.00
。ネットワーク内の各ノードをクリックして、初期化された
使用できます。再生ボタン(▶️)を押す前に、次の質問に回答してください。
モデルの出力値から
正か負か、0 か?
正の出力値
あなたは肯定的です
出力値。手順は次のとおりです。
入力データに対して推論を行い、正しいことを確認します。
負の出力値
除外
出力値。手順は次のとおりです。
入力データに対して推論を行い、正しいことを確認します。
出力値 0
選択した出力
0 の場合。手順は次のとおりです。
入力データに対して推論を行い、正しいことを確認します。
次に、ネットワークの上にある再生ボタン(▶️)をクリックして、隠れ層をすべて視聴します。
出力ノードの値が入力されます。上記の回答は正しかったですか?
こちらをクリックして説明をご覧ください
得られる正確な出力値は、重み
および bias パラメータはランダムに初期化されます。ただし、各ニューロンは
は、値が 0 で、入力レイヤを計算するために使用される
隠れ層のノード値はすべてゼロになります。たとえば、最初の
隠れ層ノードの計算は次のようになります。
y = ReLU(w11×0.00 + w21×0.00 + w31×0.00 + b)
y = ReLU(b)
したがって、各隠れ層ノードの値は、モデルの ReLU 値と等しくなります。
bias(b): b が負の場合は 0、b が 0 の場合は b 自体
評価します
出力ノードの値は、次のように計算されます。
y = ReLU(w11×x11 + w21×x21)
+w31×x31 + w41×41 + b)
タスク 2
ニューラル ネットワークを変更する前に、次の質問に答えてください。
隠れ層をもう 1 つ追加した場合
最初の隠れ層の後にニューラル ネットワークに与えられます。この新しいレイヤ 3 ノードは、
同じ入力パラメータと重み/バイアス パラメータを計算
どのような影響を受けるか
すべてのノード
入力ノードは除きます。
ここでは、
(入力ノードを除く)。詳しくは、
ニューラル ネットワークをアップデートして、
正解。
クラスタ内のノードだけが、
最初の隠れ層
選んだ
最初の隠れ層のノードになります。手順は次のとおりです。
ニューラル ネットワークを更新し、問題ないか確認します。
出力ノードのみ
選んだ
出力ノードを指定します。以下の手順に沿って、
問題ないか確認しましょう
次に、次のように 3 つのノードを持つ新しい隠れ層を追加するようにニューラル ネットワークを変更します。
- 「1 hidden layer」というテキストの左側にある [+] ボタンをクリックして、新しいレイヤを追加します。
出力層の前に配置されます。
- 新しい非表示レイヤの上にある [+] ボタンを 2 回クリックして、ノードをさらに 2 つ追加します。
渡します。
上記の回答は正しかったですか?
こちらをクリックして説明をご覧ください
出力ノードのみが変更されます。このニューラル ネットワークの推論は、
「フィードフォワード」(開始から終了までの計算の進行状況)、加算
新しいレイヤがネットワークに追加されると、その新しいレイヤが
レイヤのみを認識します。
タスク 3
ネットワークの最初の隠れ層にある 2 番目のノードを(上から)クリックします。
表示されます。ネットワーク構成を変更する前に、
質問です。
Deployment の
重み w12(最初の入力ノード x1 の下に表示)
クラスタ内のノードが計算に影響を与える可能性がある
?
なし
あなたは何も選択していません
。以下の手順に沿ってニューラル ネットワークを更新し、
確認します。
2 番目のノードは、
隠れ層、2 番目の隠れ層のすべてのノード、
出力ノードを指定します。
あなたは 2 つ目を選択しました。
隠れ層のすべてのノード、第 2 隠れ層のすべてのノード、
出力ノードを指定します。手順は次のとおりです。
ニューラル ネットワークを更新し、問題ないか確認します。
クラスタ内のすべてのノードは、
第 1 隠れ層、第 2 隠れ層、出力層です。
ここでは、
隠れ層のノード、第 2 隠れ層のノード、
出力層。手順は次のとおりです。
ニューラル ネットワークを更新し、問題ないか確認します。
次に、重み w12 のテキスト フィールド(
最初の入力ノード x1)を指定し、値を 5.00
に変更して Enter キーを押します。
グラフの更新を確認します。
答えは正しかったですか?答えを確認するときは注意が必要です。たとえば、ノードに
変化しないということは、基になる計算は変化していないということですか?
こちらをクリックして説明をご覧ください
最初の隠れ層で影響を受ける唯一のノードは 2 番目のノード(
クリックされたもの)が表示されます。最初のノードの他のノードの値の計算は、
隠れ層はパラメータとして w12 を含まないため、
表示されます。第 2 隠れ層のすべてのノードは影響を受けます。
計算は、最初の列にある 2 番目のノードの値に
隠されています。同様に、出力ノードの値も影響を受けます。これは、
計算は、第 2 隠れ層のノードの値に依存します。
答えは「なし」だと思ったかクラスタ内のノード値は
重み値を変更したときにネットワークが変化したでしょうか。なお、基盤となる
ノードの計算は、ノードの値を変更せずに変更される場合があります。
(例:ReLU(0) と ReLU(–5) はどちらも出力 0 になります。
ネットワークへの影響について
ノードの値を確認します。計算結果も確認するようにしてください。
演習 2
[特徴クロス演習]
カテゴリデータ モジュールでは、
非線形データを適合させるための特徴クロスを手動で構築しました。
ここで、モデルによって学習内容を自動的に学習するニューラル ネットワークを
トレーニング中に非線形データを適合させる方法を
見てきました
タスク: ニューラル ネットワークを構成して、オレンジ色の点と
損失は 0.2 未満に抑えられており、
トレーニングデータとテストデータです
Instructions:
以下のインタラクティブ ウィジェットの内容:
- ニューラル ネットワークのハイパーパラメータを、いくつかのテスト
次のように構成します。
<ph type="x-smartling-placeholder">
</ph>
- 非表示のレイヤを追加または削除するには、[+] ボタンと [-] ボタンをクリックします。
隠れ層の見出しの左側に配置されます。
- [+] と [-] をクリックして、隠れ層のニューロンを追加または削除する
非表示のレイヤの列の上にボタンを追加します。
- [学習率] から新しい値を選択して、学習率を変更します。
プルダウンを使ってみましょう。
- 活性化関数を変更するには
図の上にある [有効化] プルダウン。
- 図の上にある再生ボタン(▶️)をクリックして、ニューラル ネットワークをトレーニングします。
モデルを作成します。
- トレーニング データとして適合するモデルの可視化を観察する
進捗を確認できます。
損失のテストと
次のトレーニング損失値:
[Output] セクションに表示されます。
- モデルのテストデータとトレーニング データの損失が 0.2 を下回らない場合は、
[Reset] をクリックし、別の設定セットで手順 1 ~ 3 を繰り返します。
設定。望ましい結果が得られるまでこの手順を繰り返します。
ソリューションについては、こちらをクリックしてください
次の方法で、テストとトレーニングの両方の損失を 0.2 未満に抑えることができました。
- 3 つのニューロンを含む隠れ層を 1 つ追加しています。
- 学習率には 0.01 を選びます。
- ReLU の活性化関数を選択する。
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2024-08-16 UTC。
[null,null,["最終更新日 2024-08-16 UTC。"],[],[],null,["# Neural networks: Interactive exercises\n\nIn the interactive exercises below, you'll further explore the inner workings of\nneural networks. First, you'll see how parameter and hyperparameter changes\naffect the network's predictions. Then you'll use what you've learned to train a\nneural network to fit nonlinear data.\n\nExercise 1\n----------\n\nThe following widget sets up a neural network with the following configuration:\n\n- Input layer with 3 neurons containing the values `0.00`, `0.00`, and `0.00`\n- Hidden layer with 4 neurons\n- Output layer with 1 neuron\n- [**ReLU**](/machine-learning/glossary#ReLU) activation function applied to all hidden layer nodes and the output node\n\nReview the initial setup of the network (note: **do not** click the **▶️** or\n**\\\u003e\\|** buttons yet), and then complete the tasks below the widget.\n\n### Task 1\n\nThe values for the three input features to the neural network model are all\n`0.00`. Click each of the nodes in the network to see all the initialized\nvalues. Before hitting the Play (**▶️**) button, answer this question: \nWhat kind of output value do you think will be produced: positive, negative, or 0? \nPositive output value \nYou chose **positive\noutput value**. Follow the instructions below to perform inference on the input data and see if you're right. \nNegative output value \nYou chose **negative\noutput value**. Follow the instructions below to perform inference on the input data and see if you're right. \nOutput value of 0 \nYou chose **output\nvalue of 0**. Follow the instructions below to perform inference on the input data and see if you're right.\n\nNow click the Play (▶️) button above the network, and watch all the hidden-layer\nand output node values populate. Was your answer above correct? \n**Click here for an explanation**\n\nThe exact output value you get will vary based on how the weight\nand bias parameters are randomly initialized. However, since each neuron\nin the input layer has a value of 0, the weights used to calculate the\nhidden-layer node values will all be zeroed out. For example, the first\nhidden layer node calculation will be:\n\ny = ReLU(w~11~\\* 0.00 + w~21~\\* 0.00 + w~31~\\* 0.00 + b)\n\ny = ReLU(b)\n\nSo each hidden-layer node's value will be equal to the ReLU value of the\nbias (b), which will be 0 if b is negative and b itself if b is 0 or\npositive.\n\nThe value of the output node will then be calculated as follows:\n\ny = ReLU(w~11~\\* x~11~ + w~21~\\* x~21~\n+ w~31~\\* x~31~ + w~41~\\* x~41~ + b)\n\n### Task 2\n\nBefore modifying the neural network, answer the following question: \nIf you add another hidden layer to the neural network after the first hidden layer, and give this new layer 3 nodes, keeping all input and weight/bias parameters the same, which other nodes' calculations will be affected? \nAll the nodes in the network, except the input nodes \nYou chose **all the\nnodes in the network, except the input nodes**. Follow the instructions below to update the neural network and see if you're correct. \nJust the nodes in the first hidden layer \nYou chose **just the\nnodes in the first hidden layer**. Follow the instructions below to update the neural network and see if you're correct. \nJust the output node \nYou chose **just the\noutput node**. Follow the instructions below to update the neural network and see if you're correct.\n\nNow modify the neural network to add a new hidden layer with 3 nodes as follows:\n\n1. Click the **+** button to the left of the text **1 hidden layer** to add a new hidden layer before the output layer.\n2. Click the **+** button above the new hidden layer twice to add 2 more nodes to the layer.\n\nWas your answer above correct? \n**Click here for an explanation**\n\nOnly the output node changes. Because inference for this neural network\nis \"feed-forward\" (calculations progress from start to finish), the addition\nof a new layer to the network will only affect nodes *after* the new\nlayer, not those that precede it.\n\n### Task 3\n\nClick the second node (from the top) in the first hidden layer of the network\ngraph. Before making any changes to the network configuration, answer the\nfollowing question: \nIf you change the value of the weight w~12~ (displayed below the first input node, x~1~), which other nodes' calculations *could* be affected for some input values? \nNone \nYou chose **none**. Follow the instructions below to update the neural network and see if you're correct. \nThe second node in the first hidden layer, all the nodes in the second hidden layer, and the output node. \nYou chose **the second\nnode in the first hidden layer, all the nodes in the second hidden layer,\nand the output node**. Follow the instructions below to update the neural network and see if you're correct. \nAll the nodes in the first hidden layer, the second hidden layer, and the output layer. \nYou chose **all the\nnodes in the first hidden layer, the second hidden layer, and the\noutput layer**. Follow the instructions below to update the neural network and see if you're correct.\n\nNow, click in the text field for the weight w~12~ (displayed below the\nfirst input node, x~1~), change its value to `5.00`, and hit Enter.\nObserve the updates to the graph.\n\nWas your answer correct? Be careful when verifying your answer: if a node\nvalue doesn't change, does that mean the underlying calculation didn't change? \n**Click here for an explanation**\n\nThe only node affected in the first hidden layer is the second node (the\none you clicked). The value calculations for the other nodes in the first\nhidden layer do not contain w~12~ as a parameter, so they are not\naffected. All the nodes in the second hidden layer are affected, as their\ncalculations depend on the value of the second node in the first\nhidden layer. Similarly, the output node value is affected because its\ncalculations depend on the values of the nodes in the second hidden layer.\n\nDid you think the answer was \"none\" because none of the node values in the\nnetwork changed when you changed the weight value? Note that an underlying\ncalculation for a node may change without changing the node's value\n(e.g., ReLU(0) and ReLU(--5) both produce an output of 0).\nDon't make assumptions about how the network was affected just by\nlooking at the node values; make sure to review the calculations as well.\n\nExercise 2\n----------\n\nIn the [Feature cross exercises](/machine-learning/crash-course/categorical-data/feature-cross-exercises)\nin the [Categorical data module](/machine-learning/crash-course/categorical-data),\nyou manually constructed feature crosses to fit nonlinear data.\nNow, you'll see if you can build a neural network that can automatically learn\nhow to fit nonlinear data during training.\n\n**Your task:** configure a neural network that can separate the orange dots from\nthe blue dots in the diagram below, achieving a loss of less than 0.2 on both\nthe training and test data.\n\n**Instructions:**\n\nIn the interactive widget below:\n\n1. Modify the neural network hyperparameters by experimenting with some of the following config settings:\n - Add or remove hidden layers by clicking the **+** and **-** buttons to the left of the **HIDDEN LAYERS** heading in the network diagram.\n - Add or remove neurons from a hidden layer by clicking the **+** and **-** buttons above a hidden-layer column.\n - Change the learning rate by choosing a new value from the **Learning rate** drop-down above the diagram.\n - Change the activation function by choosing a new value from the **Activation** drop-down above the diagram.\n2. Click the Play (▶️) button above the diagram to train the neural network model using the specified parameters.\n3. Observe the visualization of the model fitting the data as training progresses, as well as the [**Test loss**](/machine-learning/glossary#test-loss) and [**Training loss**](/machine-learning/glossary#training-loss) values in the **Output** section.\n4. If the model does not achieve loss below 0.2 on the test and training data, click reset, and repeat steps 1--3 with a different set of configuration settings. Repeat this process until you achieve the preferred results.\n\n**Click here for our solution**\n\nWe were able to achieve both test and training loss below 0.2 by:\n\n- Adding 1 hidden layer containing 3 neurons.\n- Choosing a learning rate of 0.01.\n- Choosing an activation function of ReLU. \n| **Key terms:**\n|\n| - [Test loss](/machine-learning/glossary#test-loss)\n- [Training loss](/machine-learning/glossary#training-loss) \n[Help Center](https://support.google.com/machinelearningeducation)"]]