Passing lists into YAML files as variables

2,834 views
Skip to first unread message

Tom Szumowski

unread,
Mar 13, 2014, 5:00:34 PM3/13/14
to pylear...@googlegroups.com
I was looking at the "hyper_params" settings in the Softmax regression ipython notebook tutorial (link).
It's very convenient to pass in integers with %(var)i, or strings with %(var)s. But is it possible to pass in lists.

For example, I'd like to batch over various convolutional network configurations that modify the kernel size. The kernel is a length-2 array, i.e. [8, 8] as in the convnet tutorial.

For now I've been keeping to square kernels and pools and using a single integer variable. But I was curious for the future if there is a way to pass in a list.

-Tom

Mehdi Mirza

unread,
Mar 13, 2014, 5:07:56 PM3/13/14
to pylear...@googlegroups.com
Yes. You can pass lists using brackets []. Look for an example at this file: https://github.com/lisa-lab/pylearn2/blob/master/pylearn2/scripts/papers/maxout/mnist.yaml
In the tutorials we are suing yaml templates and fill-in the values, so that we can unit test the exact same model in a smaller scale. But templates are also useful, if you have a script that produce yaml file with different hyper-parameters. You can use %(var)s to pass the list as string in that case.


--
You received this message because you are subscribed to the Google Groups "pylearn-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pylearn-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Tom Szumowski

unread,
Mar 13, 2014, 9:53:57 PM3/13/14
to pylear...@googlegroups.com
I am able to have them work when explicitly assigned (like axes) in the YAML file. But I wasn't able to assign a variable (hyper_param) in a python script driver and have it passed in as a variable using %(var)i.

I didn't try %(var)s to pass in as a string. Good to know it figures out how to do the conversion to a list of ints from the string variable. I'll give it a shot. Thanks!

Vincent Dumoulin

unread,
Mar 14, 2014, 10:22:28 AM3/14/14
to pylear...@googlegroups.com
If you're interested in hyperparameter selection you might want to have a look at this blog post (shameless plug): http://vdumoulin.github.io/articles/pylearn2-jobman/. It goes a bit more into details on how to automate the process of launching several experiments using Pylearn2 and another tool we develop called Jobman.

----------------
Vincent Dumoulin


On Thu, Mar 13, 2014 at 9:53 PM, Tom Szumowski <tszum...@gmail.com> wrote:
I am able to have them work when explicitly assigned (like axes) in the YAML file. But I wasn't able to assign a variable (hyper_param) in a python script driver and have it passed in as a variable using %(var)i.

I didn't try %(var)s to pass in as a string. Good to know it figures out how to do the conversion to a list of ints from the string variable. I'll give it a shot. Thanks!

--

Ian Goodfellow

unread,
Mar 14, 2014, 10:31:20 AM3/14/14
to pylear...@googlegroups.com
Just to be clear, the string substitution here is not anything Pylearn2 specific. It's just Python's native string substitution. You can pass any kind of object to %s substitutions and Python will use the object's __str__ method to coerce it into a string.

>>> my_list = [1, 2, 3]
>>> "%(my_list)s" % locals()
'[1, 2, 3]'

>>> class A(object):
...     def __str__(self):
...             return str(id(self))
...
>>> "%s" % A()
'140684937632720'




Reply all
Reply to author
Forward
0 new messages