lmjohns3 / theanets

Neural network toolkit for Python
http://theanets.rtfd.org
MIT License
328 stars 74 forks source link

IPython compability #37

Closed kudkudak closed 9 years ago

kudkudak commented 9 years ago

The code doesn't work with IPython notebook due to argument parsing :( (IPython adds some arguments when calling python). Simple workaround would be to change parse_args to parse_known_args.

Reproducing: create any experiment inside IPython notebook.

lmjohns3 commented 9 years ago

Thanks for the report! Not working in IPython is definitely annoying. However, parsing known arguments is problematic because people might use theanets with additional arguments downstream.

I think what might work is just to wrap the parse_args code with an exception handler? That way if the parsing blows up, we can just assume the user is working in an environment like IPython and skip the argument parsing altogether. Thoughts?

kudkudak commented 9 years ago

Sure sounds like a good solution :) I don't think IPython user would like to pass arguments. However - in general - it seems passing any extra arguments will cause errors? If this is correct I think it might be better to parse arguments that are known and ignore unknown (for instance using parse_known_args)?

arogozhnikov commented 9 years ago

Hi, I upvote this issue. Opinion: I'd be happy just to have some function like 'ignore_python_arguments', because I can't anyway manipulate them in IPython.

lmjohns3 commented 9 years ago

I just checked in a quick change to avoid parsing arguments from within IPython. Please reopen if this does not fix the issue for you!

Also I anticipate moving much of this argument-parsing code into the climate package at some point, but that probably won't happen soon.

arogozhnikov commented 9 years ago

Hi, just copy-pasted into ipython notebook xor example, got this

INFO:theanets.main:runtime arguments:
I 2014-11-01 22:49:25 theanets.main:63 runtime arguments:
INFO:theanets.main:--layers = (2, 2, 1)
I 2014-11-01 22:49:25 theanets.main:65 --layers = (2, 2, 1)
INFO:theanets.main:--learning_rate = 0.1
I 2014-11-01 22:49:25 theanets.main:65 --learning_rate = 0.1
INFO:theanets.main:--momentum = 0.5
I 2014-11-01 22:49:25 theanets.main:65 --momentum = 0.5
INFO:theanets.main:--num_updates = 500
I 2014-11-01 22:49:25 theanets.main:65 --num_updates = 500
INFO:theanets.main:--patience = 300
I 2014-11-01 22:49:25 theanets.main:65 --patience = 300
INFO:theanets.feedforward:hidden activation: logistic
I 2014-11-01 22:49:25 theanets.feedforward:184 hidden activation: logistic
INFO:theanets.feedforward:output activation: linear
I 2014-11-01 22:49:25 theanets.feedforward:189 output activation: linear
INFO:theanets.feedforward:weights for layer 0: 2 x 2
I 2014-11-01 22:49:25 theanets.feedforward:343 weights for layer 0: 2 x 2
INFO:theanets.feedforward:weights for layer out_0: 2 x 1
I 2014-11-01 22:49:25 theanets.feedforward:343 weights for layer out_0: 2 x 1
INFO:theanets.feedforward:9 total network parameters
I 2014-11-01 22:49:25 theanets.feedforward:195 9 total network parameters
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
 in ()
     20                         momentum=0.5,
     21                         patience=300,
---> 22                         num_updates=500)
     23 e.run(train, train)
     24 
/Users/axelr/ipython/theanets/theano-nets/theanets/main.pyc in __init__(self, network_class, **overrides)
    103         kw = {}
    104         kw.update(self.kwargs)
--> 105         self._build_trainers(**kw)
    106 
    107     def _build_network(self, network_class, **kwargs):
/Users/axelr/ipython/theanets/theano-nets/theanets/main.pyc in _build_trainers(self, **kwargs)
    116         '''Build trainers from command-line arguments.
    117         '''
--> 118         if isinstance(self.args.optimize, str):
    119             self.args.optimize = self.args.optimize.strip().split()
    120         for factory in self.args.optimize:
AttributeError: 'Namespace' object has no attribute 'optimize'
lmjohns3 commented 9 years ago

Yes, this happens because within IPython (i.e., without processing the argparse flags) there is no longer a default value for any of the model or optimization parameters. Either you need to pass an explicit value for required parameters such as optimize, or we'll need to copy the default values from flags.py into main.py for folks who use IPython. I'd be ok with it either way, any comments?

lmjohns3 commented 9 years ago

I went ahead and just set a default value for this one parameter. We can reopen this if there are other parameters that need defaults.