mappings#
- tensordict.nn.mappings(key: str) Callable#
Returns the function named by
key, which maps a tensor elementwise, for example to positive values.Modules such as
NormalParamExtractoruse it to turn the output of a network into a scale. All the functions except"none"(the identity) map real numbers to non-negative numbers."relu"can return 0, the others return positive numbers.- Parameters:
key (str) – one of
"softplus","exp","relu","expln"(seeexpln()),"biased_softplus"(abiased_softpluswithbias=1.0),"none", or a name added withadd_custom_mapping()."biased_softplus_{bias}"and"biased_softplus_{bias}_{min_val}"return abiased_softpluswith these arguments, for example"biased_softplus_2.0_0.1".- Returns:
A callable that takes a tensor and returns a tensor.
- Raises:
NotImplementedError – if
keyis not a known name.ValueError – if a
"biased_softplus_..."key does not have the form"biased_softplus_{bias}"or"biased_softplus_{bias}_{min_val}".
Examples
>>> import torch >>> from tensordict.nn import mappings >>> mappings("exp")(torch.zeros(2)) tensor([1., 1.]) >>> mappings("biased_softplus_2.0_0.1")(torch.zeros(2)) tensor([2., 2.])