Solved by LucasVandroux in post #3 
              
              
                Hello, I don’t think nn.CrossEntropyLoss is actually helpful here. I would recommend using nn.MSELoss. You can find some discussion about the differences between the two here: 
 
 
Therefore, after some minor changes to your code, I managed to get it to converge: 
import torch
from torch import nn, …