Something like this should work
import torch
import torch.nn as nn
from torch.autograd import Variable

time_steps = 10
batch_size = 3
in_size = 5
classes_no = 7
hidden_size = 12 # for example

class Model(nn.Module):
    def __init__(self):
        super(Model, self).__init__()
        self.lstm = nn.LSTM(in_size, hidden_size, 2)
        self.linear = nn.Linear(hidden_size, classes_no)

    def forward(self, input_seq):
        output_seq, _ = self.lstm(input_seq)
        last_output = output_seq[-1]
        class_predictions = self.linear(last_output)
        return class_predictions

# initialise model and loss function
model = Model()
loss = nn.CrossEntropyLoss()

# prepare input and target
input_seq = Variable(torch.randn(time_steps, batch_size, in_size)) 
target = Variable(torch.LongTensor(batch_size).random_(0, classes_no-1))

# calculate stuff
output = model(input_seq)
err = loss(last_output, target)
err.backward()