Could you check your input for NaN values?
Just use
print((matrix1==matrix1).all())

There are a few minor issues in your code:


torch.Tensor creates an uninitialized tensor. I would recommend to use e.g. torch.zeros instead, so that the values are zero in case you are not initializing them.
It’s uncommon so add F.log_softmax between layers. Usually you would want to use it at your last linear layer in case you have a classification use case. F.relu would be a common non-linearity between layers.

Variables are deprecated since 0.4.0. You can directly use tensors instead now.
Probably not an issue, but you are not closing the file k. A good way is to use with open('Dataset.txt', 'r') as k: so that the file will be automatically closed.
I would suggest to create the criterion and optimizer outside the for loop. It’s not that important for the criterion. In case you would use an optimizer with running estimates (e.g. Adam) you would re-initialize it in each iteration.