import torch.nn as nn import torch.nn.functional as F class CharRNN([nn.Module](https://docs.pytorch.org/docs/stable/generated/torch.nn.Module.html#torch.nn.Module "torch.nn.Module")): def __init__(self, input_size, hidden_size, output_size): super([CharRNN](https://docs.pytorch.org/docs/stable/generated/torch.nn.Module.html#torch.nn.Module "torch.nn.Module"), self).__init__() self.rnn = [nn.RNN](https://docs.pytorch.org/docs/stable/generated/torch.nn.RNN.html#torch.nn.RNN "torch.nn.RNN")(input_size, hidden_size) self.h2o = [nn.Linear](https://docs.pytorch.org/docs/stable/generated/torch.nn.Linear.html#torch.nn.Linear "torch.nn.Linear")(hidden_size, output_size) self.softmax = [nn.LogSoftmax](https://docs.pytorch.org/docs/stable/generated/torch.nn.LogSoftmax.html#torch.nn.LogSoftmax "torch.nn.LogSoftmax")(dim=1) def forward(self, line_tensor): rnn_out, hidden = self.rnn(line_tensor) [output](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "torch.Tensor") = self.h2o(hidden[0]) [output](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "torch.Tensor") = self.softmax([output](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "torch.Tensor")) return [output](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "torch.Tensor")