MCPcopy Index your code
hub / github.com/pytorch/tutorials / maskNLLLoss

Function maskNLLLoss

beginner_source/chatbot_tutorial.py:876–881  ·  view source on GitHub ↗
(inp, target, mask)

Source from the content-addressed store, hash-verified

874#
875
876def maskNLLLoss(inp, target, mask):
877 nTotal = mask.sum()
878 crossEntropy = -torch.log(torch.gather(inp, 1, target.view(-1, 1)).squeeze(1))
879 loss = crossEntropy.masked_select(mask).mean()
880 loss = loss.to(device)
881 return loss, nTotal.item()
882
883
884######################################################################

Callers 1

trainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected