Theano / Theano

Theano was a Python library that allows you to define, optimize, and evaluate mathematical expressions involving multi-dimensional arrays efficiently. It is being continued as PyTensor: www.github.com/pymc-devs/pytensor

Home Page:https://www.github.com/pymc-devs/pytensor

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

A Suspected Bug in `categorical_crossentropy`

cheyennee opened this issue · comments

I found that the the calculation result of categorical_crossentropy loss function is different from other deep learning libraries, such as tensorflow.

repo code:
theano 1.0.4

import numpy as np
from theano import tensor as T
y_true = np.array([0., 1., 0.], dtype=np.float32)
y_pred = np.array([0.9999999, 0.9999999, 0.0000001], dtype=np.float32)
res = T.nnet.categorical_crossentropy(y_pred, y_true)
print("loss = ", res.eval())
# loss =  1.192093e-07

tensorflow 2.0.0

import numpy as np
import keras
y_true = np.array([0., 1., 0.], dtype=np.float32)
y_pred = np.array([0.9999999, 0.9999999, 0.0000001], dtype=np.float32)
res = keras.losses.categorical_crossentropy(y_true, y_pred)
print("loss = ", res.numpy())
# loss =  0.69314724