概念
三个门:遗忘门、输入门、输出门
候选记忆单元
记忆单元
隐状态
ot 控制是否让输出,是否要进行重置。
总结
代码实现
import torch
from torch import nn
from d2l import torch as d2lbatch_size,num_steps = 32,35
train_iter,vocab = d2l.load_data_time_machine(batch_size,num_steps)
vocab_size, num_hiddens, device = len(vocab), 256, d2l.try_gpu()
num_inputs = vocab_size
lstm_layer = nn.LSTM(num_inputs, num_hiddens)
model = d2l.RNNModel(lstm_layer, len(vocab))
model = model.to(device)
num_epochs, lr = 500, 1
d2l.train_ch8(model, train_iter, vocab, lr, num_epochs, device)