Note btw that the binary_cross_entropy()
function in the video has a small error, but this is fixed in the fastbook-repo (inputs
, and 1-inputs
was switched):
def binary_cross_entropy(inputs, targets):
inputs = inputs.sigmoid()
return -torch.where(targets==1, inputs, 1-inputs).log().mean()