Fastai v2 daily code walk-thrus

Where will the link be shared?

Here on this forum post

2 Likes

Added zoom link to top thread: https://zoom.us/j/694153329

5 Likes

I’m not sure if I will be able to make it to the walk-through.

Here are a couple of things I tried in code as I was working through 01_core. I don’t fully understand what is happening, but I feel that this is okay. The learning experience was in trying these out.

As it turns out, class is of type type! And type is of type type. Trying to explain this can be quite a tongue twister.

It seems to be type all the way down.

image

It seems we can create a type, which is really another name for a class (doing class Something(): pass is just syntactic sugar for using type?). In the process we get a class that we can use as we would use a regular class… that is instantiate objects using it.

Here is a nice blog post on this.

image

Metaclasses are maybe inheritance for types? And type is something that is really a class… but it’s more like we are peaking behind the curtain. Maybe it let’s you play with things you would normally not have access to if you were using classes.

Here we seem to be creating a type but type is really a class… we know that now. What is important here are the __new__ and __init__ methods - they look very familiar to how we were defining a type (really a class) above using type. And if you instantiate an object from a class, or a type from a metaclass (huh?) these two methods will get called. That is the important bit.

Maybe a metaclass is just a specific type of class that can be used as a metaclass? :thinking:

But wait, there is more!

image

You can create a method adding it to dct. And it will live on the class, but sort of like a static method without a mechanism for passing in the class. So you can pass whatever you’d like.

But if you instantiate the class, it will work like a regular instance method. Phew.

image

And here we see that without using metaclasses, __new__ and __init__ still get called. But it seems they are a less powerful variety in terms of what we have access to than if we were defining a type? (a metaclass?).

Sure, let’s just go crazy!

And if this isn’t enough, to top it all, here is a decorator taking in an argument:

image

And here is quite a nice article explaining how to use decorators.

14 Likes

@radek this is great - all spot on :slight_smile:

1 Like

Added youtube link: https://www.youtube.com/watch?v=44pe47sB4BI

5 Likes

It was a great session… thank you Jeremy.

However i would want to watch it again, do you plan to share the recording.

2 Likes

That was really something; feels like we’re seeing the start of a new way to develop software. Here’re some notes I was able to jot down. Maybe pooling the community’s notes will make a good starting point for documentation later on.

  • notebook 01 is the most complicated because it starts with metaclasses and monkeypatching and a lot of other utilities. Starting there would be a very enthusiastic approach.

  • nb 08 is a tutorial notebook ← recommended start here

  • local.imports is the only python module created manually — not by notebook.

  • any class w/ a .show method is something that can be used by the fastAI transformation system (universal)

  • output type annotations cast data into the specified type → used to ensure certain behavior

6 Likes

The recording is here: https://youtu.be/44pe47sB4BI?t=251

6 Likes

Output type annotations are my favorite so far. I plan to write something about literate programming since that caught my interest and is a major aspect of this revision.

Also, I’m interested in whatever we can know about the planned book such as:

(1) Will it be freely available online or a paid product or some combination
(2) Will it be in a traditional “book” (written text) format or an interactive format
(3) Opportunities to contribute?

It will be an O’Reilly book.

2 Likes

@jeremy do you think if people put questions over here during future walk-thrus, you would answer it? Similar to how the courses were set up?

does fastai have an animal or will the cover be a random one from O’Reilly’s zoo? (important questions here) :grinning:

2 Likes

If it has an animal, it should be “fast”. Like a cheetah. Or peregrine falcon.

Although… blue wildebeests reach about 50 mph. An enticing option.

(I just realized: “swift” for tensorflow. There is a definite theme.)

1 Like

It would be easier if you can put questions in the zoom chat.

https://www.amazon.com/Deep-Learning-Coders-fastai-PyTorch/dp/1492045527

17 Likes

Is that a tench?

5 Likes

It is a Boarfish, which is notable for being deeper than it is long :slight_smile:

17 Likes

The walk-thru format seems to be working great :slight_smile: Thank you so much Jeremy for doing this!

Here is what I learned on decorators today:
image
Oh no, we are losing the name! Along with it we would also lose the docstring, argument list, etc.

But fear not for functools.wraps is here!

image

Here is more information on this.

6 Likes

Thank you Jeremy, the walk-tru was great (around midnight from France but so worth it!)

The literate programming approach, with Jupyter as the editor + scripts to translate to .py and docs, is very interesting and quite different from what I know.
It’s illuminating to learn such a different way of coding.
Do you plan to describe in depth the development process and the tools you used? Will it be part of the book?

2 Likes