This project presents a Transformer-based deep learning model capable of processing raw audio signals to classify classical music compositions into four distinct eras: Baroque, Classical, Romantic, and Modern.
Instead of traditional feature extraction methods, the project utilizes state-of-the-art "Pre-trained" audio models such as Wav2Vec2, HuBERT, and WavLM to predict the musical era directly from sound waves.
With the exponential growth of online multimedia content, automated classification of large-scale audio data has become crucial. This study aims to detect the musical era of a piece by analyzing its sonic characteristics (rhythm, harmony, instrumentation) using data collected from YouTube.
Five different models were fine-tuned and tested using the Hugging Face library:
| Model | Description |
|---|---|
| HuBERT Base | (facebook/hubert-base-ls960) - Learns hidden representations for robust feature extraction. |
| WavLM Base | (microsoft/wavlm-base) - Developed by Microsoft, highly resistant to noisy environments. |
| Wav2Vec2 Base | (facebook/wav2vec2-base-960h) - Effective in extracting meaningful representations from speech/audio signals. |
| Distil-Wav2Vec2 | (OthmaneJ/distil-wav2vec2) - A lighter and faster optimized version. |
| Wav2Vec2-KS | (superb/wav2vec2-base-superb-ks) - Optimized for Keyword Spotting tasks. |
The dataset was constructed by scraping YouTube using the pytube library.
- Source: YouTube (Baroque, Classical, Romantic, Modern era playlists).
- Size: Total of 21,437 audio files. Approximately 5,000 balanced samples per era.
- Format: Mono channel
.wavfiles resampled to 16 kHz. - Segmentation: Each piece was split into 15-second chunks for labeling.
Model performance was evaluated using Accuracy, F1-Score, Precision, Recall, and ROC AUC metrics.
- Training was conducted on Google Colab (T4 GPU).
- Confusion Matrices and Loss graphs were analyzed for each model.
- HuBERT and WavLM demonstrated superior performance in capturing the complex distinctions between musical eras.
To run this project locally:
-
Clone the repository:
git clone [https://github.com/omer-gulsoy/ML-ClassicalMusicEra.git](https://github.com/omer-gulsoy/ML-ClassicalMusicEra.git) cd ML-ClassicalMusicEra -
Install dependencies:
pip install torch transformers librosa pytube moviepy torchaudio numpy pandas
-
Data Collection (Optional): Run the
data_collection.pyscript (if available) to scrape new data from YouTube.
- Developer: Ömer Hasan GÜLSOY (Kocaeli University, Information Systems Engineering)
- Contributors: Ecem Su YILMAZ, Halit Mert ARTUN
- Advisor: Assoc. Prof. Dr. Zeynep Hilal KİLİMCİ
Special thanks to the open-source community and the musicians whose work inspired this project.
This project was developed for the 2024-2025 Introduction to Machine Learning Course.