FluxML / FastAI.jl

Repository of best practices for deep learning in Julia, inspired by fastai
https://fluxml.ai/FastAI.jl
MIT License
589 stars 51 forks source link

Make block learning methods more modular #188

Closed lorenzoh closed 2 years ago

lorenzoh commented 2 years ago

Progress for tackling #165.

VAE notebook from @darsnack https://github.com/darsnack/fastai-vae-demo.

darsnack commented 2 years ago

I took a look over the updated notebook. The FastAI.jl hooks make sense to me, and it seems like the boilerplate has been reduced quite a bit from the original example. The only thing that's confusing for me is why EmbeddingMethod requires so many blocks (e.g. x, y, ŷ, sample, etc.). Maybe an explanation or comment in the code describing their purpose would help?

In terms of the tutorial aspect, I would add something at the start giving an overview of each piece of FastAI.jl that we will override/extend. Something like:

The FastAI.jl default methods and training loops are designed for supervised learning. To support our unsupervised approach, we will extend FastAI.jl by
- creating a data iterator over only the samples (no labels)
- defining our own block method, `EmbeddingMethod` (the analogue to `SupervisedMethod`)
- defining our own FluxTraining.jl phase, `VAETrainingPhase`, which will take the gradients with respect to our unsupervised loss correctly
lorenzoh commented 2 years ago

Thanks for the feedback! Planning to either (1) put the source for EmbeddingMethod into FastAI.jl itself or (2) make the definition shorter, using just a function with only the blocks needed for this tutorial, e.g.

function EmbeddingMethod(block, encodings)
    sample = block
    x = y\hat = encodedsample = FastAI.encodedblockfilled(encodings, block)
    return BlockMethod((; sample, x, y\hat, encodedsample), encodings)
end

With then some explanation what those blocks mean and maybe where they're needed (i.e. showoutputs needs y\hat). Would that make the part clearer?

darsnack commented 2 years ago

With then some explanation what those blocks mean and maybe where they're needed (i.e. showoutputs needs y\hat). Would that make the part clearer?

Yes, that makes it much clearer!