• Stars
    star
    122
  • Rank 292,031 (Top 6 %)
  • Language
    Python
  • License
    MIT License
  • Created over 4 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Transformer-XL for Jazz music composition. Paper: "The Jazz Transformer on the Front Line: Exploring the Shortcomings of AI-Composed Music through Quantitative Measures", ISMIR 2020

The Jazz Transformer

An adapted Transformer-XL deep learning model that composes Jazz music (lead sheetsβ€”chord progression & melody).

Tensorflow implementation of the automatic music composition model presented in our paper:

  • The Jazz Transformer on the Front Line: Exploring the Shortcomings of AI-composed Music through Quantitative Measures
    Shih-Lun Wu and Yi-Hsuan Yang
    The 21st International Society for Music Information Retrieval Conference (ISMIR), 2020.

Want to listen to some compositions by the Jazz Transformer first? Click here!

Usage Notes

Prerequisites

  • Python 3.6 (install)
  • Recommended: a working GPU with β‰₯2GB of memory
  • Install dependencies (pip or pip3, depending on your sytem)
pip3 install -r requirements.txt

Compose Some Songs Right Away

  • Download pretrained model
./download_model.sh
  • Inference (compose)
python3 inference.py [--model MODEL] [--temp TEMP] [--struct_csv CSV] [--n_bars N_BARS] output_midi
  • output_midi: path to the output MIDI file
  • --model MODEL: path to the trained model checkpoint (default: the downloaded checkpoint)
  • --temp TEMP: sampling temperature for generation (default: 1.2)
  • --n_bars N_BARS: # of bars to generate (default: 32)
  • --struct_csv CSV : path to the output csv file that records generated structure-related events (optional)

Train from Scratch

  • Preprocess dataset
./data_preprocess.sh
  • Train the model
python3 train.py ckpt_dir log_file
  • ckpt_dir: directory to save checkpoints
  • log_file: path to the log file

Likewise, you may compose music with the model trained by yourself using inference.py (see above for instructions)

Directory Structure

β”œβ”€β”€ data_preprocess.sh      (executes python scripts to build vocab and prepare data) 
β”œβ”€β”€ inference.py            (generates Jazz music)
β”œβ”€β”€ requirements.txt        (python dependencies)
β”œβ”€β”€ train.py                (trains Transformer-XL from scratch)
β”œβ”€β”€ data                    (.pkl files for training)
β”œβ”€β”€ mcsv_beat               (Jazzomat dataset content---beats+chords)
β”œβ”€β”€ mcsv_melody             (Jazzomat dataset content---solo melody)
β”œβ”€β”€ output                  (sample generated piece)
β”‚   β”œβ”€β”€ demo.csv
β”‚   β”œβ”€β”€ demo.midi
β”œβ”€β”€ pickles                 (houses required metadata for training)
β”œβ”€β”€ remi_encs_struct        (contains training data in readable REMI event sequences)
β”œβ”€β”€ src
β”‚   β”œβ”€β”€ build_chord_profile.py   (reads and stores key templates for different chord types defined in ``chord_profile.txt``)
β”‚   β”œβ”€β”€ build_vocab.py           (builds the vocabulary for the Jazz Transformer)
β”‚   β”œβ”€β”€ chord_processor.py       (the class and methods for converting notes to chords and vice versa)
β”‚   β”œβ”€β”€ chord_profile.txt        (hand-crafted key templates for each chord type)
β”‚   β”œβ”€β”€ containers.py            (container classes for events in mcsv files)
β”‚   β”œβ”€β”€ convert_to_remi.py       (converts Jazzomat dataset to REMI events for training)
β”‚   β”œβ”€β”€ explore_mcsv.py          (utilities for reading events from dataset .csv files)
β”‚   β”œβ”€β”€ mcsv_to_midi.py          (converts mcsv file to midi format)
β”‚   β”œβ”€β”€ midi_decoder.py          (the class and methods for conversion from REMI to midi)
β”‚   β”œβ”€β”€ mlus_events.txt          (the mlu events used by the Jazz Transformer)
β”‚   β”œβ”€β”€ mlu_processor.py         (the class and methods for defining and parsing Mid-level Unit (MLU) events)
β”‚   β”œβ”€β”€ prepare_data.py          (splits data into training and validation sets before training the Jazz transformer)
β”‚   β”œβ”€β”€ remi_containers.py       (container classes for REMI events)
β”‚   β”œβ”€β”€ utils.py                 (miscellaneous utilities)
β”œβ”€β”€ transformer_xl
β”‚   β”œβ”€β”€ model_aug.py             (Jazz Transformer model)
β”‚   β”œβ”€β”€ modules.py               (functions for constructing Transformer-XL)

Acknowledgements

The Jazz Transformer is trained on the Weimar Jazz Database (WJazzD), a dataset meticulously annotated by the Jazzomat Research Project (@ University of Music FRANZ LISZT Weimar). Many thanks to them for the great work and making it publicly accessible!

Also, we would like to thank Yi-Jen Shih (@ NTUEE, personal GitHub) for the help he provided in arranging the codes of this repository.

See Also