This work has been completed by Peter Huang, Ryan Kim and Horatiu Lazu
The purpose of this project is to analyze and evaluate the performance of classical machine learning methods (decision trees, support vector regression, random forests, linear regression) along with Convolutional Neural Networks (CNNs) for predicting the trending year of a given song. We take existing research and open-source implementations for music genre classifiation, and by leveraging the techniques applied there we adapt and attempt to solve this different type of problem.
This repository includes the implementation and scripts used for reproducing the results outlined in the paper.
There are four components to this project.
- Training + Validation Dataset
- Convolutional Neural Network (CNN)
- Classical Machine Learning Models
- Basic scripts for bulk testing
We cover each part independently such to reproduce the results in the paper.
The dataset used for training was the Billboard Top 100 for the years 1960 to 2020. We obtained the .wav
files for the top 10 songs in each year, which provides sufficient training data for the models. The audio files are not included in this repository or in general due to copyright restrictions, but they were obtained legally for the purposes of this project.
The base implementation of this work was based on the music-genre-classification repository, with adaptions made to accomodate for not using a classifier, but instead regression. In order to install, the following must be done:
- Install Python3.8
- Install NumPy, SciPy along with PyTorch
Afterward, the repository found in convolutional_neural_network
that contains the required code.
In order to train the repository:
- Configure
config.py
to have the properDATAPATH
that points to the dataset's folder- Structure the folders such that each folder is enclosed in a folder named after its release year
- Invoke
python3 train.py
, which should train the model with the provided audio data fromDATAPATH
.
Note that the first time the script is run, we need to uncomment the following lines (14-18):
data = Data(GENRES, DATAPATH)
data.make_raw_data()
data.save()
data = Data(GENRES, DATAPATH)
data.load()
- We can then test the music release year prediction using the following command:
python3 ./get_genre.py <pathtofilename>
In the end, the expected classification for each chunk is outputted along with the final predicted year. For example:
~/hlazu/music-genre-classification/src$ /usr/bin/python3.8 get_genre.py ~/files/genres/2000/Savage\ Garden\ -\ I\ Knew\ I\ Loved\ You\ \(Official\ Video\)-jjnmICxvoVY.wav
29.9542179107666
44.364620208740234
44.00571060180664
21.105619430541992
31.873672485351562
37.884220123291016
43.597721099853516
41.68931198120117
...
42.107696533203125
43.88893127441406
37.91337585449219
36.08418655395508
13.254826545715332
10.613168716430664
Predicted: 1998.2867131171288
The predicted value at the end is the final answer. The intermediate values outputted are the number of years after 1960 that the model predicts for an individual chuns, as the model partitions songs into smaller chunks and takes the average to produce the final answer.
Classical Machine Learning Models (Linear Regression, Decision Tree, Random Forest, Support Vector Regression)
The original implementation for music genre classification was based on the gtzan repository. Each of the models in the original repository were changed to support regression rather than classification. The logstic regression was changed to linear regression, decision tree classification was changed to decision tree regression, random forest classification was changed to random forest regression, and support vector machine was changed to support vector regression.
- Install Python3.7
- Install Latest SKLearn, Pandas, IPython, NBConvert
In order to train the models:
- Go to the classical_models directory and invoke
python3 -m IPython train_classical_models.py
. This will extract the features from the songs in the music repository and create models for linear regression, decision trees, random forests, and support vector regression.
In order to run the models:
- We can then test the music year prediction using the following command:
/usr/bin/python3 app.py -t ml -m ../models/pipe_lr.joblib -s <path_to_song>
The final predicted year is outputted for the specified song.
2. The ../models/pipe_lr.joblib
can be modified to use decision trees (pipe_cart), random forest (pipe_rf), or support vector regression (pipe_svr)
Several helper scripts are included that facilitate bulk testing.
test.sh
expects the filepath for running the Python script to predict the genre- Note: it requires the final outputted statement to be in the format
Predicted: <ans>
- In addition, the location of the folders may need to be tweaked in line 24
- The result emitted includes:
results-csv.txt
which includespredicted_year,year
pairs in a CSVsum.txt
which includes a formula denoting the absolute value differences
- Note: it requires the final outputted statement to be in the format
calc.py
is used to interpret thesum.txt
andsum_den.txt
values (more specifically computing the file percentage)