Skip to content

Commit 08476ed

Browse files
author
Yoshua Bengio
committed
added comment to help parse [T.arange(y.shape[0]),y]
1 parent e4fce9f commit 08476ed

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

code/logistic_sgd.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,15 @@ def negative_log_likelihood(self, y):
107107
Note: we use the mean instead of the sum so that
108108
the learning rate is less dependent on the batch size
109109
"""
110+
# y.shape[0] is the number of examples n in the minibatch
111+
# T.arange(y.shape[0]) is a vector containing [0,1,2,... n-1]
112+
# T.log(self.p_y_given_x) is a matrix L with one row per example and one column per class
113+
# L[T.arange(y.shape[0]),y] is a vector v containing [L[0,y[0]], L[1,y[1]], L[2,y[2]], ..., L[n-1,y[n-1]]]
114+
# and T.mean(L[T.arange(y.shape[0]),y]) is the mean (across minibatch examples) of the elements in v,
115+
# i.e., the mean log-likelihood across the minibatch.
110116
return -T.mean(T.log(self.p_y_given_x)[T.arange(y.shape[0]),y])
111117

112118

113-
114-
115-
116119
def errors(self, y):
117120
"""Return a float representing the number of errors in the minibatch
118121
over the total number of examples of the minibatch ; zero one

0 commit comments

Comments
 (0)