天天看點

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實作

繼續閱讀