Skip to main content

A library for computing Frechet Music Distance.

Project description

Frechet Music Distance

Table of Contents

Introduction

A library for calculating Frechet Music Distance (FMD). This is an official implementation of the paper Frechet Music Distance: A Metric For Generative Symbolic Music Evaluation.

Features

  • Calculating FMD and FMD-Inf scores between two datasets for evaluation
  • Caching extracted features and distribution parameters to speedup subsequent computations
  • Support for various symbolic music representations (MIDI and ABC)
  • Support for various embedding models (CLaMP 2)(TODO: CLaMP 1)
  • Support for various methods of estimating embedding distribution parameters (TODO)
  • Computation of per-song FMD to find outliers in the dataset (TODO)

Installation

The library can be installed from from PyPi using pip:

pip install frechet-music-distance

or directly from source by cloning the repository and installing it locally:

git clone https://github.com/jryban/frechet-music-distance.git
cd frechet-music-distance
pip install -e .

The library was tested on Linux and MacOS, but it should Work on Windows as well.

Usage

The library currently supports MIDI and ABC symbolic music representaions.

Note: When using ABC Notation please ensure that each song is located in a separate file

Command Line

fmd [-h] [--model {clamp2,clamp}] [--reference_ext REFERENCE_EXT] [--test_ext TEST_EXT] [--inf]
                              [--steps STEPS] [--min_n MIN_N] [--clear-cache]
                              <reference_dataset> <test_dataset>

Positional arguments:

  • reference_dataset: Path to reference dataset
  • test_dataset: Path to test dataset

Options:

  • --model {clamp2,clamp}, -m {clamp2,clamp} Embedding model name
  • --reference_ext, -r REFERENCE_EXT Music file extension in referene dataset (e.g. .midi). The program will automatically ifer this if not provided
  • --test_ext, -t TEST_EXT Music file extension in test dataset (e.g. .midi). The program will automatically ifer this if not provided.
  • --inf Use FMD-Inf extrapolation
  • --steps, -s STEPS Number of steps when calculating FMD-Inf
  • --min_n, -n MIN_N Mininum sample size when calculating FMD-Inf (Must be smaller than the size of test dataset)

Cleanup

Additionaly the pre-computed cache can be cleared by executing:

fmd --clear-cache

Python API

Standard FMD score

from frechet_music_distance import FrechetMusicDistance

metric = FrechetMusicDistance()
score = metric.score(
    reference_dataset="<reference_dataset>",
    test_dataset="<test_dataset>"
)

FMD-Inf score

from frechet_music_distance import FrechetMusicDistance

metric = FrechetMusicDistance()
result = metric.score_inf(
    reference_dataset="<reference_dataset>",
    test_dataset="<test_dataset>",
    steps=<num_steps> # default=25
    min_n=<minumum_sample_size> # default=500
)

result.score   # To get the FMD-Inf score
result.r2      # To get the R^2 of FMD-Inf linear regression
result.slope   # To get the slope of the regression
result.points  # To get the point estimates used in FMD-Inf regression

Cleanup

Additionaly the pre-computed cache can be cleared like so:

from frechet_music_distance import FrechetMusicDistance

metric = FrechetMusicDistance()
metric.clear_cache()

Supported Models

Model Name in library Description Creator
CLaMP2 clamp2 CLaMP 2: Multimodal Music Information Retrieval Across 101 Languages Using Large Language Models sanderwood

Citation

If you use Frecheet Music Distance in your research, please cite the following paper:

@article{retkowski2024frechet,
  title={Frechet Music Distance: A Metric For Generative Symbolic Music Evaluation},
  author={Retkowski, Jan and St{\k{e}}pniak, Jakub and Modrzejewski, Mateusz},
  journal={arXiv preprint arXiv:2412.07948},
  year={2024}
}

Acknowledgements

This library uses code from the following repositories for handling the embedding models:

License

This project is licensed under the MIT License. See the LICENSE file for details.


Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

frechet_music_distance-0.1.0.tar.gz (15.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

frechet_music_distance-0.1.0-py3-none-any.whl (16.0 kB view details)

Uploaded Python 3

File details

Details for the file frechet_music_distance-0.1.0.tar.gz.

File metadata

  • Download URL: frechet_music_distance-0.1.0.tar.gz
  • Upload date:
  • Size: 15.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.3

File hashes

Hashes for frechet_music_distance-0.1.0.tar.gz
Algorithm Hash digest
SHA256 330ee84c440410e37ff7f9d217bc555c57af4dba362154b525381b0fae09edc8
MD5 f3be01f11d10dca1c22b72a3b1b55cf2
BLAKE2b-256 d37eb58388949cdaed007023a36598037be55d1829d6e58258fb8dcf956e0688

See more details on using hashes here.

File details

Details for the file frechet_music_distance-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for frechet_music_distance-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d20f585761c68b21ef66ba4b38b5606bbb3da39e7c57295027d234eacf4a36d2
MD5 7041a7cdd02582b37540a2f368697d71
BLAKE2b-256 c9553a56feac374b5f1bb2a80ac186b5032076a8e0708e31138b8896b49033d7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page