Multi-Class Cross Entropy Loss function implementation in PyTorch

Hi @ptrblck

How should I go about converting following numpy expression to an equivalent one using torch.sum() or torch.view().sum()?

loss = -np.mean(np.sum(np.sum(np.sum(labels * np.log(predictions), axis=1), axis=1), axis=1))

There was a discussion here Sum / Mul over multiple axes but I’m still trying to figure out the syntax.

1 Like