--- license: cc-by-sa-4.0 pretty_name: Captioned MIDI with ChordStream task_categories: - text-to-audio tags: - midi - music - captions - chords - symbolic-music configs: - config_name: default data_files: - split: train path: data/train-* - split: test path: data/test-* dataset_info: features: - name: i dtype: int64 - name: source dtype: class_label: names: '0': godzilla '1': midicaps_prose '2': pdmx - name: caption dtype: string - name: key_tok dtype: string - name: midi_name dtype: string - name: midi dtype: binary - name: chordstream sequence: uint64 - name: cs_tokens dtype: int32 - name: cs_bars dtype: int32 - name: cs_key dtype: string - name: cs_error dtype: string splits: - name: train num_bytes: 35220596 num_examples: 900 - name: test num_bytes: 3718590 num_examples: 100 download_size: 18872022 dataset_size: 38939186 --- # Captioned MIDI with ChordStream 1,000 captioned MIDI files, each with its harmony extracted as a **ChordStream** token sequence: one 64-bit token per chord change or silence, carrying the key, the chord's degree in that key, its pitch-class content, its bass, and its absolute bar, onset and length in musical time. Rows are the first 1,000 `midicaps_prose` rows of `PsiPi/captioned-midi-moods-and-genre` (a private dataset), with the ChordStream column computed from each row's own `midi` bytes. ## Splits | split | rows | |---|---| | train | 900 | | test | 100 | Split 90/10 with `train_test_split(test_size=0.1, seed=0)`. ## Columns | column | meaning | |---|---| | `i` | row id in the source dataset | | `source` | always `midicaps_prose` here | | `caption` | the prose caption | | `key_tok` | key as labelled in the source dataset | | `midi_name` | `{i}-{original file name}.mid` | | `midi` | the MIDI file's bytes | | `chordstream` | the ChordStream tokens, `uint64` per token | | `cs_tokens` | number of tokens | | `cs_bars` | bars covered | | `cs_key` | key at the start of the piece, e.g. `C`, `Am`; the key can change, and each token carries its own | | `cs_error` | empty, or why extraction produced nothing | Every token's top bit is zero, so the column is equally safe read as `uint64` or `int64`. That is deliberate: numpy promotes `uint64` above 2^63-1 to float64 whenever it meets a signed type, and Arrow refuses such values outright. ## ChordStream token layout A token is two 32-bit words: `word_a = token & 0xFFFFFFFF`, `word_b = token >> 32`. **Word A (chord)** | bits | field | meaning | |---|---|---| | 0-3 | tonic | key tonic pitch class 0-11 | | 4 | mode | 0 major, 1 minor | | 5-8 | degree | chord root relative to the tonic 0-11; **14 = solo line**, **15 = silence** | | 9-19 | mask | bit i-1 set means the interval i semitones above the root is present | | 20-23 | bass | bass pitch class relative to the chord root | | 24-31 | reserved | zero | **Word B (time)** | bits | field | meaning | |---|---|---| | 0-15 | bar | absolute bar from the start of the piece | | 16-21 | onset | sixteenths after the bar's downbeat | | 22-29 | dur | length in sixteenths (1-255) | | 30 | cont | 1 = continuation of the previous token (a chord that began earlier) | | 31 | reserved | zero (the token's top bit) | The absolute chord root is `(tonic + degree) mod 12`. Everything except the tonic is relative to the key, so transposing a piece changes only the tonic. Time is in sixteenths derived from ticks, never from tempo, so playback speed cannot change a token. Every token carries its own bar, onset and key, so any contiguous slice is self-describing: a window whose first token has `bar > 0` began mid-piece, and its `cont` flag says whether its chord started earlier. ## Reading it ```python from datasets import load_dataset PC = ["C", "Db", "D", "Eb", "E", "F", "Gb", "G", "Ab", "A", "Bb", "B"] ROMAN = ["I", "bII", "II", "bIII", "III", "IV", "bV", "V", "bVI", "VI", "bVII", "VII"] ds = load_dataset("PsiPi/captioned-ChordStream", split="train") row = ds[0] for tok in row["chordstream"]: a, b = tok & 0xFFFFFFFF, tok >> 32 tonic, mode = a & 15, a >> 4 & 1 degree, mask, bass = a >> 5 & 15, a >> 9 & 0x7FF, a >> 20 & 15 bar, onset, dur, cont = b & 0xFFFF, b >> 16 & 63, b >> 22 & 255, b >> 30 & 1 if degree == 15: name = "N.C." # silence elif degree == 14: name = "solo" # a single line, no harmony to name else: root = (tonic + degree) % 12 minorish = mask >> 2 & 1 and not mask >> 3 & 1 # minor third, no major third numeral = ROMAN[degree].lower() if minorish else ROMAN[degree] intervals = [i for i in range(1, 12) if mask >> (i - 1) & 1] name = f"{numeral} {PC[root]} intervals={intervals} bass=+{bass}" print(f"bar {bar}.{onset} dur {dur}{' cont' if cont else ''} " f"key {PC[tonic]}{'m' if mode else ''} {name}") ``` ## How the harmony was extracted Per chord step (the metre's beat, grouped to at least a quarter note), a duration-weighted pitch-class histogram is matched against 16 chord templates, with melody voices downweighted, pedal points removed and refitted, unaccompanied single lines marked as solo, passing chords absorbed and consecutive same-root steps merged. The key comes from Aarden-Essen profiles over a sliding 8-bar window with hysteresis. The full procedure, with every threshold, is in the ChordStream write-up (see **Citation and further reading**). ## Known limitations - **The extractor is heuristic** and has not been validated against human harmonic annotation. Chord quality is the noisy part: power chords, add9 and sus2 are over-produced where melody notes leak into the chord. Roots and cadences are more reliable. - **Only major and minor keys** are modelled. - **3 of the 1,000 rows produced no tokens** (`cs_error` is `no pitched notes`: the file has drums only or no notes the extractor uses). They are kept, with empty token lists, so rows stay aligned with the source dataset. - **Expressive performances** (a recorded performance with a dense tempo map rather than a quantised score) have nominal bar lines, so chord steps placed on them may not match the harmonic rhythm a listener hears. This has not been measured. ## Licence and provenance The **MIDI files** come from the `midicaps_prose` portion of the parent dataset, which is [MidiCaps](https://huggingface.co/datasets/amaai-lab/MidiCaps) over the Lakh MIDI dataset: **CC BY-SA 4.0**. The **captions are not MidiCaps captions**. They were written for this project by PsiPi, generated with Anthropic models at PsiPi's own expense, and are licensed **CC BY-SA 4.0**. The **ChordStream column** is derived from the MIDI files in the same rows. ## Citation and further reading The ChordStream format, its extraction procedure and its measured limitations are described in the accompanying write-up: