Forward Propagate RNN using Pytorch
I am trying to create an RNN forward pass method that can take a variable input, hidden, and output size and create the rnn cells needed. To me, it seems like I am passing the correct variables to self.rnn_cell -- the input values of x and the previous hidden layer. However, the error I receive is included below. 

I have also tried using x[i] and x[:,i,i] (as suggested by my professor) to no avail. I am confused and just looking for guidance as to whether or not I am doing the right thing here. My prof suggested that since I keep receiving errors, I should restart the kernel in jupyter notebook and rerun code. I have, and I receive the same errors...

Please let me know if you need additional context. 

class RNN(nn.Module):
    def __init__(self, input_size, hidden_size, output_size):
        super(RNN, self).__init__()
        self.hidden_size = hidden_size

        self.rnn_cell = nn.RNNCell(input_size, hidden_size)
        self.fc = nn.Linear(hidden_size, output_size)
        self.softmax = nn.LogSoftmax(dim=1)

    def forward(self, x):
        """
        x: size [seq_length, 1, input_size]
        """
        h = torch.zeros(x.size(1), self.hidden_size)

        for i in range(x.size(0)):
            ### START YOUR CODE ###
            h = self.rnn_cell(x[:,:,i], h)
            ### END YOUR CODE ###

        ### START YOUR CODE ###
        # Hint: first call fc, then call softmax
        out = self.softmax(self.fc(self.hidden_size, h.size(0)))
        ### END YOUR CODE ###

        return out 
IndexError: Dimension out of range (expected to be in range of [-1, 0], but got 1)


I am not an expert at RNNs but giving it a try.

class RNN(nn.Module):
def __init__(self, input_size, hidden_size, output_size):
    super(RNN, self).__init__()
    self.hidden_size = hidden_size

    self.rnn_cell = nn.RNN(input_size, hidden_size)
    self.fc = nn.Linear(hidden_size, output_size)


def forward(self, x):
    """
    x: size [seq_length, 1, input_size]
    """
    h = torch.zeros(num_layers(hidden), x.size(0), self.hidden_size)


        ### START YOUR CODE ###
    out,hidden = self.rnn_cell(x, h)
        ### END YOUR CODE ###

    ### START YOUR CODE ###
    # Hint: first call fc, then call softmax
    out = out.contiguous().view(-1, self.hidden_dim) #You need to reshape the output to fit the FC layer
    out = self.fc(out)
    return F.softmax(out)
    ### END YOUR CODE ###

    return out 


Please try running this and let me know in case of errors or any doubts. (Cannot ask you details as I can't comment rn.)

If you got any idea from my answer, do support.
