title: Cross Entropy in PyTorch
body: <p>Cross entropy formula:</p>
  <p><a href="https://i.stack.imgur.com/W3xm0.gif" rel="noreferrer"><img src="https://i.stack.imgur.com/W3xm0.gif" alt="enter image description here" /></a></p>
  <p>But why does the following give <code>loss = 0.7437</code> instead of <code>loss = 0</code> (since <code>1*log(1) = 0</code>)?</p>
  
  <pre class="lang-python prettyprint-override"><code>import torch
  import torch.nn as nn
  from torch.autograd import Variable
  
  output = Variable(torch.FloatTensor([0,0,0,1])).view(1, -1)
  target = Variable(torch.LongTensor([3]))
  
  criterion = nn.CrossEntropyLoss()
  loss = criterion(output, target)
  print(loss)
  </code></pre>