文章目录
- 模型
- 交叉熵损失函数及softmax
- 计算误差
- Python代码
模型

前面得到的Z,然后经过softmax得到输出a,然后根据groud truth y计算损失函数。
交叉熵损失函数及softmax
计算误差
Python代码
def delta_cross_entropy(X, y):
'''
X: (num_examples * num_classes) output of fc layer
y: (num_examples * 1) labels
'''
m = y.shape[0]
a = softmax(X)
a[range(m), y] -= 1
delta = a / m
retrun delta
参考:
The Softmax function and its derivative
Softmax和交叉熵的深度解析和Python实现