# oneflow.nn.LogSoftmax¶

class oneflow.nn.LogSoftmax(dim: Optional[int] = None)

Applies the LogSoftmax function to an n-dimensional input Tensor. The LogSoftmax formulation can be simplified as:

$\text{LogSoftmax}(x_{i}) = \log\left(\frac{\exp(x_i) }{ \sum_j \exp(x_j)} \right) = x_i - \log({ \sum_j \exp(x_j)})$
Parameters

dim (int) – A dimension along which LogSoftmax will be computed.

Shape:
• Input: $$(N, *)$$ where * means, any number of additional dimensions

• Output: $$(N, *)$$, same shape as the input

For example:

>>> import numpy as np
>>> import oneflow as flow

>>> m = flow.nn.LogSoftmax(dim=1)
>>> x = flow.Tensor(
...    np.array(
...        [[ 0.4296, -1.1957,  2.5463],
...        [ 1.2552, -1.5747,  0.6923]]
...    )
... )
>>> out = m(x)
>>> out
tensor([[-2.2513, -3.8766, -0.1346],
[-0.4877, -3.3176, -1.0506]], dtype=oneflow.float32)

__init__(dim: Optional[int] = None)

Initialize self. See help(type(self)) for accurate signature.

Methods

 __call__(*args, **kwargs) Call self as a function. __delattr__(name, /) Implement delattr(self, name). __dir__() Default dir() implementation. __eq__(value, /) Return self==value. __format__(format_spec, /) Default object formatter. __ge__(value, /) Return self>=value. __getattr__(name) __getattribute__(name, /) Return getattr(self, name). __gt__(value, /) Return self>value. __hash__() Return hash(self). __init__([dim]) Initialize self. __init_subclass__ This method is called when a class is subclassed. __le__(value, /) Return self<=value. __lt__(value, /) Return self