@albanD  here is the other error message that I get when I use the initial code above:
File "<ipython-input-147-5a55720cc37f>", line 84, in <module>
    train_acc += (pred == labels).sum()

File "/usr/local/lib/python3.6/site-packages/torch/tensor.py", line 348, in __eq__
    return self.eq(other)

TypeError: eq received an invalid combination of arguments - got (Variable), but expected one of:
 * (int value)
      didn't match because some of the arguments have invalid types: (!Variable!)
 * (torch.LongTensor other)
      didn't match because some of the arguments have invalid types: (!Variable!)