This post is an abstract of a Jupyter notebook containing a line-by-line example of a multi-task deep learning model, implemented using the fastai v1 library for PyTorch. This model takes in an image of a human face and predicts their gender, race, and age.

The notebook wants to show:

an example of a multi-task deep learning model; the multi-task model makes better predictions than the individual model; and how to use the fastai library to easily implement the model.

The Jupyter notebook is working and runnable, so you can run and change the code if you like (at least it’s fun to randomly sample faces — some of them you may recognize).

As an abstract, this post does not contain the code. Full notebook with code is here:

Multi-task learning

First, some quick introduction to multi-task learning.

What it is

wikipedia: Multi-task learning (MTL) is a subfield of machine learning in which multiple learning tasks are solved at the same time, while exploiting commonalities and differences across tasks.

In this post, multiple learning tasks are the three tasks to predict gender, race (both classification tasks), and age (a regression task), respectively.

Why do it

wikipedia: This can result in improved learning efficiency and prediction accuracy for the task-specific models, when compared to training the models separately.

In this post,

Regarding improved learning efficiency: we run the multi-task model once instead of three time for the single-task models (all four models have similar run time).

Regarding improved prediction accuracy: we will show that the multi-task model cut average age prediction error in half from 10 years to 5 years while holding the gender and race prediction accuracy almost the same.

Why it works

wikipedia: Multi-task learning works because regularization induced by requiring an algorithm to perform well on a related task can be superior to regularization that prevents overfitting by penalizing all complexity uniformly.

We will not cover the math here. Wikipedia provides some good resources.