Class: DNN::Losses::SoftmaxCrossEntropy

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Loss

#backward, #forward

Constructor Details

#initialize(eps: 1e-7) ⇒ SoftmaxCrossEntropy

Returns a new instance of SoftmaxCrossEntropy.

Parameters:

  • eps (Float) (defaults to: 1e-7) —

    Value to avoid nan.



122
123
124
# File 'lib/dnn/core/losses.rb', line 122

def initialize(eps: 1e-7)
  @eps = eps
end

Instance Attribute Details

#eps ⇒ Float

Return the eps value.

Returns:

  • (Float) —

    Return the eps value.



111
112
113
# File 'lib/dnn/core/losses.rb', line 111

def eps
  @eps
end

Class Method Details

.from_hash(hash) ⇒ Object



113
114
115
# File 'lib/dnn/core/losses.rb', line 113

def self.from_hash(hash)
  SoftmaxCrossEntropy.new(eps: hash[:eps])
end

.softmax(x) ⇒ Object



117
118
119
# File 'lib/dnn/core/losses.rb', line 117

def self.softmax(x)
  NMath.exp(x) / NMath.exp(x).sum(1).reshape(x.shape[0], 1)
end

Instance Method Details

#to_hash ⇒ Object



126
127
128
# File 'lib/dnn/core/losses.rb', line 126

def to_hash
  super(eps: @eps)
end