循环神经网络#
- class pytorch_forecasting.models.nn.rnn.RNN(mode: str, input_size: int, hidden_size: int, num_layers: int = 1, bias: bool = True, batch_first: bool = False, dropout: float = 0.0, bidirectional: bool = False, proj_size: int = 0, device=None, dtype=None)[来源]#
基础:
ABC,RNNBase基础类灵活的RNNs。
前向函数可以处理长度为0的序列。
方法
forward(x[, hx, lengths, enforce_sorted])允许零长度序列的rnn的前向函数。
handle_no_encoding(hidden_state, ...)在没有编码的地方屏蔽隐藏状态。
初始化一个 hidden_state。
repeat_interleave(hidden_state, n_samples)将hidden_state复制n_samples次。
- forward(x: PackedSequence | Tensor, hx: Tuple[Tensor, Tensor] | Tensor = None, lengths: LongTensor = None, enforce_sorted: bool = True) Tuple[PackedSequence | Tensor, Tuple[Tensor, Tensor] | Tensor][来源]#
允许零长度序列的rnn的前向函数。
对于RNN,函数正常。仅当定义了长度时才会改变输出。
- Parameters:
x (Union[rnn.PackedSequence, torch.Tensor]) – 输入到 RNN。可以是打包序列或填充序列的张量
hx (隐藏状态, 可选) – 隐藏状态。默认为 None。
lengths (torch.LongTensor, 可选) – 序列的长度。如果不是 None,用于确定正确返回的隐状态。可以包含零。默认为 None。
enforce_sorted (bool, 可选) – 如果传递了长度,确定RNN是否期望它们已排序。默认值为True。
- Returns:
- 输出和隐藏状态。
如果输入是一个打包序列,则输出是打包序列。
- Return type:
元组[联合[rnn.PackedSequence, torch.Tensor], 隐藏状态]
- abstract handle_no_encoding(hidden_state: Tuple[Tensor, Tensor] | Tensor, no_encoding: BoolTensor, initial_hidden_state: Tuple[Tensor, Tensor] | Tensor) Tuple[Tensor, Tensor] | Tensor[来源]#
在没有编码的地方屏蔽隐藏状态。
- Parameters:
hidden_state (HiddenState) – 需要替换某些条目的隐藏状态
no_encoding (torch.BoolTensor) – 需要替换的位置
initial_hidden_state (HiddenState) – 用于替换的隐状态
- Returns:
适当情况下传播初始隐藏状态的隐藏状态
- Return type:
隐藏状态
初始化一个 hidden_state。
- Parameters:
x (torch.Tensor) – 网络输入
- Returns:
默认(零类)隐藏状态
- Return type:
隐藏状态