spikingjelly.activation_based.rnn module#
- spikingjelly.activation_based.rnn.directional_rnn_cell_forward(cell, x, states)[源代码]#
-
中文
沿时间维对单个 RNN cell 执行循环,返回整段输出序列和最终状态。
x的时间维位于第 0 维。该函数会逐个时间步调用cell(x[t], ss), 其中ss是当前状态。若states是二维张量,则cell被视为只有一个 状态张量;若states是三维张量,则其第 0 维表示状态数量,且默认将第 0 个 状态视为当前时间步的输出。- 参数:
- 返回:
(output, final_states),其中output的形状为[T, batch_size, hidden_size],final_states的形状与states相同- 返回类型:
- 抛出:
ValueError -- 若
states.dim()既不是2也不是3,则行为未定义,调用方应保证输入合法
English
Run a single RNN cell along the time dimension and return the full output sequence together with the final state.
The time axis of
xis the first dimension. The function repeatedly evaluatescell(x[t], ss)wheressis the current state. Ifstatesis a 2-D tensor, the cell is treated as having a single state tensor. Ifstatesis a 3-D tensor, its first dimension is interpreted as the number of states, and the first state is treated as the output at each time step.- 参数:
- 返回:
(output, final_states), whereoutputhas shape[T, batch_size, hidden_size]andfinal_stateshas the same shape asstates- 返回类型:
- 抛出:
ValueError -- Callers are expected to provide
stateswith rank 2 or 3
- spikingjelly.activation_based.rnn.bidirectional_rnn_cell_forward(cell, cell_reverse, x, states, states_reverse)[源代码]#
-
中文
沿时间维同时执行正向与反向 RNN cell,返回拼接后的输出序列以及两个方向的最终状态。
对于每个时间步
t,正向 cell 接收x[t],反向 cell 接收x[T - t - 1]。若状态张量为三维,则默认将第 0 个状态视为该时间步输出。- 参数:
cell (nn.Module) -- 正向RNN cell,输入是正向序列
cell_reverse (nn.Module) -- 反向的RNN cell,输入是反向序列
x (Tensor) --
shape = [T, batch_size, input_size]的输入states (Tensor) -- 正向RNN cell的起始状态 若RNN cell只有单个隐藏状态,则
shape = [batch_size, hidden_size]; 否则shape = [states_num, batch_size, hidden_size]states_reverse (Tensor) -- 反向RNN cell的起始状态 若RNN cell只有单个隐藏状态,则
shape = [batch_size, hidden_size]; 否则shape = [states_num, batch_size, hidden_size]
- 返回:
(output, final_states, final_states_reverse)。其中output的形状为[T, batch_size, 2 * hidden_size],由正向与反向输出拼接而成; 其余两个返回值的形状分别与states、states_reverse相同- 返回类型:
English
Run a forward RNN cell and a reverse RNN cell along the time dimension, returning the concatenated output sequence and the final states of both directions.
At each time step
t, the forward cell consumesx[t]and the reverse cell consumesx[T - t - 1]. If the state tensor is 3-D, its first state is treated as the output at that step.- 参数:
cell (nn.Module) -- forward RNN cell that takes the forward sequence as input
cell_reverse (nn.Module) -- reverse RNN cell that takes the reverse sequence as input
x (Tensor) -- input with
shape = [T, batch_size, input_size]states (Tensor) -- initial state of the forward RNN cell. If the RNN cell has a single hidden state,
shape = [batch_size, hidden_size]; otherwiseshape = [states_num, batch_size, hidden_size]states_reverse (Tensor) -- initial state of the reverse RNN cell. If the RNN cell has a single hidden state,
shape = [batch_size, hidden_size]; otherwiseshape = [states_num, batch_size, hidden_size]
- 返回:
(output, final_states, final_states_reverse).outputhas shape[T, batch_size, 2 * hidden_size]and concatenates the forward and reverse outputs. The other two return values have the same shapes asstatesandstates_reverse, respectively- 返回类型:
- class spikingjelly.activation_based.rnn.SpikingRNNCellBase(input_size, hidden_size, bias=True)[源代码]#
基类:
Module
中文
Spiking RNN cell 的基类。
- 参数:
备注
所有权重和偏置项都会按照 \(\mathcal{U}(-\sqrt{k}, \sqrt{k})\) 进行初始化。 其中 \(k = \frac{1}{\text{hidden_size}}\).
English
The base class of Spiking RNN Cell.
- 参数:
Note
All the weights and biases are initialized from \(\mathcal{U}(-\sqrt{k}, \sqrt{k})\) where \(k = \frac{1}{\text{hidden_size}}\).
- class spikingjelly.activation_based.rnn.SpikingRNNBase(input_size, hidden_size, num_layers, bias=True, dropout_p=0, invariant_dropout_mask=False, bidirectional=False, *args, **kwargs)[源代码]#
基类:
Module
中文
多层(可选双向)脉冲 RNN 的基类。
- 参数:
input_size (int) -- 输入
x的特征数hidden_size (int) -- 隐藏状态
h的特征数num_layers (int) -- 内部RNN的层数,例如
num_layers = 2将会创建堆栈式的两层RNN,第1层接收第0层的输出作为输入, 并计算最终输出bias (bool) -- 若为
False, 则内部的隐藏层不会带有偏置项b_ih和b_hh。 默认为Truedropout_p (float) -- 若非
0,则除了最后一层,每个RNN层后会增加一个丢弃概率为dropout_p的Dropout层。 默认为0invariant_dropout_mask (bool) -- 若为
False,则使用普通的Dropout;若为True,则使用SNN中特有的,mask不 随着时间变化的Dropout,参见Dropout。默认为Falsebidirectional (bool) -- 若为
True,则使用双向RNN。默认为Falseargs -- 子类使用的额外参数
kwargs -- 子类使用的额外参数
English
The base-class of a multi-layer spiking RNN.
- 参数:
input_size (int) -- The number of expected features in the input
xhidden_size (int) -- The number of features in the hidden state
hnum_layers (int) -- Number of recurrent layers. E.g., setting
num_layers=2would mean stacking two LSTMs together to form astacked RNN, with the second RNN taking in outputs of the first RNN and computing the final resultsbias (bool) -- If
False, then the layer does not use bias weightsb_ihandb_hh. Default:Truedropout_p (float) -- If non-zero, introduces a
Dropoutlayer on the outputs of each RNN layer except the last layer, with dropout probability equal todropout. Default: 0invariant_dropout_mask (bool) -- If
False,use the naiveDropout;IfTrue,use the dropout in SNN thatmaskdoesn't change in different time steps, seeDropoutfor more information. Default:Falsebidirectional (bool) -- If
True, becomes a bidirectional LSTM. Default:Falseargs -- additional arguments for sub-class
kwargs -- additional arguments for sub-class
- create_cells(*args, **kwargs)[源代码]#
-
中文
- 参数:
args -- 子类使用的额外参数
kwargs -- 子类使用的额外参数
- 返回:
若
self.bidirectional == True则会返回正反两个堆栈式RNN;否则返回单个堆栈式RNN- 返回类型:
nn.Sequential | tuple[nn.Sequential, nn.Sequential]
English
- 参数:
args -- additional arguments for sub-class
kwargs -- additional arguments for sub-class
- 返回:
If
self.bidirectional == True, return a RNN for forward direction and a RNN for reverse direction; else, return a single stacking RNN- 返回类型:
nn.Sequential | tuple[nn.Sequential, nn.Sequential]
- static base_cell()[源代码]#
-
中文
- 返回:
构成该RNN的基本RNN Cell。例如对于
SpikingLSTM, 返回的是SpikingLSTMCell- 返回类型:
nn.Module
English
- 返回:
The base cell of this RNN. E.g., in
SpikingLSTMthis function will returnSpikingLSTMCell- 返回类型:
nn.Module
- static states_num()[源代码]#
-
中文
- 返回:
状态变量的数量。例如对于
SpikingLSTM,由于其输出是h和c, 因此返回2;而对于SpikingGRU,由于其输出是h,因此返回1- 返回类型:
English
- 返回:
The states number. E.g., for
SpikingLSTMthe output arehandc, this function will return2; forSpikingGRUthe output ish, this function will return1- 返回类型:
- forward(x, states=None)[源代码]#
-
中文
执行多层(可选双向)脉冲 RNN 的前向传播。
输入
x的时间维位于第 0 维。若states为None,则会在x.device上自动创建零初始状态。对双向 RNN,状态张量的第 0 维按照[layer_0_forward, ..., layer_{L-1}_forward, layer_0_reverse, ..., layer_{L-1}_reverse]排列;对单向 RNN,则仅包含各层正向状态。- 参数:
x (Tensor) --
shape = [T, batch_size, input_size],输入序列states (Union[Tensor, tuple]) --
self.states_num()为1时是单个tensor, 否则是一个tuple,包含self.states_num()个tensors。 所有的tensor的尺寸均为shape = [num_layers * num_directions, batch, hidden_size], 包含self.states_num()个初始状态 如果RNN是双向的,num_directions为2, 否则为1
- 返回:
(output, output_states)。output的形状为[T, batch, num_directions * hidden_size];output_states在self.states_num() == 1时为单个张量,否则为包含多个状态张量的 tuple- 返回类型:
- 抛出:
TypeError -- 若
states既不是None、torch.Tensor也不是tupleValueError -- 若
states的层数/方向数维度与当前 RNN 配置不匹配
English
Run the forward pass of a stacked spiking RNN, optionally bidirectional.
The time axis of
xis the first dimension. IfstatesisNone, zero initial states are created onx.device. For bidirectional RNNs, the first state dimension is ordered as[layer_0_forward, ..., layer_{L-1}_forward, layer_0_reverse, ..., layer_{L-1}_reverse].- 参数:
x (Tensor) --
shape = [T, batch_size, input_size], tensor containing the features of the input sequencestates (Union[Tensor, tuple]) -- a single tensor when
self.states_num()is1, otherwise a tuple withself.states_num()tensors.shape = [num_layers * num_directions, batch, hidden_size]for all tensors, containing theself.states_num()initial states for each element in the batch. If the RNN is bidirectional,num_directionsshould be2, else it should be1
- 返回:
(output, output_states).outputhas shape[T, batch, num_directions * hidden_size].output_statesis a single tensor whenself.states_num() == 1; otherwise it is a tuple of state tensors- 返回类型:
- 抛出:
TypeError -- If
statesis neitherNone,torch.TensornortupleValueError -- If the layer/direction dimension of
statesdoes not match this RNN configuration
- class spikingjelly.activation_based.rnn.SpikingLSTMCell(input_size, hidden_size, bias=True, surrogate_function1=Erf(alpha=2.0, spiking=True), surrogate_function2=None)[源代码]#
-
中文
脉冲长短时记忆 (LSTM) cell, 最先由 Long Short-Term Memory Spiking Networks and Their Applications 一文提出。
\begin{align*} i &= \Theta(W_{ii} x + b_{ii} + W_{hi} h + b_{hi}) \\ f &= \Theta(W_{if} x + b_{if} + W_{hf} h + b_{hf}) \\ g &= \Theta(W_{ig} x + b_{ig} + W_{hg} h + b_{hg}) \\ o &= \Theta(W_{io} x + b_{io} + W_{ho} h + b_{ho}) \\ c' &= f \odot c + i \odot g \\ h' &= o \odot c' \end{align*}其中 \(\Theta\) 是 Heaviside 阶跃函数(脉冲函数),\(\odot\) 是 Hadamard 点积,即逐元素相乘。
- 参数:
input_size (int) -- 输入
x的特征数hidden_size (int) -- 隐藏状态
h的特征数bias (bool) -- 若为
False, 则内部的隐藏层不会带有偏置项b_ih和b_hh。 默认为Truesurrogate_function1 (SurrogateFunctionBase) -- 反向传播时用来计算脉冲函数梯度的替代函数, 计算
i,f,o反向传播时使用surrogate_function2 (Optional[SurrogateFunctionBase]) -- 反向传播时用来计算脉冲函数梯度的替代函数, 计算
g反向传播时使用。 若为None, 则设置成surrogate_function1。默认为None
备注
所有权重和偏置项都会按照 \(\mathcal{U}(-\sqrt{k}, \sqrt{k})\) 进行初始化。 其中 \(k = \frac{1}{\text{hidden_size}}\).
示例代码:
T = 6 batch_size = 2 input_size = 3 hidden_size = 4 rnn = rnn.SpikingLSTMCell(input_size, hidden_size) input = torch.randn(T, batch_size, input_size) * 50 h = torch.randn(batch_size, hidden_size) c = torch.randn(batch_size, hidden_size) output = [] for t in range(T): h, c = rnn(input[t], (h, c)) output.append(h) print(output)
English
A spiking long short-term memory (LSTM) cell, which is firstly proposed in Long Short-Term Memory Spiking Networks and Their Applications.
\begin{align*} i &= \Theta(W_{ii} x + b_{ii} + W_{hi} h + b_{hi}) \\ f &= \Theta(W_{if} x + b_{if} + W_{hf} h + b_{hf}) \\ g &= \Theta(W_{ig} x + b_{ig} + W_{hg} h + b_{hg}) \\ o &= \Theta(W_{io} x + b_{io} + W_{ho} h + b_{ho}) \\ c' &= f \odot c + i \odot g \\ h' &= o \odot c' \end{align*}where \(\Theta\) is the Heaviside function, and \(\odot\) is the Hadamard product.
- 参数:
input_size (int) -- The number of expected features in the input
xhidden_size (int) -- The number of features in the hidden state
hbias (bool) -- If
False, then the layer does not use bias weightsb_ihandb_hh. Default:Truesurrogate_function1 (SurrogateFunctionBase) -- surrogate function for replacing gradient of spiking functions during back-propagation, which is used for generating
i,f,osurrogate_function2 (Optional[SurrogateFunctionBase]) -- surrogate function for replacing gradient of spiking functions during back-propagation, which is used for generating
g. IfNone, the surrogate function for generatinggwill be set assurrogate_function1. Default:None
Note
All the weights and biases are initialized from \(\mathcal{U}(-\sqrt{k}, \sqrt{k})\) where \(k = \frac{1}{\text{hidden_size}}\).
Examples:
T = 6 batch_size = 2 input_size = 3 hidden_size = 4 rnn = rnn.SpikingLSTMCell(input_size, hidden_size) input = torch.randn(T, batch_size, input_size) * 50 h = torch.randn(batch_size, hidden_size) c = torch.randn(batch_size, hidden_size) output = [] for t in range(T): h, c = rnn(input[t], (h, c)) output.append(h) print(output)
- forward(x, hc=None)[源代码]#
-
中文
执行单步 Spiking LSTM cell 前向传播。
若
hc为None,则会在x.device上构造零初始状态h_0和c_0。返回值中的h_1、c_1分别表示当前时间步的隐藏状态与细胞状态。- 参数:
- 返回:
(h_1, c_1),两个张量的形状均为[batch_size, hidden_size]- 返回类型:
English
Run the forward pass of a single-step Spiking LSTM cell.
If
hcisNone, zero initial statesh_0andc_0are created onx.device. The returnedh_1andc_1are the hidden state and cell state of the current time step.- 参数:
- 返回:
(h_1, c_1), both tensors have shape[batch_size, hidden_size]- 返回类型:
- class spikingjelly.activation_based.rnn.SpikingLSTM(input_size, hidden_size, num_layers, bias=True, dropout_p=0, invariant_dropout_mask=False, bidirectional=False, surrogate_function1=Erf(alpha=2.0, spiking=True), surrogate_function2=None)[源代码]#
-
中文
多层脉冲长短时记忆 LSTM, 最先由 Long Short-Term Memory Spiking Networks and Their Applications 一文提出。
每一层的计算按照
\begin{align*} i_{t} &= \Theta(W_{ii} x_{t} + b_{ii} + W_{hi} h_{t-1} + b_{hi}) \\ f_{t} &= \Theta(W_{if} x_{t} + b_{if} + W_{hf} h_{t-1} + b_{hf}) \\ g_{t} &= \Theta(W_{ig} x_{t} + b_{ig} + W_{hg} h_{t-1} + b_{hg}) \\ o_{t} &= \Theta(W_{io} x_{t} + b_{io} + W_{ho} h_{t-1} + b_{ho}) \\ c_{t} &= f_{t} \odot c_{t-1} + i_{t} \odot g_{t} \\ h_{t} &= o_{t} \odot c_{t} \end{align*}其中 \(h_{t}\) 是 \(t\) 时刻的隐藏状态,\(c_{t}\) 是 \(t\) 时刻的细胞状态,\(h_{t-1}\) 是该层 \(t-1\) 时刻的隐藏状态或起始状态,\(i_{t}\),\(f_{t}\),\(g_{t}\),\(o_{t}\) 分别是输入,遗忘,细胞,输出门, \(\Theta\) 是 Heaviside 阶跃函数(脉冲函数),\(\odot\) 是 Hadamard 点积,即逐元素相乘。
- 参数:
input_size (int) -- 输入
x的特征数hidden_size (int) -- 隐藏状态
h的特征数num_layers (int) -- 内部RNN的层数,例如
num_layers = 2将会创建堆栈式的两层RNN,第1层接收第0层的输出作为输入, 并计算最终输出bias (bool) -- 若为
False, 则内部的隐藏层不会带有偏置项b_ih和b_hh。 默认为Truedropout_p (float) -- 若非
0,则除了最后一层,每个RNN层后会增加一个丢弃概率为dropout_p的Dropout层。 默认为0invariant_dropout_mask (bool) -- 若为
False,则使用普通的Dropout;若为True,则使用SNN中特有的,mask不 随着时间变化的Dropout,参见Dropout。默认为Falsebidirectional (bool) -- 若为
True,则使用双向RNN。默认为Falsesurrogate_function1 (SurrogateFunctionBase) -- 反向传播时用来计算脉冲函数梯度的替代函数, 计算
i,f,o反向传播时使用surrogate_function2 (Optional[SurrogateFunctionBase]) -- 反向传播时用来计算脉冲函数梯度的替代函数, 计算
g反向传播时使用。 若为None, 则设置成surrogate_function1。默认为None
English
The spiking multi-layer long short-term memory (LSTM), which is firstly proposed in Long Short-Term Memory Spiking Networks and Their Applications.
For each element in the input sequence, each layer computes the following function:
\begin{align*} i_{t} &= \Theta(W_{ii} x_{t} + b_{ii} + W_{hi} h_{t-1} + b_{hi}) \\ f_{t} &= \Theta(W_{if} x_{t} + b_{if} + W_{hf} h_{t-1} + b_{hf}) \\ g_{t} &= \Theta(W_{ig} x_{t} + b_{ig} + W_{hg} h_{t-1} + b_{hg}) \\ o_{t} &= \Theta(W_{io} x_{t} + b_{io} + W_{ho} h_{t-1} + b_{ho}) \\ c_{t} &= f_{t} \odot c_{t-1} + i_{t} \odot g_{t} \\ h_{t} &= o_{t} \odot c_{t} \end{align*}where \(h_t\) is the hidden state at time
t, \(c_t\) is the cell state at timet, \(x_t\) is the input at timet, \(h_{t-1}\) is the hidden state of the layer at timet - 1or the initial hidden state at time0, and \(i_t\), \(f_t\), \(g_t\), \(o_t\) are the input, forget, cell, and output gates, respectively. \(\Theta\) is the Heaviside function, and \(\odot\) is the Hadamard product.- 参数:
input_size (int) -- The number of expected features in the input
xhidden_size (int) -- The number of features in the hidden state
hnum_layers (int) -- Number of recurrent layers. E.g., setting
num_layers=2would mean stacking two LSTMs together to form astacked RNN, with the second RNN taking in outputs of the first RNN and computing the final resultsbias (bool) -- If
False, then the layer does not use bias weightsb_ihandb_hh. Default:Truedropout_p (float) -- If non-zero, introduces a
Dropoutlayer on the outputs of each RNN layer except the last layer, with dropout probability equal todropout. Default: 0invariant_dropout_mask (bool) -- If
False,use the naiveDropout;IfTrue,use the dropout in SNN thatmaskdoesn't change in different time steps, seeDropoutfor more information. Default:Falsebidirectional (bool) -- If
True, becomes a bidirectional LSTM. Default:Falsesurrogate_function1 (SurrogateFunctionBase) -- surrogate function for replacing gradient of spiking functions during back-propagation, which is used for generating
i,f,osurrogate_function2 (Optional[SurrogateFunctionBase]) -- surrogate function for replacing gradient of spiking functions during back-propagation, which is used for generating
g. IfNone, the surrogate function for generatinggwill be set assurrogate_function1. Default:None
- class spikingjelly.activation_based.rnn.SpikingVanillaRNNCell(input_size, hidden_size, bias=True, surrogate_function=Erf(alpha=2.0, spiking=True))[源代码]#
-
中文
单步脉冲 Vanilla RNN cell。
- 参数:
input_size (int) -- 输入
x的特征数hidden_size (int) -- 隐藏状态
h的特征数bias (bool) -- 若为
False,则内部线性层不使用偏置项。默认为Truesurrogate_function (SurrogateFunctionBase) -- 反向传播时用于替代脉冲函数梯度的替代函数
English
Single-step spiking Vanilla RNN cell.
- 参数:
input_size (int) -- Number of input features in
xhidden_size (int) -- Number of features in the hidden state
hbias (bool) -- If
False, the internal linear layers do not use bias. Default:Truesurrogate_function (SurrogateFunctionBase) -- Surrogate function used to replace the spike gradient during back-propagation
- class spikingjelly.activation_based.rnn.SpikingVanillaRNN(input_size, hidden_size, num_layers, bias=True, dropout_p=0, invariant_dropout_mask=False, bidirectional=False, surrogate_function=Erf(alpha=2.0, spiking=True))[源代码]#
-
中文
多层(可选双向)脉冲 Vanilla RNN。
- 参数:
input_size (int) -- 输入
x的特征数hidden_size (int) -- 隐藏状态
h的特征数num_layers (int) -- 循环层数
bias (bool) -- 若为
False,内部线性层不使用偏置项。默认为Truedropout_p (float) -- 除最后一层外的层间 dropout 概率。默认为
0invariant_dropout_mask (bool) -- 若为
True,则训练时在时间维共享 dropout maskbidirectional (bool) -- 若为
True,则构造双向 RNN。默认为Falsesurrogate_function (SurrogateFunctionBase) -- 反向传播时用于替代脉冲函数梯度的替代函数
English
Stacked spiking Vanilla RNN, optionally bidirectional.
- 参数:
input_size (int) -- Number of input features in
xhidden_size (int) -- Number of features in the hidden state
hnum_layers (int) -- Number of recurrent layers
bias (bool) -- If
False, the internal linear layers do not use bias. Default:Truedropout_p (float) -- Inter-layer dropout probability except for the last layer. Default:
0invariant_dropout_mask (bool) -- If
True, the dropout mask is shared across time steps during trainingbidirectional (bool) -- If
True, build a bidirectional RNN. Default:Falsesurrogate_function (SurrogateFunctionBase) -- Surrogate function used to replace the spike gradient during back-propagation
- class spikingjelly.activation_based.rnn.SpikingGRUCell(input_size, hidden_size, bias=True, surrogate_function1=Erf(alpha=2.0, spiking=True), surrogate_function2=None)[源代码]#
-
中文
单步脉冲 GRU cell。
- 参数:
input_size (int) -- 输入
x的特征数hidden_size (int) -- 隐藏状态
h的特征数bias (bool) -- 若为
False,则内部线性层不使用偏置项。默认为Truesurrogate_function1 (SurrogateFunctionBase) -- 用于
r、z门及默认候选态梯度近似的替代函数surrogate_function2 (Optional[SurrogateFunctionBase]) -- 候选态
n的替代函数。若为None,则复用surrogate_function1
English
Single-step spiking GRU cell.
- 参数:
input_size (int) -- Number of input features in
xhidden_size (int) -- Number of features in the hidden state
hbias (bool) -- If
False, the internal linear layers do not use bias. Default:Truesurrogate_function1 (SurrogateFunctionBase) -- Surrogate function used for the
randzgates and, by default, the candidate statesurrogate_function2 (Optional[SurrogateFunctionBase]) -- Surrogate function for the candidate state
n. IfNone,surrogate_function1is reused
- class spikingjelly.activation_based.rnn.SpikingGRU(input_size, hidden_size, num_layers, bias=True, dropout_p=0, invariant_dropout_mask=False, bidirectional=False, surrogate_function1=Erf(alpha=2.0, spiking=True), surrogate_function2=None)[源代码]#
-
中文
多层(可选双向)脉冲 GRU。
- 参数:
input_size (int) -- 输入
x的特征数hidden_size (int) -- 隐藏状态
h的特征数num_layers (int) -- 循环层数
bias (bool) -- 若为
False,内部线性层不使用偏置项。默认为Truedropout_p (float) -- 除最后一层外的层间 dropout 概率。默认为
0invariant_dropout_mask (bool) -- 若为
True,则训练时在时间维共享 dropout maskbidirectional (bool) -- 若为
True,则构造双向 RNN。默认为Falsesurrogate_function1 (SurrogateFunctionBase) -- 用于
r、z门及默认候选态梯度近似的替代函数surrogate_function2 (Optional[SurrogateFunctionBase]) -- 候选态
n的替代函数。若为None,则复用surrogate_function1
English
Stacked spiking GRU, optionally bidirectional.
- 参数:
input_size (int) -- Number of input features in
xhidden_size (int) -- Number of features in the hidden state
hnum_layers (int) -- Number of recurrent layers
bias (bool) -- If
False, the internal linear layers do not use bias. Default:Truedropout_p (float) -- Inter-layer dropout probability except for the last layer. Default:
0invariant_dropout_mask (bool) -- If
True, the dropout mask is shared across time steps during trainingbidirectional (bool) -- If
True, build a bidirectional RNN. Default:Falsesurrogate_function1 (SurrogateFunctionBase) -- Surrogate function used for the
randzgates and, by default, the candidate statesurrogate_function2 (Optional[SurrogateFunctionBase]) -- Surrogate function for the candidate state
n. IfNone,surrogate_function1is reused