Class: Tensorflow::Keras::Losses::SparseCategoricalCrossentropy

Inherits:
Object
  • Object
show all
Defined in:
lib/tensorflow/keras/losses/sparse_categorical_crossentropy.rb

Instance Method Summary collapse

Instance Method Details

#call(target, output) ⇒ Object



5
6
7
8
9
10
# File 'lib/tensorflow/keras/losses/sparse_categorical_crossentropy.rb', line 5

def call(target, output)
  output = Math.log(output)
  target = Tensorflow.cast(target, :int64)
  cost, _ = RawOps.sparse_softmax_cross_entropy_with_logits(features: output, labels: target)
  Math.reduce_sum(cost) / Tensorflow.cast(RawOps.size(input: cost), :float)
end