Skip to content

Commit c577281

Browse files
authored
A minor mistake in cross entropy loss (#357)
tf.reduce_mean(-tf.reduce_sum(y_true * tf.math.log(y_pred),1)) or else it simply finds the sum and the reduced mean remains the sum itself.
1 parent 7aeb6cb commit c577281

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

tensorflow_v2/notebooks/2_BasicModels/logistic_regression.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@
109109
" # Clip prediction values to avoid log(0) error.\n",
110110
" y_pred = tf.clip_by_value(y_pred, 1e-9, 1.)\n",
111111
" # Compute cross-entropy.\n",
112-
" return tf.reduce_mean(-tf.reduce_sum(y_true * tf.math.log(y_pred)))\n",
112+
" return tf.reduce_mean(-tf.reduce_sum(y_true * tf.math.log(y_pred),1))\n",
113113
"\n",
114114
"# Accuracy metric.\n",
115115
"def accuracy(y_pred, y_true):\n",

0 commit comments

Comments
 (0)