Training a recurrent neural network
Recurrent Neural Networks (RNNs) are a class of neural networks that are especially effective for tasks involving sequential data, such as time series forecasting and natural language processing.
Getting ready
RNNs use sequential information by having hidden layers capable of passing information from one step in the sequence to the next.
How to do it…
Similar to the feedforward network, we begin by defining our RNN
class. For simplicity, let’s define a single-layer RNN
:
class RNN(nn.Module): def __init__(self, input_size, hidden_size, output_size): super(RNN, self).__init__() self.hidden_size = hidden_size self.rnn = nn.RNN(input_size, hidden_size, batch_first=True) self.fc = nn.Linear(hidden_size, output_size...