Hi Koen!



 Koen:

I am looking for a loss function that prefers nearby classes, so for example I have 10 classes, and a sample has class 6, then class 5 and 7 should receive a relatively low loss, while further classes should receive an increasingly higher loss value.


Consider MSELoss 1.


(bonus points if I can tweak the penalty based on how far away a class is or something)


You can always write your own loss function.  (If you implement using
only differentiable pytorch tensor functions you don’t have to package
it as an official torch.autograd.Function nor implement explicit
forward() and backward() methods.)
Best.
K. Frank