Reading through your question I’m getting a feeling that the error is with regards to your input dimensions and not your output. All RNN modules in PyTorch expect a 3D input of type (seq_len, batch, input_size) (See https://pytorch.org/docs/stable/nn.html#recurrent-layers 1). And I’m guessing that that’s where the error is from.
In terms of NLP related tasks usually, you create a dataset of seq_len x batch dimensions which in turn you pass through an nn.Embedding (https://pytorch.org/docs/stable/nn.html#embedding 4) sparse layer to get the input_size dimension thus creating the proper input to pass to the RNN layers.
seq_len is a segment of a document (a paragraph, a sentence or even a part of a sentence) which is tokenized and each token is being represented by a numeric id. So the sentence “What do you get when you multiply six by seven?” becomes [ 11 24 31 2 7 10 38 30 37 33 34 ]. This is your first dimension.
Say now you have multiple sentences that you could process in parallel. You group them together (perhaps padding them first so that all have the same length) and you get the second dimension which is the batch. (So now you have a batch, a group, of equal length of inputs)
At this point you usually map each word to a vector which represents the “meaning” (loosely speaking) of the word. This could be randomly initialised or one could use an existing vector created via word2vec, glove etc. This vector is your input_size.