GeezerVison is showing github.com — Merge pull request #16 from lisa-lab/updates_dict_warning · imclab/DeepLearningTutorials@2237825
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: code/DBN.py +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -220,9 +220,9 @@ def build_finetune_functions(self, datasets, batch_size, learning_rate): | 220 | 220 | gparams = T.grad(self.finetune_cost, self.params) | 221 | 221 |
| 222 | 222 | # compute list of fine-tuning updates | 223 | | - updates = {} | | 223 | + updates = [] | 224 | 224 | for param, gparam in zip(self.params, gparams): | 225 | | - updates[param] = param - gparam * learning_rate | | 225 | + updates.append((param, param - gparam * learning_rate)) | 226 | 226 |
| 227 | 227 | train_fn = theano.function(inputs=[index], | 228 | 228 | outputs=self.finetune_cost, | |
Collapse file Copy file name to clipboardExpand all lines: code/SdA.py +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -252,9 +252,9 @@ def build_finetune_functions(self, datasets, batch_size, learning_rate): | 252 | 252 | gparams = T.grad(self.finetune_cost, self.params) | 253 | 253 |
| 254 | 254 | # compute list of fine-tuning updates | 255 | | - updates = {} | | 255 | + updates = [] | 256 | 256 | for param, gparam in zip(self.params, gparams): | 257 | | - updates[param] = param - gparam * learning_rate | | 257 | + updates.append((param, param - gparam * learning_rate)) | 258 | 258 |
| 259 | 259 | train_fn = theano.function(inputs=[index], | 260 | 260 | outputs=self.finetune_cost, | |
Collapse file Copy file name to clipboardExpand all lines: code/cA.py +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -213,9 +213,9 @@ def get_cost_updates(self, contraction_level, learning_rate): | 213 | 213 | # to its parameters | 214 | 214 | gparams = T.grad(cost, self.params) | 215 | 215 | # generate the list of updates | 216 | | - updates = {} | | 216 | + updates = [] | 217 | 217 | for param, gparam in zip(self.params, gparams): | 218 | | - updates[param] = param - learning_rate * gparam | | 218 | + updates.append((param, param - learning_rate * gparam)) | 219 | 219 |
| 220 | 220 | return (cost, updates) | 221 | 221 |
| |
Collapse file Copy file name to clipboardExpand all lines: code/convolutional_mlp.py +3-3Lines changed: 3 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -206,11 +206,11 @@ def evaluate_lenet5(learning_rate=0.1, n_epochs=200, | 206 | 206 | # train_model is a function that updates the model parameters by | 207 | 207 | # SGD Since this model has many parameters, it would be tedious to | 208 | 208 | # manually create an update rule for each model parameter. We thus | 209 | | - # create the updates dictionary by automatically looping over all | | 209 | + # create the updates list by automatically looping over all | 210 | 210 | # (params[i],grads[i]) pairs. | 211 | | - updates = {} | | 211 | + updates = [] | 212 | 212 | for param_i, grad_i in zip(params, grads): | 213 | | - updates[param_i] = param_i - learning_rate * grad_i | | 213 | + updates.append((param_i, param_i - learning_rate * grad_i)) | 214 | 214 |
| 215 | 215 | train_model = theano.function([index], cost, updates=updates, | 216 | 216 | givens={ | |
Collapse file Copy file name to clipboardExpand all lines: code/dA.py +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -229,9 +229,9 @@ def get_cost_updates(self, corruption_level, learning_rate): | 229 | 229 | # to its parameters | 230 | 230 | gparams = T.grad(cost, self.params) | 231 | 231 | # generate the list of updates | 232 | | - updates = {} | | 232 | + updates = [] | 233 | 233 | for param, gparam in zip(self.params, gparams): | 234 | | - updates[param] = param - learning_rate * gparam | | 234 | + updates.append((param, param - learning_rate * gparam)) | 235 | 235 |
| 236 | 236 | return (cost, updates) | 237 | 237 |
| |
Collapse file Copy file name to clipboardExpand all lines: code/logistic_sgd.py +4-3Lines changed: 4 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -279,9 +279,10 @@ def sgd_optimization_mnist(learning_rate=0.13, n_epochs=1000, | 279 | 279 | g_W = T.grad(cost=cost, wrt=classifier.W) | 280 | 280 | g_b = T.grad(cost=cost, wrt=classifier.b) | 281 | 281 |
| 282 | | - # specify how to update the parameters of the model as a dictionary | 283 | | - updates = {classifier.W: classifier.W - learning_rate * g_W, | 284 | | - classifier.b: classifier.b - learning_rate * g_b} | | 282 | + # specify how to update the parameters of the model as a list of | | 283 | + # (variable, update expression) pairs. | | 284 | + updates = [(classifier.W, classifier.W - learning_rate * g_W), | | 285 | + (classifier.b, classifier.b - learning_rate * g_b)] | 285 | 286 |
| 286 | 287 | # compiling a Theano function `train_model` that returns the cost, but in | 287 | 288 | # the same time updates the parameter of the model based on the rules | |
Collapse file Copy file name to clipboardExpand all lines: code/mlp.py +4-3Lines changed: 4 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -258,14 +258,15 @@ def test_mlp(learning_rate=0.01, L1_reg=0.00, L2_reg=0.0001, n_epochs=1000, | 258 | 258 | gparam = T.grad(cost, param) | 259 | 259 | gparams.append(gparam) | 260 | 260 |
| 261 | | - # specify how to update the parameters of the model as a dictionary | 262 | | - updates = {} | | 261 | + # specify how to update the parameters of the model as a list of | | 262 | + # (variable, update expression) pairs | | 263 | + updates = [] | 263 | 264 | # given two list the zip A = [a1, a2, a3, a4] and B = [b1, b2, b3, b4] of | 264 | 265 | # same length, zip generates a list C of same size, where each element | 265 | 266 | # is a pair formed from the two lists : | 266 | 267 | # C = [(a1, b1), (a2, b2), (a3, b3), (a4, b4)] | 267 | 268 | for param, gparam in zip(classifier.params, gparams): | 268 | | - updates[param] = param - learning_rate * gparam | | 269 | + updates.append((param, param - learning_rate * gparam)) | 269 | 270 |
| 270 | 271 | # compiling a Theano function `train_model` that returns the cost, but | 271 | 272 | # in the same time updates the parameter of the model based on the rules | |
Collapse file Copy file name to clipboardExpand all lines: doc/DBN.txt +7-7Lines changed: 7 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -307,7 +307,7 @@ Theano variable to it that has a default value. | 307 | 307 | # get the cost and the updates list | 308 | 308 | # using CD-k here (persisent=None) for training each RBM. | 309 | 309 | # TODO: change cost function to reconstruction error | 310 | | - cost,updates = rbm.cd(learning_rate, persistent=None, k) | | 310 | + cost, updates = rbm.cd(learning_rate, persistent=None, k) | 311 | 311 |
| 312 | 312 | # compile the Theano function; check if k is also a Theano | 313 | 313 | # variable, if so added to the inputs of the function | @@ -316,10 +316,10 @@ Theano variable to it that has a default value. | 316 | 316 | else: | 317 | 317 | inputs = index, theano.Param(learning_rate, default=0.1)] | 318 | 318 | fn = theano.function(inputs=inputs, | 319 | | - outputs=cost, | 320 | | - updates=updates, | 321 | | - givens={self.x: train_set_x[batch_begin: | 322 | | - batch_end]}) | | 319 | + outputs=cost, | | 320 | + updates=updates, | | 321 | + givens={self.x: train_set_x[batch_begin: | | 322 | + batch_end]}) | 323 | 323 | # append `fn` to the list of functions | 324 | 324 | pretrain_fns.append(fn) | 325 | 325 |
| @@ -369,9 +369,9 @@ and a ``test_model`` function). | 369 | 369 | gparams = T.grad(self.finetune_cost, self.params) | 370 | 370 |
| 371 | 371 | # compute list of fine-tuning updates | 372 | | - updates = {} | | 372 | + updates = [] | 373 | 373 | for param, gparam in zip(self.params, gparams): | 374 | | - updates[param] = param - gparam*learning_rate | | 374 | + updates.append((param, param - gparam * learning_rate)) | 375 | 375 |
| 376 | 376 | train_fn = theano.function(inputs=[index], | 377 | 377 | outputs= self.finetune_cost, | |
Collapse file Copy file name to clipboardExpand all lines: doc/LICENSE.txt +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 3 | 3 | LICENSE | 4 | 4 | ======= | 5 | 5 |
| 6 | | -Copyright (c) 2008--2009, Theano Development Team | | 6 | +Copyright (c) 2008--2013, Theano Development Team | 7 | 7 | All rights reserved. | 8 | 8 |
| 9 | 9 | Redistribution and use in source and binary forms, with or without | |
Collapse file Copy file name to clipboardExpand all lines: doc/SdA.txt +4-4Lines changed: 4 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -249,7 +249,7 @@ during training we associate a Theano variable to them. | 249 | 249 | pretrain_fns = [] | 250 | 250 | for dA in self.dA_layers: | 251 | 251 | # get the cost and the updates list | 252 | | - cost,updates = dA.get_cost_updates(corruption_level, learning_rate) | | 252 | + cost, updates = dA.get_cost_updates(corruption_level, learning_rate) | 253 | 253 | # compile the theano function | 254 | 254 | fn = theano.function(inputs=[index, | 255 | 255 | theano.Param(corruption_level, default=0.2), | @@ -271,7 +271,7 @@ in mind when working with Theano. | 271 | 271 |
| 272 | 272 | In the same fashion we build a method for constructing function required | 273 | 273 | during finetuning ( a ``train_model``, a ``validate_model`` and a | 274 | | -``test_model`` funcion). | | 274 | +``test_model`` function). | 275 | 275 |
| 276 | 276 | .. code-block:: python | 277 | 277 |
| @@ -309,9 +309,9 @@ during finetuning ( a ``train_model``, a ``validate_model`` and a | 309 | 309 | gparams = T.grad(self.finetune_cost, self.params) | 310 | 310 |
| 311 | 311 | # compute list of fine-tuning updates | 312 | | - updates = {} | | 312 | + updates = [] | 313 | 313 | for param, gparam in zip(self.params, gparams): | 314 | | - updates[param] = param - gparam * learning_rate | | 314 | + updates.append((param, param - gparam * learning_rate)) | 315 | 315 |
| 316 | 316 | train_fn = theano.function(inputs=[index], | 317 | 317 | outputs=self.finetune_cost, | |
|