license: mit
tags:
- music
pretty_name: FMA rank
size_categories:
- 100K<n<1M
What is FMA-rank?
FMA is a music dataset from the Free Music Archive, containing over 8000 hours of Creative Commons-licensed music from 107k tracks across 16k artists and 15k albums. It was created in 2017 by Defferrard et al. in collaboration with Free Music Archive.
FMA contains a lot of good music, and a lot of bad music, so the question is: can we rank the samples in FMA?
FMA-rank is a CLAP-based statistical ranking of each sample in FMA. We calculate the log-likelihood of each sample in FMA belonging to an estimated gaussian in the CLAP latent space, using these values we can rank and filter FMA. In log-likelihood, higher values are better.
Quickstart
Download any FMA split from the official github https://github.com/mdeff/fma. Extract the FMA folder from the downloaded zip and set the path to the folder in fma_root_dir
.
Run the following code snippet to load and filter the FMA samples according to the given percentages. The code snippet will return a HF audio dataset.
from datasets import load_dataset, Dataset, Audio
import os
# provide location of fma folder
fma_root_dir = "/path/to/fma/folder"
# provide percentage of fma dataset to use
# for whole dataset, use start_percentage=0 and end_percentage=100
# for worst 20% of dataset, use start_percentage=0 and end_percentage=20
# for best 20% of dataset, use the following values:
start_percentage = 80
end_percentage = 100
# load fma_rank.csv from huggingface and sort from lowest to highest
csv_loaded = load_dataset("disco-eth/FMA-rank")
fma_item_list = csv_loaded["train"]
fma_sorted_list = sorted(fma_item_list, key=lambda d: d['CLAP-log-likelihood'])
def parse_fma_audio_folder(fma_root_dir):
valid_fma_ids = []
subfolders = os.listdir(fma_root_dir)
for subfolder in subfolders:
subfolder_path = os.path.join(fma_root_dir, subfolder)
if os.path.isdir(subfolder_path):
music_files = os.listdir(subfolder_path)
for music_file in music_files:
if ".mp3" not in music_file:
continue
else:
fma_id = music_file.split('.')[0]
valid_fma_ids.append(fma_id)
return valid_fma_ids
# select the existing files according to the provided fma folder
valid_fma_ids = parse_fma_audio_folder(fma_root_dir)
df_dict = {"id":[], "score": [], "audio": []}
for fma_item in fma_sorted_list:
this_id = f"{fma_item['id']:06d}"
if this_id in valid_fma_ids:
df_dict["id"].append(this_id)
df_dict["score"].append(fma_item["CLAP-log-likelihood"])
df_dict["audio"].append(os.path.join(fma_root_dir, this_id[:3] , this_id+".mp3"))
# filter the fma dataset according to the percentage defined above
i_start = int(start_percentage * len(df_dict["id"]) / 100)
i_end = int(end_percentage * len(df_dict["id"]) / 100)
df_dict_filtered = {
"id": df_dict["id"][i_start:i_end],
"score": df_dict["score"][i_start:i_end],
"audio": df_dict["audio"][i_start:i_end],
}
# get final dataset
audio_dataset = Dataset.from_dict(df_dict_filtered).cast_column("audio", Audio())
"""
Dataset({
features: ['id', 'score', 'audio'],
num_rows: 1599
})
"""