Class: DNN::Losses::SoftmaxCrossEntropy
- Inherits:
-
Loss
- Object
- Loss
- DNN::Losses::SoftmaxCrossEntropy
show all
- Defined in:
- lib/dnn/core/losses.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Loss
#forward, #regularizes_backward, #to_hash
Class Method Details
.softmax(x) ⇒ Object
103
104
105
|
# File 'lib/dnn/core/losses.rb', line 103
def self.softmax(x)
NMath.exp(x) / NMath.exp(x).sum(1).reshape(x.shape[0], 1)
end
|
Instance Method Details
#backward(y) ⇒ Object
113
114
115
|
# File 'lib/dnn/core/losses.rb', line 113
def backward(y)
@out - y
end
|
#loss(x, y) ⇒ Object
107
108
109
110
111
|
# File 'lib/dnn/core/losses.rb', line 107
def loss(x, y)
@out = SoftmaxCrossEntropy.softmax(x)
batch_size = y.shape[0]
-(y * NMath.log(@out + 1e-7)).sum / batch_size
end
|