@@ -121,11 +121,9 @@ 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 ])
125124
126- def predict (self ):
127- return T .mul (self .y_pred ,1 )
128-
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+
129127 def errors (self , y ):
130128 """Return a float representing the number of errors in the minibatch
131129 over the total number of examples of the minibatch ; zero one
@@ -194,7 +192,7 @@ def load_data(dataset):
194192 test_set_size = 1000 ;
195193 predict_set_size = 28000 ;
196194
197- debug = "false " ;
195+ debug = "true " ;
198196 if debug == "true" :
199197 train_set_size = 3600 ;
200198 valid_set_size = 500 ;
@@ -285,7 +283,7 @@ def shared_dataset(data_xy, borrow=True):
285283
286284def sgd_optimization_mnist (learning_rate = 0.13 , n_epochs = 1000 ,
287285 dataset = '../data/mnist.pkl.gz' ,
288- batch_size = 600 ):
286+ batch_size = 500 ):
289287 """
290288 Demonstrate stochastic gradient descent optimization of a log-linear
291289 model
@@ -344,11 +342,6 @@ def sgd_optimization_mnist(learning_rate=0.13, n_epochs=1000,
344342 x : test_set_x [index * batch_size : (index + 1 ) * batch_size ],
345343 y : test_set_y [index * batch_size : (index + 1 ) * batch_size ]})
346344
347- release_output = theano .function (inputs = [index ],
348- outputs = classifier .release_output (),
349- givens = {
350- x : predict_set_x [index :]})
351-
352345 validate_model = theano .function (inputs = [index ],
353346 outputs = classifier .errors (y ),
354347 givens = {
@@ -428,9 +421,11 @@ def sgd_optimization_mnist(learning_rate=0.13, n_epochs=1000,
428421 test_losses = [test_model (i )
429422 for i in xrange (n_test_batches )]
430423 test_score = numpy .mean (test_losses )
424+
425+ y_pred_show = classifier .y_pred .eval ({input :predict_set_x })
431426
432- y_pred_show = [release_output ( i )
433- for i in xrange (n_predict_batches )]
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 )]
434429
435430 print y_pred_show ;
436431 f = open ("predict_res" ,"w+" );
0 commit comments