MCPcopy Index your code
hub / github.com/patrickloeber/pytorchTutorial / cross_entropy

Function cross_entropy

11_softmax_and_crossentropy.py:33–37  ·  view source on GitHub ↗
(actual, predicted)

Source from the content-addressed store, hash-verified

31# whose output is a probability value between 0 and 1.
32# -> loss increases as the predicted probability diverges from the actual label
33def cross_entropy(actual, predicted):
34 EPS = 1e-15
35 predicted = np.clip(predicted, EPS, 1 - EPS)
36 loss = -np.sum(actual * np.log(predicted))
37 return loss # / float(predicted.shape[0])
38
39# y must be one hot encoded
40# if class 0: [1 0 0]

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected