SparseSoftmaxCrossEntropyWithLogits

public class SparseSoftmaxCrossEntropyWithLogits

Public Constructors

Public Methods

static <T extends TNumber , U extends TNumber > Operand
sparseSoftmaxCrossEntropyWithLogits ( Scope scope, Operand <T> labels, Operand <U> logits)
Computes sparse softmax cross entropy between logits and labels .

Inherited Methods

Public Constructors

public SparseSoftmaxCrossEntropyWithLogits ()

Public Methods

public static Operand sparseSoftmaxCrossEntropyWithLogits ( Scope scope, Operand <T> labels, Operand <U> logits)

Computes sparse softmax cross entropy between logits and labels .

Measures the probability error in discrete classification tasks in which the classes are mutually exclusive (each entry is in exactly one class). For example, each CIFAR-10 image is labeled with one and only one label: an image can be a dog or a truck, but not both.

NOTE:

For this operation, the probability of a given label is considered exclusive. That is, soft classes are not allowed, and the labels vector must provide a single specific index for the true class for each row of logits (each minibatch entry). For soft softmax classification with a probability distribution for each entry, ERROR(/org.tensorflow.op.NnOps#softmaxCrossEntropyWithLogits) .

WARNING:

This op expects unscaled logits, since it performs a softmax on logits internally for efficiency. Do not call this op with the output of softmax , as it will produce incorrect results.

A common use case is to have logits of shape [batchSize, numClasses] and have labels of shape [batchSize] , but higher dimensions are supported, in which case the dim -th dimension is assumed to be of size numClasses . logits must have the dataType of TFloat16 , TFloat32 , or TFloat64 , and labels must have the dtype of TInt32 or TInt64 .

Parameters
scope current scope
labels Tensor of shape [d_0, d_1, ..., d_{r-1}] (where r is rank of labels and result) and the dataType is TInt32 or TInt64 . Each entry in labels must be an index in [0, numClasses) . Other values will raise an exception when this op is run on CPU, and return NaN for corresponding loss and gradient rows on GPU.
logits Per-label activations (typically a linear output) of shape [d_0, d_1, ..., d_{r-1}, numClasses] and dataType of TFloat16 , TFloat32 , or TFloat64 . These activation energies are interpreted as unnormalized log probabilities.
Returns
  • A Tensor of the same shape as labels and of the same type as logits with the softmax cross entropy loss.
Throws
IllegalArgumentException If logits are scalars (need to have rank >= 1) or if the rank of the labels is not equal to the rank of the logits minus one.