Self-Supervised Contrastive Learning of Music Spectrograms
Songs on the Billboard Year End Hot 100 were collected from the years 1960-2020. This list tracks the top songs of the US market for a given calendar year based on aggregating metrics including streaming plays, physical and digital purchases, radio plays, etc. In total the dataset includes 5737 songs, excluding some songs which could not be found and some which are duplicates across multiple years. It’s worth noting that the types of songs that are able to make it onto this sort of list represent a very narrow subset of the overall variety of the US music market, let alone the global music market. So while we can still learn some interesting things from this dataset, we shouldn’t mistake it for being representative of music in general.
Raw audio files were processed into spectrograms using a synchrosqueeze CWT algorithm from the ssqueezepy python library. Some additional cleaning and postprocessing was done and the spectrograms were saved as grayscale images. These images are structured so that the Y axis which spans 256 pixels represents a range of frequencies from 30Hz – 12kHz with a log scale. The X axis represents time with a resolution of 200 pixels per second. Pixel intensity therefore encodes the signal energy at a particular frequency at a moment in time.
The full dataset can be found here: https://www.kaggle.com/tpapp157/billboard-hot-100-19602020-spectrograms
A 30 layer ResNet styled CNN architecture was used as the primary feature extraction network. This was augmented with learned position embeddings along the frequency axis inserted at regular block intervals. Features were learned in a completely self-supervised fashion using Contrastive Learning. Matched pairs were taken as random 256x1024 pixel crops (corresponding to ~5 seconds of audio) from each song with no additional augmentations.
Output feature vectors have 512 channels representing a 64 pixel span (~0.3 seconds of audio).
The entirety of each song was processed via the feature extractor with the resulting song matrix averaged across the song length into a single vector. UMAP is used for visualization and HDBSCAN for cluster extraction producing the following plot:
Each color represents a cluster (numbered 0-16) of similar songs based on the learned features. Immediately we can see a very clear structure in the data, showing the meaningful features have been learned. We can also color the points by year of release:
Points are colored form oldest (dark) to newest (light). As expected, the distribution of music has changed over the last 60 years. This gives us some confidence that the learned features are meaningful but let’s try a more specific test. A gradient boosting regressor model is trained on the learned features to predict the release year of a song.
The model achieves an overall mean absolute error of ~6.2 years. The violin and box plots show the distribution of predictions for songs in each year. This result is surprisingly good considering we wouldn’t expect a model get anywhere near perfect. The plot shows some interesting trends in how the predicted median and overall variance shift from year to year. Notice, for example, the high variance and rapid median shift across the years 1990 to 2000 compared to the decades before and after. This hints at some potential significant changes in the structure of music during this decade. Those with a knowledge of modern musical history probably already have some ideas in mind. Again, it’s worth noting that this dataset represents generically popular music which we would expect to lag behind specific music trends (probably by as much as 5-10 years).
Let’s bring back the 17 clusters that were identified previously and look at the distribution of release years of songs in each cluster. The black grouping labeled -1 captures songs which were not strongly allocated to any particular cluster and is simply included for completeness.
Here again we see some interesting trends of clusters emerging, peaking, and even dying out at various points in time. Aligning with out previous chart, we see four distinct clusters (7, 10, 11, 12) die off in the 90s while two brand new clusters (3, 4) emerge. Other clusters (8, 9, 15), interestingly, span most or all of the time range.
We can also look at the relative allocation of songs to clusters by year to get a better sense of the overall size of each cluster.
So what exactly are these clusters? I’ve provided links below to ten representative songs from each cluster so you can make your own qualitative evaluation. Before going further and listening to these songs I want to encourage you loosen your preconceived notions of musical genre. Popular conception of musical genres typically includes non-musical aspects like lyrics, theme, particular instruments, artist demographics, singer accent, year of release, marketing, etc. These aspects are not captured in the dataset and therefore not represented below but with an open ear you may find examples of songs that you considered to be different genres are actually quite musically similar.
Cluster 0
- Manfred Mann's Earth Band - Blinded By The Light
- Elvis Presley - Bossa Nova Baby
- Blondie - Rapture
- The O'Jays - For the Love of Money
- Stray Cats - Stray Cat Strut
- Orleans - Still the One
- Babyface - When Can I See You
- Color Me Badd - All 4 Love
- Omarion - O
- Hootie & The Blowfish - Only Wanna Be with You
Cluster 1
- David Guetta - Turn Me On
- Kelly Clarkson - Stronger
- Pitbull - International Love
- Soulja Boy - Kiss Me Thru The Phone
- Soul II Soul - Keep On Movin'
- Black Box - Strike It Up
- Pitbull - Timber
- Black Eyed Peas - Don't Lie
- Lil Wayne - She Will
- Paula Abdul - Rush Rush
Cluster 2
- Tara Kemp - Hold You Tight
- Allure - All Cried Out
- Nelly Furtado - I'm Like A Bird
- 3OH!3 - My First Kiss
- WALK THE MOON - Shut Up and Dance
- Third Eye Blind - Never Let You Go
- P!nk - Stupid Girls
- Ellie Goulding - Burn
- Dua Lipa - Break My Heart
- Charlie Puth - Attention
Cluster 3
- Migos - Stir Fry
- Ludacris - Get Back
- Waka Flocka Flame - No Hands
- Baby Bash - Cyclone
- Yung Joc - I Know You See It
- DJ Snake - Taki Taki
- Migos - Bad and Boujee
- Miguel - Sky Walker
- Nelly - Hot In Herre
- Case - Touch Me Tease Me
Cluster 4
- Desiigner - Panda
- Chris Brown - Turn Up the Music
- Stevie B - Dream About You
- John Legend - Green Light
- Eve - Let Me Blow Ya Mind
- Mariah Carey - Touch My Body
- Jordin Sparks - One Step At a Time
- Surf Mesa - ily
- Drake - Jumpman
- Khalid - Better
Cluster 5
- Barbra Streisand - The Main EventFight
- Peaches & Herb - Close Your Eyes
- Air Supply - The One That You Love
- Brian Hyland - Itsy Bitsy Teenie Weenie Yellow Polka Dot Bikini
- Carrie Underwood - Inside Your Heaven
- LeAnn Rimes - How Do I Live
- Journey - Don't Stop Believin'
- Rihanna - Cheers
- Blues Traveler - Run-Around
- Phil Collins - Something Happened on the Way to Heaven
Cluster 6
- NSYNC - Bye Bye Bye
- Eve 6 - Here's to the Night
- Nickelback - Gotta Be Somebody
- A Flock Of Seagulls - I Ran
- Nickelback - If Everyone Cared
- Stevie Nicks - Talk to Me
- The Temptations - The Way You Do The Things You Do
- Billy Joel - It's Still Rock and Roll to Me
- Huey Lewis & The News - I Want A New Drug
- Default - Wasting My Time
Cluster 7
- New Edition - If It Isn't Love
- Leif Garrett - I Was Made for Dancin'
- James Taylor - You've Got a Friend
- Three Dog Night - Mama Told Me
- The Cars - You Might Think
- Chicago - Feelin' Stronger Every Day
- Alice Cooper - I Never Cry
- Ringo Starr - No-No Song
- James Taylor - Fire and Rain
- Richard Marx - Endless Summer Nights
Cluster 8
- J. Frank Wilson & The Cavaliers - Last Kiss
- Lou Christie - Two Faces Have I
- Herman's Hermits - Can't You Hear My Heartbeat
- Colbie Caillat - Fallin' For You
- Ciara - Promise
- Van Halen - Can't Stop Lovin' You
- Bobby Lewis - One Track Mind
- Luke Bryan - Country Girl
- Three Dog Night - One
- Kool & The Gang - Cherish
Cluster 9
- Edwin McCain - I'll Be
- Alan Jackson - It's Five O'Clock Somewhere
- The Capris - There's A Moon Out Tonight
- Manfred Mann - The Mighty Quinn
- The Paris Sisters - I Love How You Love Me
- Tim McGraw - Live Like You Were Dying
- David Lee Roth - California Girls
- Linda Ronstadt - Ooh Baby Baby
- Chicago - Colour My World
- Thompson Twins - King For A Day
Cluster 10
- Roberta Flack - Making Love
- Bobby McFerrin - Don't Worry Be Happy
- Vanessa Williams - Colors Of The Wind
- George Benson - On Broadway
- George Michael - Praying for Time
- Alive 'N Kickin' - Tighter, Tighter
- Cher - Bang Bang
- Hot Butter - Popcorn
- Wilson Pickett - Funky Broadway
- Gary Wright - Love Is Alive
Cluster 11
- Cyndi Lauper - True Colors
- David Rose - The Stripper
- Starland Vocal Band - Afternoon Delight
- The Cufflinks - Tracy
- Celine Dion - Where Does My Heart Beat Now
- Tommy James & The Shondells - Mony Mony
- Jimmy Soul - If You Wanna Be Happy
- Cher - If I Could Turn Back Time
- The Manhattan Transfer - Boy From New York City
- Little Peggy March - I Will Follow Him
Cluster 12
- Don Henley - The Boys Of Summer
- Harold Melvin & The Blue Notes - Wake up Everybody
- Culture Club - Do You Really Want To Hurt Me
- Kris Kristofferson - Why Me
- Larry Verne - Mr. Custer
- Matt Monro - My Kind of Girl
- The Four Preps - More Money For You and Me
- Lou Rawls - Your Good Thing
- Richard Harris - MacArthur Park
- Rocky Burnette - Tired of Toein' the Line
Cluster 13
- R.E.M. - Stand
- The Irish Rovers - The Unicorn
- Tom Jones - What's New Pussycat
- Elton John - Can You Feel The Love Tonight
- Chesney Hawkes - The One and Only
- Dion - Lovers Who Wander
- Ray Stevens - Misty
- Lee Dorsey - Working in the Coal Mine
- Charles Wright & The Watts 103rd Street Rhythm Band - Express Yourself
- Gary Puckett & The Union Gap - Young Girl
Cluster 14
- U2 - Desire
- Prince - 1999
- Tom Petty and the Heartbreakers - You Got Lucky
- New Edition - Cool It Now
- Blondie - Call Me
- Gnarls Barkley - Crazy
- James Brown - Cold Sweat
- Boyz II Men - Motownphilly
- Michael Jackson - Billie Jean
- Digable Planets - Rebirth Of Slick
Cluster 15
- Jimmy Jones - Good Timin'
- Emeli Sande - Next To Me
- Kyu Sakamoto - Sukiyaki
- Puddle Of Mudd - Blurry
- Sean Paul - Get Busy
- Black Eyed Peas - Rock That Body
- Four Tops - Baby I Need Your Loving
- Miranda Lambert - Bluebird
- The Beach Boys - California Girls
- Calvin Harris - Slide
Cluster 16