TensorDictBase.softmax#
- TensorDictBase.softmax(dim: int, dtype: dtype | None = None)#
Returns a new tensordict with
torch.softmax()applied to every leaf along a batch dimension.A
LazyStackedTensorDict, also a nested one, gives a lazy stack with the values of its dense copy. The exception is a softmax along the stack dim of members whose entries have different shapes, which have no dense copy: each leaf of each member is normalised along its own dimdim.- Parameters:
Examples
>>> import torch >>> from tensordict import TensorDict >>> td = TensorDict(x=torch.zeros(2, 3), batch_size=[2]) >>> td.softmax(0)["x"] tensor([[0.5000, 0.5000, 0.5000], [0.5000, 0.5000, 0.5000]])
Every tensordict class and every tensorclass has this method. For the other methods, see Methods by task.