-
Notifications
You must be signed in to change notification settings - Fork 948
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Modify examples to be simpler #215
Comments
I'm inclined to agree, we may have gone overboard cleaning them up a bit in the past (they used to be simpler before, e.g. 98f2ee7). It might be better to dial that back a little and cut some corners in the interest of immediate clarity of the code, since the main purpose of the examples is to quickly show people how to get things done, after all. While all the functions are a good idea in practice, they do obscure the flow a bit. One downside is that this will complicate testing of the examples. We currently have tests that run each example for 1 epoch to ensure everything still works. With scripts like this one, this is impossible (unless we make it accept command line arguments which in turn complicates the example again). I wonder if there's a way around this. |
Just thinking out loud here, but wouldn't it be an idea to move usage examples of Lasagne into another repository within the Lasagne organization? This would further reduce the scope of this library while also simplify test coverage. |
We don't have to cut it back that far. Having a The only reason why we would want those indirections is to share code between the four examples (one for an MLP, three for CNNs), but the current examples are still a pretty complete failure at sharing code. What if we strip that back to a single
I think a big downside of the current example is that it requires transferring everything at once. If I recall correctly, several users have asked how to bypass this. Your example is both easier to understand and easy to extend to large datasets. In the long term, we'd need to include (or refer to) a real tutorial handling different ways of handling the input data, but for now I'd say your style is suited better. |
Hmm, that would be an option. Currently we need it within the repository so we can keep the examples in sync with API-breaking changes, and I think good manners dictate providing an example directly with the library, but we could have a separate repository for reproducing results of some popular papers on some popular datasets, for example. |
That sounds like an excellent idea, and it mirrors how I use the library in practice (with config files describing the model architecture that are actually Python modules). |
Same here :) |
On Mo, Apr 20, 2015 at 12:35 , Jan Schlüter notifications@github.com
I usually try to avoid having functions with a lot of lines: they I think there's ultimately a lot of DRY code in those examples that So I guess the deeper problem behind the examples is that that they are
|
Agreed, but as long as there is no training loop code in the library there is no way that's going to happen. Coincidentally I spent some time last week setting up a bit of an experimentation framework, parts of which could probably be added to the library for this purpose. But I don't think we should start working on that until after the first release is out. |
No, I think that's necessary. Lasagne is just a collection of tools to make it easier to setup Theano graphs and update expressions for neural networks, and you have to go through and understand the 200+ lines of example code if you want to apply it to your own problem. Splitting it up into separate functions is good if it helps understanding the example, I'm definitely not against it, but currently I'm afraid it's making things more complicated and should be left to the individual users. A compromise might be providing an everything-in-one-place example and then an aiming-at-reusability example as a refactored version of the former. That way there's one for people to read and understand (with little cognitive overhead), and one for people to copy as a starting point if they like the suggested refactoring. If there's just a well-engineered usage example, I'd spend half of the time figuring out what the flat code equivalent would be so I can a) see what the example code does and b) understand the software design decisions of the example and whether they're the same for my task or need a different approach.
This is what's solved by higher-level wrappers such as your
I've got one as well, it's really nice and modular, but not finished enough to publish yet. I'm not sure if we can add bits of that to Lasagne, though, I think that would be somewhat outside the scope.
Great! Glad to see you again, by the way! |
On Mi, Apr 22, 2015 at 4:44 , Jan Schlüter notifications@github.com
The question about the scope of Lasagne is an interesting one. Is it a The question remains whether Lasagne also wants to be attractive to
Thanks. :-) |
I've added this to the First Release milestone since I think it would be a good idea to address this in time for the first release. |
Excellent, if no one else wants to do this, I can do it this weekend. My summary of the conversation:
|
Great! I'd only include fully-connected and convolutional, the others don't really add anything. If we want to point users at the other convolution implementations, that could just be done in a comment. |
I think the current cuda-convnet / cudnn examples are actually somewhat valuable, at least until we have a guide explaining how to use the different convolution implementations (the |
But wouldn't it be better to document that in the comments of the example? I.e., when creating the Conv2DLayer, explain that you can force alternative implementations to be used via one of the other classes? Giving three examples that look almost the same could be more confusing than enlightening. |
That also works :) |
Now that IPython notebooks are rendered inline on GitHub, maybe we should consider this format for our examples instead? Or at least in addition to :) The idea is to eventually have a ton of examples implementing all kinds of different layer types / nonlinearities / architectures from literature (like the highway layer @ebenolson just wrote: https://gist.github.com/ebenolson/4c223b8e2d72b0e35bde), and I guess notebooks would be a great format for that. |
I think it's a good idea. Notebooks are great for tutorials since you can have output and plots interspersed with the code. |
A few negatives:
|
The testing is a great point. I wonder if there are any tools for that yet, because it should be perfectly possible to test a notebook (at least to test that no errors are thrown and that certain cells give the correct output, or something). EDIT: relevant reading: http://stackoverflow.com/questions/20483313/testing-ipython-notebooks |
This package might be a possible solution: https://github.com/zonca/pytest-ipynb |
That looks like it helps you write tests in IPython notebooks though, which is not exactly what we want. Rather, we want to write examples in IPython notebooks, and then test whether they can run without errors (which is something we already do with our current, file-based examples). I think this may be closer to what we need: https://gist.github.com/minrk/2620735 |
I made an IPython notebook example of my highway networks implementation: https://github.com/Lasagne/Lasagne/blob/highway_example/examples/Highway%20Networks.ipynb I actually started working on this when the paper appeared on r/machinelearning, and a little later @ebenolson posted an implementation in Lasagne as well. My version actually didn't work at the time because of #104, but luckily it does now :) I put it in a branch but I haven't made a PR, I'm not sure what to do with it. Maybe it's a little too specialized to have it among the examples bundled with the library, but I like how it showcases the extensibility of the library. |
Haven't taken a look at the code yet, but I think we could well create some subdirectories under |
By the way, @diogo149 are you still up for doing this? If not, does anyone else want to take a stab at it? |
I'd be interested in working on this, but I won't have a chance till sometime next week. -----Original Message----- By the way, @diogo149 are you still up for doing this? If not, does anyone else want to take a stab at it? |
Sure, we can wait a few more days :) As long as we don't have any double work happening, that would be unfortunate! I'd wait to hear first if @diogo149 is still interested in doing it, since he proposed it. By the way, I did another one: https://github.com/Lasagne/Lasagne/blob/highway_example/examples/Hidden%20factors.ipynb This is a reproduction of one of the experiments from Discovering Hidden Factors of Variation in Deep Networks by Cheung et al., from ICLR 2015. It's a nice demonstration of how to use Unfortunately I'm not able to achieve the same classification accuracy as in the paper (there's probably some detail I'm missing), but the resulting reconstructions do look very similar to what's in the paper. Scroll all the way down for some cool images! |
How about a different repository inside the Lasagne org for notebooks? |
I guess 'recipes' works for me (especially if we're keeping the basic examples in the main repo and we're not renaming that subdirectory :p). It's probably more inviting for users also to send us their 'recipes' rather than their 'examples'. |
Sure, that should still be
Yes, don't underestimate that. I think our package name was quite important as well :) |
I'm going to go ahead and set this up. If there is any further discussion about the name we can always rename it later, but I think "recipes" is probably a winner :) EDIT: here we go https://github.com/Lasagne/Recipes now to have a think about the directory structure, I guess. Also the notebooks I've done so far depend on the |
On all of the example code or just a small part of it? I guess we can have some |
Agree. I can probably just strip out the dependency as well, but it was nice to not have to include the data loading etc. in the notebooks. |
I think it's a good idea to make the basic examples self-contained. It's easier to understand, and the interdependence creates potential for confusion (for example, currently |
Yes, the basic example in the |
Just a thought, maybe for Recipes we can accept both example code as well as implementations of new techniques (layers, update rules, ...) that aren't necessarily "executable" by themselves. That way it can also double as a repository for contributed code that doesn't fit in the main library. We could create a separate repo for this, but I have a feeling that there will be a lot of overlap and people will be confused about which repo their stuff belongs in. Lots of examples will also implement custom layers anyway. As for the organisation of the repo: having a subdirectory for each example is probably the safest bet. We could technically put single-file examples in the top level directory, but if those examples are then modified later and grow to multiple files we'd have to move them into subdirectories anyway. Comments are welcome, in the meantime I'll start populating the repo a bit in the next few days, I think. |
We could have two or three different categories that make up the first subdirectory level, and subdirectories under those that are the separate contributions. Possible categories: |
I guess that works, although I wouldn't overdo it with the names in this case. |
Okay. We just need to figure out a clean way to import snippets, if we want to use it both for "things to copy/paste into your code if you need them" and "things we need in multiple recipes and don't want to copy/paste".
Other ideas? It's probably just a few things like the MNIST data download/reading code and maybe some layer implementations that could be shared between multiple tutorials or papers and tutorials, but still. I'd try to keep this as a simple collection of directories, not an installable module. |
I feel like that MNIST loading code doesn't belong in 'snippets' though... I see that more as a repository for library extensions (new layers, update functions, etc.), data loading boilerplate doesn't really belong there imo. |
I like this - I have a handful of stuff that could go into I feel like there should be a separation though between examples/tutorials which it should be a priority to keep bug-free, and other stuff which might not be so actively maintained. |
There will still be a bunch of (tested) examples bundled with the library. This repo would be for contributed content. Which potentially includes examples and tutorials, but it would be okay for those not to be as well-tested. |
Ah ok so this repo is the distinction :) So is the plan still to rewrite the |
I'm not sure to be honest. If we have a bunch of recipes in the form of notebooks it might not be necessary. Some people might also not be familiar with the notebook format. Also a requirement would be that we can still test them like we currently do, I don't think that discussion was resolved. |
I think it could be both. We could have yet another subdirectory
As Sander said, not for the Lasagne repository, but possibly for the Recipes repository. |
Does anybody else want to take the lead on this, and on populating the Recipes repository as well (I'll give you commit rights)? I'm moving abroad in a few weeks and I need to finish up my dissertation, so I don't have much time to spare for Lasagne at the moment. |
I'm good with co-maintaining the main repo for now. Anybody else interested in maintaining the Recipes? @craffel? @ebenolson?
|
Yes please! |
I'll try to get some of my code ready for Recipes this week, but I'm a bit short on time right now as well. I could take care of responding to PRs there though. |
What's the deadline then?
Sounds great! |
The deadline is three weeks ago :) I don't know, I guess there is no deadline. Just sooner rather than later, preferably. There's not a lot left to do, cleaning up the examples and sorting out the regularization docs are the main things. And wrapping up the default nonlinearity discussion, I guess. |
@ebenolson you should now have read/write access to the Recipes repository. Let me know if it doesn't work because I'm not sure I set it up correctly... |
I'm curious if other people would be interested in having examples in this fashion: https://github.com/enlitic/lasagne4newbs/blob/master/mnist_conv.py. I've found the existing examples to be a little confusing to people new to Lasagne, and made that version to help them out. I think the biggest downside would be teaching slightly less than optimal practices (specifically not transfering a large amount of input data to the GPU at once).
The text was updated successfully, but these errors were encountered: