You would have to map the words to indices as e.g. described in this tutorial 633 first and could then create the tensors containing the numerical values.
The second error is raised, if the JPEG file descriptor instead of an already loaded image array is passed to the tensor creation. Make sure img is transformed to a tensor in the self.transforms or create it from a numpy array via torch.from_numpy.