讨论最简单情况:
以神经网络为例:
假设在softmax层,输入的数据是N维的一维数组,输出结果是多分类的各个概率,假设为C类。
--1. input: x --> import data with dimension N, can be writen as , in neural network, means the last hidden layer output.
W, b --> the affine weight with shape:(N, C) and (C, )
y --> the target label of the data, the value of y is in (0, C-1). I will transform y to be an one-hot vector. In the form .
--2: Derivation
定义隐层输出为.
定义损失函数:
求反向传播参数dx, dW:
这里我把它变成求中间变量dz, 然后用dz 推导dx, dW.
So:
where:
改写成:
, one-hot 性质决定了结果中实际只有一个值有效。因此这个形式可以化简成其中
为1的那项。
同理可以求出其他z,然后根据z求出dx, dW.
欢迎讨论!