@@ -121,9 +121,11 @@ def negative_log_likelihood(self, y):
121121 # LP[n-1,y[n-1]]] and T.mean(LP[T.arange(y.shape[0]),y]) is
122122 # the mean (across minibatch examples) of the elements in v,
123123 # i.e., the mean log-likelihood across the minibatch.
124+ return - T .mean (T .log (self .p_y_given_x )[T .arange (y .shape [0 ]), y ])
124125
125- return - T .mean (T .log (self .p_y_given_x )[T .arange (y .shape [0 ]), y ]) + 0.0001 * T .sum (self .W ** 2 )
126-
126+ def predict (self ):
127+ return T .mul (self .y_pred ,1 )
128+
127129 def errors (self , y ):
128130 """Return a float representing the number of errors in the minibatch
129131 over the total number of examples of the minibatch ; zero one
@@ -192,7 +194,7 @@ def load_data(dataset):
192194 test_set_size = 1000 ;
193195 predict_set_size = 28000 ;
194196
195- debug = "true " ;
197+ debug = "false " ;
196198 if debug == "true" :
197199 train_set_size = 3600 ;
198200 valid_set_size = 500 ;
@@ -283,7 +285,7 @@ def shared_dataset(data_xy, borrow=True):
283285
284286def sgd_optimization_mnist (learning_rate = 0.13 , n_epochs = 1000 ,
285287 dataset = '../data/mnist.pkl.gz' ,
286- batch_size = 500 ):
288+ batch_size = 600 ):
287289 """
288290 Demonstrate stochastic gradient descent optimization of a log-linear
289291 model
@@ -342,6 +344,11 @@ def sgd_optimization_mnist(learning_rate=0.13, n_epochs=1000,
342344 x : test_set_x [index * batch_size : (index + 1 ) * batch_size ],
343345 y : test_set_y [index * batch_size : (index + 1 ) * batch_size ]})
344346
347+ release_output = theano .function (inputs = [index ],
348+ outputs = classifier .release_output (),
349+ givens = {
350+ x : predict_set_x [index :]})
351+
345352 validate_model = theano .function (inputs = [index ],
346353 outputs = classifier .errors (y ),
347354 givens = {
@@ -421,11 +428,9 @@ def sgd_optimization_mnist(learning_rate=0.13, n_epochs=1000,
421428 test_losses = [test_model (i )
422429 for i in xrange (n_test_batches )]
423430 test_score = numpy .mean (test_losses )
424-
425- y_pred_show = classifier .y_pred .eval ({input :predict_set_x })
426431
427- y_pred_show = [classifier . y_pred . eval ({ input : predict_set_x [ index * batch_size : ( index + 1 ) * batch_size ]} )
428- for index in xrange (n_predict_batches )]
432+ y_pred_show = [release_output ( i )
433+ for i in xrange (n_predict_batches )]
429434
430435 print y_pred_show ;
431436 f = open ("predict_res" ,"w+" );
0 commit comments