In the interactive exercises below, you'll further explore the inner workings of neural networks. First, you'll see how parameter and hyperparameter changes affect the network's predictions. Then you'll use what you've learned to train a neural network to fit nonlinear data.
练习1
以下组件使用以下配置设置神经网络:
- 输入层包含 3 个神经元
0.00其值分别为0.00和0.00 - 隐藏层包含4个神经元
- 输出层(1个神经元)
- ReLU激活函数应用于所有隐藏层节点和输出节点
查看网络的初始设置(注意:暂时不要点击▶️或>|按钮),然后完成小部件下面的任务。
任务1
The values for the three input features to the neural network model are all 0.00 . Click each of the nodes in the network to see all the initialized values. Before hitting the Play ( ▶️ ) button, answer this question:
你认为会产生什么样的产出值:正值、负值还是 0?
正输出值
您选择了正的输出值。请按照以下说明对输入数据进行推理,看看您的选择是否正确。
负输出值
你选择了负的输出值。请按照以下说明对输入数据进行推理,看看你的判断是否正确。
输出值为 0
您选择的输出值为 0。请按照以下说明对输入数据进行推理,看看您的选择是否正确。
现在点击网络图上方的播放(▶️)按钮,观察所有隐藏层节点和输出节点的值如何变化。你上面的答案正确吗?
点击此处查看说明
The exact output value you get will vary based on how the weight and bias parameters are randomly initialized. However, since each neuron in the input layer has a value of 0, the weights used to calculate the hidden-layer node values will all be zeroed out. For example, the first hidden layer node calculation will be:
y = ReLU(w 11 * 0.00 + w 21 * 0.00 + w 31 * 0.00 + b)
y = ReLU(b)
因此,每个隐藏层节点的值将等于偏置项 (b) 的 ReLU 值,如果 b 为负,则该值为 0;如果 b 为 0 或正,则该值为 b 本身。
然后,输出节点的值将按如下方式计算:
y = ReLU(w 11 * x 11 + w 21 * x 21 + w 31 * x 31 + w 41 * x 41 + b)
任务 2
在修改神经网络之前,请回答以下问题:
If 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?
网络中除输入节点外的所有节点
您选择了网络中除输入节点之外的所有节点。请按照以下说明更新神经网络,看看您的选择是否正确。
仅第一隐藏层中的节点
您只选择了第一个隐藏层中的节点。请按照以下说明更新神经网络,看看是否正确。
仅输出节点
您只选择了输出节点。请按照以下说明更新神经网络,看看是否正确。
现在修改神经网络,添加一个包含 3 个节点的新隐藏层,如下所示:
- 单击文本“1 个隐藏图层”左侧的“ +”按钮,在输出图层之前添加一个新的隐藏图层。
- 单击新隐藏图层上方的“+”按钮两次,即可向该图层添加 2 个节点。
你上面的回答正确吗?
点击此处查看说明
Only the output node changes. Because inference for this neural network is "feed-forward" (calculations progress from start to finish), the addition of a new layer to the network will only affect nodes after the new layer, not those that precede it.
任务3
单击网络图第一层隐藏区域中从上往下数的第二个节点。在对网络配置进行任何更改之前,请回答以下问题:
如果更改权重 w 12 (显示在第一个输入节点 x 1下方)的值,对于某些输入值,哪些其他节点的计算可能会受到影响?
没有任何
您选择了“无” 。请按照以下说明更新神经网络,看看您的选择是否正确。
第一隐藏层中的第二个节点、第二隐藏层中的所有节点以及输出节点。
You chose the second node in the first hidden layer, all the nodes in the second hidden layer, and the output node . Follow the instructions below to update the neural network and see if you're correct.
第一隐藏层、第二隐藏层和输出层中的所有节点。
您选择了第一隐藏层、第二隐藏层和输出层中的所有节点。请按照以下说明更新神经网络,看看您的选择是否正确。
现在,点击权重 w 12的文本框(显示在第一个输入节点 x 1下方),将其值更改为5.00 ,然后按 Enter 键。观察图表的更新。
你的答案正确吗?验证答案时要小心:如果节点值没有改变,是否意味着底层计算也没有改变?
点击此处查看说明
在第一层隐藏层中,唯一受影响的节点是第二个节点(您点击的那个)。第一层隐藏层中其他节点的值计算不包含w12作为参数,因此它们不受影响。第二层隐藏层中的所有节点都会受到影响,因为它们的计算依赖于第一层隐藏层中第二个节点的值。同样,输出节点的值也会受到影响,因为它的计算依赖于第二层隐藏层中节点的值。
你是不是因为更改权重值时网络中所有节点的值都没有改变,就认为答案是“无”?请注意,节点的底层计算可能会在节点值不变的情况下发生变化(例如,ReLU(0) 和 ReLU(-5) 的输出结果都是 0)。不要仅仅通过观察节点值就对网络受到的影响妄下结论;务必同时检查计算过程。
练习 2
In the Feature cross exercises in the Categorical data module , you manually constructed feature crosses to fit nonlinear data. Now, you'll see if you can build a neural network that can automatically learn how to fit nonlinear data during training.
你的任务:配置一个神经网络,使其能够将下图中的橙色点与蓝色点分开,在训练数据和测试数据上实现小于 0.2 的损失。
指示:
在下面的交互式组件中:
- 通过尝试以下一些配置设置来修改神经网络超参数:
- 在网络图中,单击“隐藏图层”标题左侧的+和-按钮,即可添加或删除隐藏图层。
- 单击隐藏层列上方的+和-按钮,即可向隐藏层添加或删除神经元。
- 通过从图表上方的“学习率”下拉菜单中选择新值来更改学习率。
- 通过从图表上方的“激活”下拉菜单中选择新值来更改激活函数。
- 点击图表上方的播放(▶️)按钮,使用指定的参数训练神经网络模型。
- 观察模型在训练过程中拟合数据的可视化效果,以及输出部分中的测试损失和训练损失值。
- 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.
点击此处查看我们的解决方案
我们通过以下方式成功将测试损失和训练损失都控制在 0.2 以下:
- 添加 1 个包含 3 个神经元的隐藏层。
- 选择学习率为 0.01。
- 选择 ReLU 作为激活函数。