主题
循环神经网络(基础篇)
总结:RNNCell
cell = torch.nn.RNNCell(input_size = input_size, hidden_size = hidden_size)
hidden = cell(input, hidden)
构建一个RNNCell节点需要的参数:输入的维度input_size与输出(隐藏层)output_size的维度
训练RNNCell节点时的数据集需要额外的维度:序列长度seqLen、批样本数batchSize
input.shape =(batchSize, inputSize)
output.shape =(batchSize, hiddenSize)
dataset.shape = (seqLen, batchSize, inputSize)
总结:RNN
cell = torch.nn.RNN(input_size = input_size, hidden_size = hidden_size, num_layers = num_layers)
outputs, hidden = cell(inputs, hidden)
input:
- input.shape = (seqSize, batch, input_size)
- hidden.shape = (numLayers, batch, hidden_size)
output:
- output.shape = (seqLen, batch, hidden_size)
- hidden.shape = (numLayers, batch, hidden_size)
实例化RNNCell的可选参数:
batch_first = False/True
。默认是False。若设置为True。输入与输入的数据格式变为(batch_size, seqLen, input/output_size)
总结:带Embedding层的RNN
把文本转换成 one-hot 向量
交叉熵损失
总结:LSTM
总结:GRU
总结
one-hot编码的缺点:
(1)高维
(2)稀疏
(3)硬编码Embedding的优点:
(1)低维
(2)稠密
(3)从数据中学习而来处理序列数据,循环处理,网络参数权重共享。