深度循环神经网咯

import torch
from torch import nn
from d2l import torch as d2l
batch_size, num_steps = 32, 35
train_iter, vocab = d2l.load_data_time_machine(batch_size, num_steps)
直接用框架实现
vocab_size, num_hiddens, num_layers = len(vocab), 256, 2
num_inputs = vocab_size
device = d2l.try_gpu()
lstm_layer = nn.LSTM(num_inputs, num_hiddens, num_layers)
model = d2l.RNNModel(lstm_layer, len(vocab))
model = model.to(device)
lstm_layer = nn.LSTM(num_inputs, num_hiddens, num_layers)这里用的是LSTM模块,
num_layers参数定义层数
num_epochs, lr = 500, 2
d2l.train_ch8(model, train_iter, vocab, lr, num_epochs, device)
perplexity 1.0, 93583.7 tokens/sec on cuda:0
time travelleryou can show black is white by argument said filby
travelleryou can show black is white by argument said filby

本文介绍了如何使用PyTorch实现深度循环神经网络(LSTM)模型,详细步骤包括加载Time Machine数据集、构建模型结构、设置训练参数并进行训练。实验结果展示了模型在时间序列预测中的性能,如perplexity和平均每秒处理的token数。
1807

被折叠的 条评论
为什么被折叠?



