h1 = 32 is the size hidden state which is independent from the output. Hence the last linear layer that maps the hidden state to the output (self.linear = nn.Linear(self.hidden_dim, output_dim)). That’s the normal setup. You could also have a series of linear layers (with activation functions and optional dropout etc.) as long as the last one maps to the output classes.
Good point regarding the loss function though. I’m more of an beginner myself, so I’m not sure either. I usually go with log_softmax as the last step in the forward method and than NLLLoss to compute the loss.