<jupyter_start><jupyter_text>http://preview.d2l.ai/d2l-en/master/chapter_recurrent-modern/bi-rnn.html<jupyter_code>from d2l import torch as d2l
import torch
from torch import nn

# Load data
batch_size, num_steps, device = 32, 35, d2l.try_gpu()
train_iter, vocab = d2l.load_data_time_machine(batch_size, num_steps)
# Define the model
vocab_size, num_hiddens, num_layers = len(vocab), 256, 2
num_inputs = vocab_size
lstm_layer = nn.LSTM(num_inputs, num_hiddens, num_layers, bidirectional=True)
lstm_layer.bidirectional
model = d2l.RNNModel(lstm_layer, len(vocab))
model = model.to(device)
# Train the model
num_epochs, lr = 500, 1
d2l.train_ch8(model, train_iter, vocab, lr, num_epochs, device)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10926694329183956, 'fraction_numerical': 0.029045643153526972, 'mean_word_length': 7.044444444444444, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '95314', 'license': 'MIT', 'n_tokens_mistral': 312, 'n_tokens_neox': 296, 'n_words': 59, 'path': 'Ch09_Modern-RNN/9-4.ipynb', 'repo_name': 'dltech-xyz/d2l-en-read', 'size': '723'}