Class/Object

com.intel.analytics.bigdl.nn

ClassNLLCriterion

Related Docs: object ClassNLLCriterion | package nn

Permalink

class ClassNLLCriterion[T] extends TensorCriterion[T]

The negative log likelihood criterion. It is useful to train a classification problem with n classes. If provided, the optional argument weights should be a 1D Tensor assigning weight to each of the classes. This is particularly useful when you have an unbalanced training set.

The input given through a forward() is expected to contain log-probabilities/probabilities of each class: input has to be a 1D Tensor of size n. Obtaining log-probabilities/probabilities in a neural network is easily achieved by adding a LogSoftMax/SoftMax layer in the last layer of your neural network. You may use CrossEntropyCriterion instead, if you prefer not to add an extra layer to your network. This criterion expects a class index (1 to the number of class) as target when calling forward(input, target) and backward(input, target).

In the log-probabilities case, The loss can be described as: loss(x, class) = -x[class] or in the case of the weights argument it is specified as follows: loss(x, class) = -weights[class] * x[class]

Due to the behaviour of the backend code, it is necessary to set sizeAverage to false when calculating losses in non-batch mode.

Note that if the target is paddingValue, the training process will skip this sample. In other words, the forward process will return zero output and the backward process will also return zero gradInput.

By default, the losses are averaged over observations for each minibatch. However, if the field sizeAverage is set to false, the losses are instead summed for each minibatch.

In particular, when weights=None, size_average=True and logProbAsInput=False, this is same as sparse_categorical_crossentropy loss in keras.

T

numeric type

Annotations
@SerialVersionUID()
Linear Supertypes
TensorCriterion[T], AbstractCriterion[Tensor[T], Tensor[T], T], Serializable, Serializable, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. ClassNLLCriterion
  2. TensorCriterion
  3. AbstractCriterion
  4. Serializable
  5. Serializable
  6. AnyRef
  7. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new ClassNLLCriterion(weights: Tensor[T] = null, sizeAverage: Boolean = true, logProbAsInput: Boolean = true, paddingValue: Int = 1)(implicit arg0: ClassTag[T], ev: TensorNumeric[T])

    Permalink

    weights

    weights of each element of the input

    sizeAverage

    size average of batch

    logProbAsInput

    indicating whether to accept log-probabilities or probabilities as input. True means accepting log-probabilities as input.

    ev

    numeric operator

Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  5. def backward(input: Tensor[T], target: Tensor[T]): Tensor[T]

    Permalink

    Performs a back-propagation step through the criterion, with respect to the given input.

    Performs a back-propagation step through the criterion, with respect to the given input.

    input

    input data

    target

    target

    returns

    gradient corresponding to input data

    Definition Classes
    AbstractCriterion
  6. def canEqual(other: Any): Boolean

    Permalink
    Definition Classes
    AbstractCriterion
  7. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  8. def cloneCriterion(): AbstractCriterion[Tensor[T], Tensor[T], T]

    Permalink

    Deep copy this criterion

    Deep copy this criterion

    returns

    a deep copied criterion

    Definition Classes
    AbstractCriterion
  9. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  10. def equals(other: Any): Boolean

    Permalink
    Definition Classes
    AbstractCriterion → AnyRef → Any
  11. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  12. def forward(input: Tensor[T], target: Tensor[T]): T

    Permalink

    Takes an input object, and computes the corresponding loss of the criterion, compared with target.

    Takes an input object, and computes the corresponding loss of the criterion, compared with target.

    input

    input data

    target

    target

    returns

    the loss of criterion

    Definition Classes
    AbstractCriterion
  13. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  14. var gradInput: Tensor[T]

    Permalink
    Definition Classes
    AbstractCriterion
  15. def hashCode(): Int

    Permalink
    Definition Classes
    AbstractCriterion → AnyRef → Any
  16. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  17. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  18. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  19. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  20. var output: T

    Permalink
    Definition Classes
    AbstractCriterion
  21. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  22. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  23. def updateGradInput(input: Tensor[T], target: Tensor[T]): Tensor[T]

    Permalink

    Computing the gradient of the criterion with respect to its own input.

    Computing the gradient of the criterion with respect to its own input. This is returned in gradInput. Also, the gradInput state variable is updated accordingly.

    input

    input data

    target

    target data / labels

    returns

    gradient of input

    Definition Classes
    ClassNLLCriterionAbstractCriterion
  24. def updateOutput(input: Tensor[T], target: Tensor[T]): T

    Permalink

    Computes the loss using input and objective function.

    Computes the loss using input and objective function. This function returns the result which is stored in the output field.

    input

    input of the criterion

    target

    target or labels

    returns

    the loss of the criterion

    Definition Classes
    ClassNLLCriterionAbstractCriterion
  25. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  26. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  27. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from TensorCriterion[T]

Inherited from AbstractCriterion[Tensor[T], Tensor[T], T]

Inherited from Serializable

Inherited from Serializable

Inherited from AnyRef

Inherited from Any

Ungrouped