Implementing kernel
C++ engine symbols that back this Python API.Log-Softmax activation function.
Applies element-wise:
Combines the softmax normalisation with a logarithm in a single,
numerically stable pass. The output lives in and
is intended to be paired with lucid.nn.NLLLoss for
multi-class classification, or equivalently used directly with
lucid.nn.functional.cross_entropy.
Parameters
dimint or None= NoneThe dimension along which log-softmax is computed. Must be specified
explicitly for most use cases. Default:
None.Notes
- Input: — any shape.
- Output: — same shape as input; values along
dimare non-positive and represent log-probabilities.
Examples
>>> import lucid
>>> import lucid.nn as nn
>>> m = nn.LogSoftmax(dim=-1)
>>> x = lucid.tensor([[1.0, 2.0, 3.0]])
>>> m(x)
tensor([[-2.4076, -1.4076, -0.4076]])
>>> # Classifier output layer — pair with NLLLoss
>>> logits = lucid.randn(32, 10)
>>> log_probs = nn.LogSoftmax(dim=-1)(logits)
>>> log_probs.shape
(32, 10)