The Question
Music genres form a family tree, with broad genres at the top and subgenres underneath. We wanted to
know whether a model that tags songs by genre does better when it knows that tree. So we trained a
CNN from scratch and compared two ways of turning what it hears into genre predictions: one that
treats every genre separately, and one that uses a graph neural network over the genre tree.
We used FMA-medium: 25,000 clips and 97 genres after filtering. Each song can have several tags, and
the splits are filtered by artist, so no artist appears in both training and test.
Every prediction was committed to git before the experiment ran, so the timestamps show what we
expected before we saw any results. You can read them in
HYPOTHESES.md.
How It Works
Audio to Spectrogram
- Each MP3 becomes a log-mel spectrogram (128 × 1292), a picture of which frequencies are
loud at each moment of the clip.
CNN Encoder
- A 4-block CNN (~389k parameters) compresses the spectrogram into a 256-number song vector.
Two Heads, Compared
- Flat head: a linear layer with one detector per genre.
- GCN head: built from scratch, it constructs each genre's detector from its
neighbours in the genre tree.
Recommendations
- The same song vectors power a nearest-neighbour music recommendation prototype.
What the CNN sees: a hip-hop, rock, and classical clip, with feature maps from the second block.
Results
All scores are macro mAP on the test set. The head comparison was run with 3 seeds each.
- 0.207CNN + flat head, vs. 0.164 for logistic regression on hand-made audio features.
- 0.187GCN head (± 0.004), vs. 0.207 ± 0.002 for the flat head. The graph made it worse.
- 0.307Recommendation genre overlap@10 for the flat head, vs. 0.301 GCN, 0.230 hand-made features, 0.067 random.
The CNN clearly beat the hand-made-features baseline. But the genre tree hurt, mostly on rare and
fine-grained genres.
Why the Graph Didn't Help
The answer is over-smoothing. The GCN makes sibling genres' detectors nearly
identical: their average cosine similarity is 0.82, vs. 0.38 for the flat head. If two subgenres
have almost the same detector, the model can't tell them apart. Across every run, more similarity
meant a lower score.
Each point is one trained model. Further right means more over-smoothed; higher means a better score.
There were exceptions. The GCN did better on Classical (+9.2 AP) and Blues (+6.3).
Tools
Python, PyTorch, librosa, scikit-learn, Weights & Biases, Google Colab (T4 GPU), uv, pytest
(90 tests), matplotlib, and Gradio.