1 RNN背景介绍
RNN结构
参数介绍:
input_size: 输入x的特征数量
hiddien_size: 隐藏层的特征数量
num_layers: RNN的层数
nonlinearity: 指定激活函数是tanh还是relu,默认是tanh
bias:False不使用偏置权重b_ih和b_hh,默认是True
batch_first:如果是True,那么输入的Tensor的shape是[batch_size, time_step, feature],输出也是[batch_size, time_step, feature]
dropout:如果值是非零,那么除最后一层外,其他层的输出都会套上一个dropout层
bidirectional:如果是True,将是一个双向RNN,默认是False
RNN的输入:(input, h_0)
input shape: [time_step, batch_size, feature]
h_0 shape: [num_layers*num_directions, batch_size,hidden_size] #num_directions参数的值由参数bidirectional决定
RNN的输出: (output, h_n)
output shape: [time_step,batch_size,hidden_sizenum_directions]
RNN每层的计算公式是:
h_t = tanh((w_ihx_t+b_ih)+(w_hh