天天看点

Softmax交叉熵损失函数反向传播模型交叉熵损失函数及softmax计算误差Python代码

文章目录

  • 模型
  • 交叉熵损失函数及softmax
  • 计算误差
  • Python代码

模型

Softmax交叉熵损失函数反向传播模型交叉熵损失函数及softmax计算误差Python代码

前面得到的Z,然后经过softmax得到输出a,然后根据groud truth y计算损失函数。

交叉熵损失函数及softmax

Softmax交叉熵损失函数反向传播模型交叉熵损失函数及softmax计算误差Python代码

计算误差

Softmax交叉熵损失函数反向传播模型交叉熵损失函数及softmax计算误差Python代码
Softmax交叉熵损失函数反向传播模型交叉熵损失函数及softmax计算误差Python代码
Softmax交叉熵损失函数反向传播模型交叉熵损失函数及softmax计算误差Python代码
Softmax交叉熵损失函数反向传播模型交叉熵损失函数及softmax计算误差Python代码

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实现

继续阅读