快捷方式

tensordict.nn.distributions.NormalParamExtractor

class tensordict.nn.distributions.NormalParamExtractor(scale_mapping: str = 'biased_softplus_1.0', scale_lb: Number = 0.0001)

一个非参数化的 nn.Module,它将输入拆分为均值和标准差参数。

使用指定的 scale_mapping 将标准差参数映射到正值。

参数:
  • scale_mapping (str, optional) – 用于标准差的正向映射函数。默认值 = "biased_softplus_1.0" (即带有偏差的 softplus 映射,使得 fn(0.0) = 1.0) 可选值: "softplus", "exp", "relu", "biased_softplus_1""none" (无映射)。更多详情请参见 mappings()

  • scale_lb (Number, optional) – 方差可以取到的最小值。默认值为 1e-4。

示例

>>> import torch
>>> from tensordict.nn.distributions import NormalParamExtractor
>>> from torch import nn
>>> module = nn.Linear(3, 4)
>>> normal_params = NormalParamExtractor()
>>> tensor = torch.randn(3)
>>> loc, scale = normal_params(module(tensor))
>>> print(loc.shape, scale.shape)
torch.Size([2]) torch.Size([2])
>>> assert (scale > 0).all()
>>> # with modules that return more than one tensor
>>> module = nn.LSTM(3, 4)
>>> tensor = torch.randn(4, 2, 3)
>>> loc, scale, others = normal_params(*module(tensor))
>>> print(loc.shape, scale.shape)
torch.Size([4, 2, 2]) torch.Size([4, 2, 2])
>>> assert (scale > 0).all()

文档

访问全面的 PyTorch 开发者文档

查看文档

教程

为初学者和高级开发者提供深入的教程

查看教程

资源

查找开发资源并让您的问题得到解答

查看资源