You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jul 1, 2023. It is now read-only.
Add a helper function for sequential models. (#20)
Many deep learning models are composed of sequential layers stacked one on
top of each other. It can be relatively tedious to write out the explicit
`applied(to:)` function because it's fairly repetitive and the underlying
intent is relatively obscured. (It can be especially bothersome because
it's the 2nd (or 3rd) time you're writing out all the layers. (The first time
is to declare all the instance variables, and the second time (if necessary)
is in the initializer.)
Fortunately, with helper functions, we can make everything both type
safe as well as convenient and easily expressible & readable!
This commit adds a family of `sequenced(in:through:)` functions that take
in a context, an input, and a variable number of layers. It chains through the
output of one layer into the input of the next.
This API approach has a number of advantages:
1. It avoids introducing new symbolic operators, which can be very confusing
to new users.
2. It works with today's AutoDiff implementation. (Yay!)
3. It is very readable and clean.
4. It avoids users "getting stuck". Concretely, if someone implemented a model
using my previously proposed `>>>` operator, if they wanted to add a
residual (or skip) connection, they would have to basically re-write their
whole model using a struct, etc. With this API structure, only "local"
changes are required. (e.g. If only one skip-connection is required, they
can split the sequential chain into two pieces.)
Downsides of this approach:
1. It doesn't DRY-out the types required to define a model. (I have some
thoughts here, but there isn't enough room in this
margin^H^H^H^H^H^Hcommit message.)
2. We should think hard about how things should look when we have loops.
3. We should switch to gyb to generate the code for all the different arities.
0 commit comments