Self-Organizing Maps with fast.ai
or: how I learned to stop worrying and love the SOM
Earlier this year, I started my coding journey in Machine Learning by taking the Practical Deep Learning for Coders course by Jeremy Howard. The part 2 of the course focused on how the basic moving pieces of the Fast.ai library are implemented.
As an exercise, I decided to develop and integrate a neural network architecture that wasn’t natively available inside the library.
My choice fell on Self-Organizing Maps, mainly because I feel they deserve more love, but also because I had to use them for some of my work projects and I wasn’t able to find an implementation that suited our needs.
As many SOM implementations didn’t have GPU support, batching and/or custom distance functions, I decided to start from there; I also wanted something that was as simple to use as the native Fast.ai APIs.
In the end, I had so much fun writing the code and seeing it work that I went overboard and I ended up with a set of ready-to-use tools and interpretation utilities.
In this series, I will go over the steps I took in building each component and wiring everything together.
I’m really happy with the final result, as it runs really fast and it turned out to be very simple to use and customize:
If you can’t wait or if you want to have a look at the final code, it can be found in this Github repository or as an installable package on PyPi.
Steps
- Step 1: Implementing a SOM with PyTorch
- Step 2: Training the SOM Module with a Fast.ai Learner (with loss functions)
- Step 3: Updating SOM hyperparameters with Fast.ai Callbacks
- Step 4: Handling unsupervised data with Fast.ai DataBunch
- Step 5: Interpretation on a trained Self-Organizing Map