Case Study

tiny-timbre

A CNN trained from scratch that listens to a 30-second song clip and predicts all of its genre tags, testing whether a graph neural network over the genre family tree helps. It didn't, and the reason why is the interesting part.

Timeline
November 2026
Context
Final group project, COMP 395: Deep Learning
Team
Me, Miranda, and Ayesha
Stack
Python, PyTorch, librosa, Weights & Biases

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.

Three rows of images. Each row starts with the input spectrogram for a hip-hop, rock, or classical clip, followed by six feature maps from the CNN's second block, each picking out different patterns of pitch and time.

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.

Scatter plot of test macro mAP against mean cosine similarity between sibling genres' detectors. The three flat-head runs sit at the top left, around 0.38 similarity and 20.4 to 20.9 points. The GCN runs sit lower and further right, around 0.67 to 0.82 similarity and 18.5 to 19.6 points.

There were exceptions. The GCN did better on Classical (+9.2 AP) and Blues (+6.3).

Bar chart of GCN minus flat average precision for each top-level genre. The GCN is better on Classical, Blues, Spoken, Instrumental, and Hip-Hop, and the flat head is better on Electronic, Soul-RnB, Jazz, Rock, Folk, Experimental, Pop, Country, and International.

What the Model Learned

Exploratory analysis.

Linear Probe

  • The song vector stores timbre (R² up to 0.70) much more than harmony (0.11–0.48).

Occlusion

  • Muting one frequency band at a time shows the model relies mostly on low-to-mid frequencies.
  • It uses the whole clip, not just the start.

My Role

What I Built

  • The spectrogram caching pipeline: 25k MP3s into an 8 GB float16 memory-mapped cache.
  • The CNN encoder and the model wiring.
  • The training loop, with W&B logging, best-epoch checkpointing, resumable runs, and test scoring.

What I Ran and Led

  • I ran and coordinated training on Colab T4 GPUs across the team's accounts.
  • I led the analysis: result tables, figures, and the gradient and feature-map diagnostics.

The Team

  • Miranda: labels, the genre graph, evaluation metrics, and the recommendation code.
  • Ayesha: the logistic-regression baseline and the GCN layer and head.

AI Use

  • Claude Code helped finish the analysis code, wrote the interpretability scripts at my request, and built the interactive recommendation demo (a Gradio web app) entirely.
  • The method, experiments, and conclusions are the team's.

Tools

Python, PyTorch, librosa, scikit-learn, Weights & Biases, Google Colab (T4 GPU), uv, pytest (90 tests), matplotlib, and Gradio.