Marble

repository·main·Indexed 41 days ago

https://github.com/a43992899/marble

A modular, configuration-driven suite for training, evaluating, and performing inference on pretrained music models. Version 0.2.0 utilizes LightningCLI for YAML-based configurations and features a pipeline architecture consisting of DataModules, Encoders, Embedding Transforms, and Decoders.

Tokens
10.7K
Snippets
9
Records
11
Agent score
2%

What's inside Marble

  1. Project Structure Overview

    main

    The Marble repository is organized as follows:

    • marble/: Core code package
      • core/: Base classes (BaseTask, BaseEncoder, BaseTransform)
      • encoders/: Wrapper classes for various SSL encoders
      • modules/: Shared transforms, callbacks, losses, decoders
      • tasks/: Downstream tasks (probe, few-shot, datamodules)
      • utils/: IO utilities, instantiation helpers
    • cli.py: Entry-point for launching experiments
    • sota/: Scripts for state-of-the-art models and inference
    • configs/: Experiment configs (YAML)
    • data/: Datasets and metadata files
    • scripts/: Run scripts & utilities
    • tests/: Unit tests for transforms & datasets
    • pyproject.toml: Python project metadata
  2. How Marble's modular architecture works

    main

    Marble is a configuration-driven suite designed for modularity and extensibility. The architecture follows a pipeline where data flows through several isolated components:

    1. DataModule: Yields (waveform, label, path) and optional audio transforms.
    2. Encoder: Processes the waveform into hidden_states[B, L, T, H].
    3. Embedding Transforms: (Optional) Applies operations like LayerSelector or TimeAvgPool to the hidden states.
    4. Decoder(s): Processes the states to produce logits.
    5. Loss/Metrics/Callbacks: The final stage where the output is evaluated against targets.

    This design allows you to mix and match components (encoders, tasks, transforms, decoders) via YAML configurations without modifying the core logic.

  3. Quickstart: Prepare data, configure, and run experiments

    main

    Follow these steps to run a training or testing experiment:

    1. Prepare data: Run the download script to fetch necessary datasets.
    2. Configure: Copy a YAML configuration file from the configs/ directory and modify the paths, encoder settings, transforms, and task parameters to suit your needs.
    3. Run: Use cli.py with the fit command for training or the test command for evaluation, passing your configuration via the --config flag.
    4. Results: Checkpoints and logs are saved in the output/ directory and are also logged to Weights & Biases.
    # Prepare data
    python download.py all
    
    # Run training (fit)
    python cli.py fit --config configs/probe.MERT-v1-95M.GTZANGenre.yaml
    
    # Run evaluation (test)
    python cli.py test --config configs/probe.MERT-v1-95M.GTZANGenre.yaml
  4. Install MARBLE dependencies

    main

    To set up MARBLE, follow these steps to ensure all system and Python dependencies are met:

    1. Create a new Conda environment.
    2. Install FFmpeg (system dependency).
    3. Install core dependencies via pip.
    4. [Optional] Downgrade pip if you are using fairseq modules:
      pip install pip==24.0
      pip install fairseq

    Note on Encoders: Some encoders (such as Xcodec) require additional dependencies. Check the specific requirements file for the encoder you intend to use located at marble/encoders/*/requirements.txt.

    pip install pip==24.0
    pip install fairseq
  5. Install Marble via Conda and Pip

    main

    To set up Marble, create a new Conda environment with Python 3.10, install ffmpeg from the conda-forge channel, and then install the package in editable mode using pip install -e ..

    Note on Fairseq: If you are using fairseq modules, you may need to downgrade pip to version 24.0. Additionally, certain encoders (like Xcodec) require specific dependencies listed in their respective marble/encoders/*/requirements.txt files.

    # 1. create a new conda env
    conda create -n marble python=3.10 -y
    conda activate marble
    
    # 2. install ffmpeg
    conda install -c conda-forge ffmpeg -y
    
    # 3. now install other dependencies
    pip install -e .
    
    # 4. [Optional] downgrade pip to 24.0 if you are using fairseq modules
    # pip install pip==24.0
    # pip install fairseq
  6. How to add a new task to Marble

    main

    Tasks in Marble can be added via Internal or External extension modes.

    Internal Extension

    1. Create a package under marble/tasks/YourTask/ containing __init__.py, datamodule.py (a LightningDataModule subclass), and probe.py (a BaseTask subclass).

    2. Implement the classes:

    # datamodule.py
    import pytorch_lightning as pl
    class YourDataModule(pl.LightningDataModule):
        def setup(self, stage=None): ...
        def train_dataloader(self): ...
    
    # probe.py
    from marble.core.base_task import BaseTask
    class YourTask(BaseTask):
        def __init__(self, encoder, emb_transforms, decoders, losses, metrics, sample_rate, use_ema):
            super().__init__(...)
    1. Configure via YAML:
    task:
      class_path: marble.tasks.YourTask.probe.YourTask
      init_args:
        sample_rate: 22050
        use_ema: false
    
    data:
      class_path: marble.tasks.YourTask.datamodule.YourDataModule

    External Extension

    Place your task code anywhere in your project and reference the full import path in the YAML:

    model:
      class_path: my_project.probe.CustomTask
    
    data:
      class_path: my_project.datamodule.CustomDataModule
    from marble.core.base_task import BaseTask
    
    class YourTask(BaseTask):
        def __init__(self, encoder, emb_transforms, decoders, losses, metrics, sample_rate, use_ema):
            super().__init__(...)
  7. How to add a new encoder to Marble

    main

    You can extend Marble with new encoders using either Internal or External extension modes.

    Internal Extension

    Implement your encoder by subclassing BaseAudioEncoder within the marble/encoders/ directory.

    from marble.core.base_encoder import BaseAudioEncoder
    
    class MyEncoder(BaseAudioEncoder):
       def __init__(self, arg1, arg2):
          super().__init__()
          # initialize your model
    
       def forward(self, waveforms):
          # return List[Tensor] of shape (batch, layer, seq_len, hidden_size)
          # or return a dict of representations

    Then, reference it in your YAML configuration:

    model:
      encoder:
        class_path: marble.encoders.my_encoder.MyEncoder
        init_args:
          arg1: 123
          arg2: 456

    External Extension

    Place your encoder file anywhere in your project (e.g., ./my_project/my_encoder.py) and use the full Python import path in your YAML configuration:

    model:
      encoder:
        class_path: my_project.my_encoder.MyEncoder
        init_args:
          arg1: 123

    Custom Transforms

    If your encoder requires specific transforms, you can register them in the YAML:

    • Embedding-level transforms: Subclass BaseEmbTransform and register under emb_transforms.
    • Audio preprocessing: Subclass BaseAudioTransform and register under audio_transforms (can be specific to train or general).
    emb_transforms:
      - class_path: marble.modules.transforms.MyEmbTransform
        init_args:
          param: value
    
    audio_transforms:
      train:
        - class_path: marble.modules.transforms.MyAudioTransform
          init_args:
            param: value
    from marble.core.base_encoder import BaseAudioEncoder
    
    class MyEncoder(BaseAudioEncoder):
       def __init__(self, arg1, arg2):
          super().__init__()
    
       def forward(self, waveforms):
          # return List[Tensor] of shape (batch, layer, seq_len, hidden_size)
          pass
  8. Perform key prediction with sota/predict_key.py

    main

    Use the sota/predict_key.py script to perform key prediction on audio files using a pretrained model. The script handles model downloading from Hugging Face, batch processing, and saving results (key and confidence) to a JSONL file.

    Arguments:

    • --filelist_path <filelist>: Path to the file list.
    • --output_path <output>: Path where predictions will be saved.
    • --batch_size <int>: Number of clips to process in a batch.
    • --download_dir <dir>: Directory to download the model to.
    python sota/predict_key.py --filelist_path <filelist> --output_path <output> --batch_size 16 --download_dir <dir>
  9. Reference: Supported Encoders in MARBLE

    main

    The following encoders are currently supported or under development in MARBLE. These models provide the underlying representations for music and audio processing tasks.

    | Name                         | Description                                                                                                  | Paper                                                         | Link                                                          |
    | :--------------------------- | :----------------------------------------------------------------------------------------------------------- | :------------------------------------------------------------ | :------------------------------------------------------------ |
    | **CLaMP3**                   | Cross-Modal & Language-based Music Pretraining v3. Aligns audio, sheet music, MIDI, and multilingual text via contrastive learning. | [arXiv:2502.10362](https://arxiv.org/abs/2502.10362)          | [GitHub sanderwood/clamp3](https://github.com/sanderwood/clamp3) |
    | **DaSheng**                  | Deep Audio-Signal Holistic Embeddings: masked autoencoder trained on 272 k h of diverse audio.               | [arXiv:2406.06992](https://arxiv.org/abs/2406.06992)          | [GitHub richermans/dasheng](https://github.com/richermans/dasheng) |
    | **identity**                 | Pass-through encoder.                                                                        | —                                                              | —                                                             |
    | **MERT**                     | Music understanding via large-scale self-supervised training with acoustic & musical pseudo-labels.          | [arXiv:2306.00107](https://arxiv.org/abs/2306.00107)          | [GitHub yizhilll/MERT](https://github.com/yizhilll/MERT)  |
    | **MuQ**                      | Self-supervised music representation with Mel Residual Vector Quantization.                                  | [arXiv:2501.01108](https://arxiv.org/abs/2501.01108)          | [GitHub Tencent-ailab/MuQ](https://github.com/tencent-ailab/MuQ) |
    | **MuQMuLan**                 | Two-tower contrastive model combining MuQ audio and text for zero-shot tagging.                               | [arXiv:2501.01108](https://arxiv.org/abs/2501.01108)          | [Hugging Face OpenMuQ/MuQ-MuLan-large](https://huggingface.co/OpenMuQ/MuQ-MuLan-large) |
    | **MusicFM**                  | Masked-token modeling in music using random projections & codebooks.                                        | [arXiv:2311.03318](https://arxiv.org/abs/2311.03318)          | [GitHub minzwon/musicfm](https://github.com/minzwon/musicfm)    |
    | **Qwen2_5OmniEncoder**       | Qwen 2.5-Omni Audio Tower: a multimodal generalist model supporting text, image, audio, and video.           | [arXiv:2503.20215](https://arxiv.org/abs/2503.20215)          | [GitHub QwenLM/Qwen2.5-Omni](https://github.com/QwenLM/Qwen2.5-Omni) |
    | **Qwen2AudioInstructEncoder** | Instruction-tuned variant of Qwen2-Audio Encoder for interactive audio chat.                                 | [arXiv:2407.10759](https://arxiv.org/abs/2407.10759)          | [GitHub QwenLM/Qwen2-Audio](https://github.com/QwenLM/Qwen2-Audio)  |
    | **Xcodec**                   | Improves codec semantics for audio LLMs by integrating semantic features pre-quantization.                  | [arXiv:2408.17175](https://arxiv.org/abs/2408.17175)          | [GitHub zhenye234/xcodec](https://github.com/zhenye234/xcodec)  |
  10. Reference: Supported Downstream Tasks in MARBLE

    main

    The following tasks are implemented or under development.

    Task Status Tags:

    • [v1]: Implemented in MARBLE v1 (will be adapted to v2 soon).
    • [Planning]: Task is currently under development.
    | Name                   | Description                                                                                                                                                                                          | Paper                                                                                                                                                                                          | Original Link                                                                                                                                                                                          |
    |------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
    | **Chords1217**         | Large-vocabulary chord recognition on 1 217 songs drawn from Isophonics, Billboard & MARL collections.                                                                                | Mauch & Dixon (ISMIR 2019) [Large-Vocabulary Chord Recognition](https://archives.ismir.net/ismir2019/paper/000078.pdf)                                                                            | [GitHub repo](https://github.com/music-x-lab/ISMIR2019-Large-Vocabulary-Chord-Recognition)                                                                                                       |
    | **EMO**                | Emotion regression on EmoMusic (744 clips × 45 s; valence & arousal; R²)                                                                                | Bhattarai & Lee (ISMIR 2019) [Automatic Music Mood Detection Using Transfer Learning](https://pdfs.semanticscholar.org/2ec6/2d46dc43f3940b5f44deb9103c789be8b8fa.pdf)                           | [EmoMusic dataset](https://cvml.unige.ch/databases/emoMusic/)                                                                                                                                     |
    | **GS**                 | Key detection on GiantSteps Key (604 EDM tracks × 2 min; 24-class major/minor; weighted accuracy ±20 cents), plus 1 077 GiantSteps-MTG-Keys for train/val.                             | Knees et al. (ISMIR 2015) [Two data sets for tempo estimation and key detection…](https://archives.ismir.net/ismir2015/paper/000246.pdf)                                                           | [GiantSteps Key dataset](https://github.com/GiantSteps/giantsteps-key-dataset)                                                                                                         |
    | **GTZANBeatTracking**  | Beat tracking on GTZAN Rhythm                                                                                                                          | Tzanetakis & Cook (2002) [Musical genre classification of audio signals](https://www.cs.cmu.edu/~gtzan/work/pubs/tsap02gtzan.pdf)                                                                                           | [Marsyas datasets](http://marsyas.info/downloads/datasets.html)                                                                                                                                   |
    | **GTZANGenre**         | Genre classification on GTZAN (10 genres; 30 s clips; 930 tracks after artist-stratified “fail-filtered” split; accuracy)                                                              | Tzanetakis & Cook (2002) [Musical genre classification of audio signals](https://www.cs.cmu.edu/~gtzan/work/pubs/tsap02gtzan.pdf)                                                                                           | [Marsyas datasets](http://marsyas.info/downloads/datasets.html)                                                                                                                                   |
    | **[Planning] HookTheoryChord**   | Chord labeling on HookTheory user-created song hooks (chord symbols).                                                                                                      | [Melody transcription via generative pre-training](https://arxiv.org/abs/2212.01884)                                                                                 | [GitHub repo](https://github.com/chrisdonahue/sheetsage)                                                                                                      |
    | **HookTheoryKey**                | Key estimation on HookTheory hooks.                                                                                                         | [Melody transcription via generative pre-training](https://arxiv.org/abs/2212.01884)                                                                                 | [GitHub repo](https://github.com/chrisdonahue/sheetsage)                                                                                                      |
    | **[Planning] HookTheoryMelody**  | Melody prediction/completion on HookTheory hooks.                                                                                           | [Melody transcription via generative pre-training](https://arxiv.org/abs/2212.01884)                                                                                 | [GitHub repo](https://github.com/chrisdonahue/sheetsage)                                                                                                      |
    | **HookTheoryStructure**          | Structural label prediction on HookTheory hooks.                                                                                             | [Melody transcription via generative pre-training](https://arxiv.org/abs/2212.01884)                                                                                 | [GitHub repo](https://github.com/chrisdonahue/sheetsage)                                                                                                      |
    | **[Planning] HXMSA**              | Music structure analysis on the Harmonix Set (912 Western pop tracks).                                                                                                     | Nieto et al. (ISMIR 2019) [The Harmonix Set: Beats, Downbeats, and Functional Segment Annotations](https://archives.ismir.net/ismir2019/paper/000068.pdf)                                                      | [HarmonixSet GitHub](https://github.com/urinieto/harmonixset)                                                                                                                                    |
    | **MTGGenre**           | Genre tagging on MTG-Jamendo, using split 0.                                                                                                                                   | Bogdanov et al. (ICML 2019) [The MTG-Jamendo Dataset for Automatic Music Tagging (PDF)](https://repositori.upf.edu/bitstreams/c66cf295-ad09-4576-a938-d9466a84ec48/download)                                                    | [MTG-Jamendo dataset](https://mtg.github.io/mtg-jamendo-dataset/)                                                                                                                                 |
    | **MTGInstrument**      | Instrument tagging on MTG-Jamendo, using split 0.                                                                                                                               | Bogdanov et al. (ICML 2019) [The MTG-Jamendo Dataset for Automatic Music Tagging (PDF)](https://repositori.upf.edu/bitstreams/c66cf295-ad09-4576-a938-d9466a84ec48/download)                                                    | [MTG-Jamendo dataset](https://mtg.github.io/mtg-jamendo-dataset/)                                                                                                                                 |
    | **MTGMood**            | Mood/theme tagging on MTG-Jamendo, using split 0.                                                                                                                                     | Bogdanov et al. (ICML 2019) [The MTG-Jamendo Dataset for Automatic Music Tagging (PDF)](https://repositori.upf.edu/bitstreams/c66cf295-ad09-4576-a938-d9466a84ec48/download)                                                    | [MTG-Jamendo dataset](https://mtg.github.io/mtg-jamendo-dataset/)                                                                                                                                 |
    | **MTGTop50**           | Top-50 tag prediction on MTG-Jamendo, using split 0.                                                                                                                                  | Bogdanov et al. (ICML 2019) [The MTG-Jamendo Dataset for Automatic Music Tagging (PDF)](https://repositori.upf.edu/bitstreams/c66cf295-ad09-4576-a938-d9466a84ec48/download)                                                    | [MTG-Jamendo dataset](https://mtg.github.io/mtg-jamendo-dataset/)                                                                                                                                 |
    | **MTT**                | Multi-tag auto-tagging on MagnaTagATune                                                                                                                | Law et al. (ISMIR 2009) [Evaluation of Algorithms Using Games: The Case of Music Tagging](https://archives.ismir.net/ismir2009/paper/000019.pdf)                                                                               | [MagnaTagATune dataset](https://mirg.city.ac.uk/codeapps/the-magnatagatune-dataset)                                                                                                              |
    | **[v1] NSynth**             | Pitch-class note classification on NSynth (340 h; 4 s excerpts; 128-class; accuracy)                                                                                                  | Engel et al. (2017) [Neural Audio Synthesis of Musical Notes with WaveNet Autoencoders](https://arxiv.org/abs/1704.01279)                                                                                                           | [NSynth dataset](https://magenta.withgoogle.com/nsynth)                                                                                                                                          |
    | **[Planning] SHS**                | Cover-song cliques dataset: a subset of the Million Song Dataset organized into 5 854 cover groups (18 196 tracks) for cover-song identification.                                                                    | Bertin-Mahieux et al. (2011) [The Million Song Dataset](https://academiccommons.columbia.edu/doi/10.7916/D8377K1H/download)                                                                                                            | [SecondHandSongs dataset](https://millionsongdataset.com/secondhand/)                                                                                                                                           |
    | **[Planning] SongEval**           | Holistic song-aesthetics evaluation on 2 399 full-length songs (≈ 140 h) with 16 professional annotators across 5 aesthetic dimensions.                                                | Yao et al. (arXiv 2025) [SongEval: A Benchmark Dataset for Song Aesthetics Evaluation](https://arxiv.org/abs/2505.10793)                                                                                                            | [SongEval toolkit](https://github.com/ASLP-lab/SongEval)                                                                                                                                          |
    | **[v1] VocalSet**             | Solo singing-voice dataset (12 vowels × 4 registers × 30 singers).                                                                                                                     | Wilkins et al. (ISMIR 2018) [VocalSet: A Singing Voice Dataset](https://interactiveaudiolab.github.io/assets/papers/wilkins_seetharaman_ismir18.pdf)                                                                                                            | [VocalSet dataset](https://zenodo.org/records/1193957)                                                                                                                                           |
    | **[Planning] WildSVDD**             | Anomaly detection on WILD (Singing Voice Deepfake Detection Challenge) tracks (real vs. AI-generated).                                                                                | Zhang et al. (ICASSP 2024) [SVDD 2024: The Inaugural Singing Voice Deepfake Detection Challenge](https://arxiv.org/abs/2408.16132)                                                                                                                     | [SVDD Challenge](https://svddchallenge.org/)                                                                                                                                                     |
  11. Use the Marble CLI via LightningCLI

    main

    The Marble CLI is built using LightningCLI, which allows you to manage training, evaluation, and inference through configuration files. You can pass arguments directly via the command line or use YAML configuration files to define your model, data, and trainer settings.

    Because it uses subclass_mode_model=True and subclass_mode_data=True, you can pass the class paths of your custom models or datasets as arguments to instantiate them dynamically.

    # The CLI is typically invoked from the terminal, not as a python function.
    # Example usage pattern:
    # python cli.py fit --config config.yaml
    # python cli.py test --config config.yaml