Class: DNN::Losses::SoftmaxCrossEntropy

Inherits:
Loss
  • Object
show all
Defined in:
lib/dnn/core/losses.rb

Instance Method Summary collapse

Methods inherited from Loss

#d_regularize, #regularize, #to_hash

Instance Method Details

#backward(y) ⇒ Object



98
99
100
# File 'lib/dnn/core/losses.rb', line 98

def backward(y)
  @out - y
end

#forward(x, y) ⇒ Object



92
93
94
95
96
# File 'lib/dnn/core/losses.rb', line 92

def forward(x, y)
  @out = Utils.softmax(x)
  batch_size = y.shape[0]
  -(y * NMath.log(@out + 1e-7)).sum / batch_size
end