hreyulog commited on
Commit
0a22924
·
verified ·
1 Parent(s): 8e76a07

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +253 -0
README.md CHANGED
@@ -1,3 +1,256 @@
1
  ---
2
  license: apache-2.0
 
 
 
 
 
 
 
 
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: apache-2.0
3
+ library_name: transformers
4
+ pipeline_tag: fill-mask
5
+ tags:
6
+ - music
7
+ - symbolic-music
8
+ - chords
9
+ - chord-embeddings
10
+ - deberta-v2
11
+ - masked-language-modeling
12
+ - feature-extraction
13
  ---
14
+
15
+ # ChordBERT
16
+
17
+ ChordBERT is a compact DeBERTa-v2 masked language model for symbolic chord
18
+ sequences. It can predict masked chords or act as an encoder that maps a chord
19
+ progression to a 256-dimensional embedding.
20
+
21
+ The model operates on chord tokens, not raw audio, MIDI files, natural-language
22
+ descriptions, or note-level symbolic music.
23
+
24
+ ## Model details
25
+
26
+ | Property | Value |
27
+ |---|---|
28
+ | Architecture | DeBERTa-v2 masked language model |
29
+ | Transformer layers | 4 |
30
+ | Attention heads | 4 |
31
+ | Hidden size | 256 |
32
+ | Intermediate size | 1,024 |
33
+ | Vocabulary size | 3,230 |
34
+ | Parameters | 4,713,886 |
35
+ | Recommended maximum length | 256 tokens including boundary tokens |
36
+ | Training objective | Masked language modeling |
37
+ | Training domain | Chordonomicon chord sequences |
38
+ | License | Apache-2.0 |
39
+
40
+ This repository contains the original Chordonomicon-pretrained ChordBERT
41
+ checkpoint. It is not the separately adapted `ChordBERT + WIR` checkpoint.
42
+
43
+ ## Intended uses
44
+
45
+ ChordBERT is intended for research with harmonic sequences, including:
46
+
47
+ - chord and progression embeddings;
48
+ - harmonic similarity and retrieval;
49
+ - clustering and visualization of musical works;
50
+ - masked-chord prediction;
51
+ - feature extraction for downstream music-information-retrieval models.
52
+
53
+ The model was not designed for audio transcription, music generation,
54
+ copyright detection, composer attribution, or high-stakes cultural and
55
+ historical judgments.
56
+
57
+ ## Input format
58
+
59
+ Input must be a whitespace-separated sequence of tokens from the supplied
60
+ tokenizer vocabulary:
61
+
62
+ ```text
63
+ C G Amin F
64
+ Cmaj7 Amin7 Dmin7 G7
65
+ Bb F Gmin Eb
66
+ ```
67
+
68
+ Chord spelling follows the Chordonomicon convention:
69
+
70
+ - major triads use only the root, such as `C`;
71
+ - sharps use `s`, such as `Csmin` for C-sharp minor;
72
+ - flats use `b`, such as `Bb`;
73
+ - common suffixes include `min`, `7`, `maj7`, `min7`, `dim`, `dim7`, and
74
+ `aug`;
75
+ - some structural markers, such as `<verse_1>`, are present in the vocabulary.
76
+
77
+ Unknown or differently formatted symbols may become `<unk>`. Check token
78
+ coverage before embedding a new corpus:
79
+
80
+ ```python
81
+ from transformers import AutoTokenizer
82
+
83
+ model_id = "YOUR_USERNAME/YOUR_MODEL_NAME"
84
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
85
+
86
+ tokens = "C G Amin F".split()
87
+ unknown = [token for token in tokens if token not in tokenizer.get_vocab()]
88
+ print("Unknown tokens:", unknown)
89
+ ```
90
+
91
+ ## Masked-chord prediction
92
+
93
+ ```python
94
+ from transformers import pipeline
95
+
96
+ model_id = "YOUR_USERNAME/YOUR_MODEL_NAME"
97
+ fill_mask = pipeline("fill-mask", model=model_id, tokenizer=model_id)
98
+
99
+ predictions = fill_mask("C G <mask> F", top_k=5)
100
+ for prediction in predictions:
101
+ print(prediction["token_str"], prediction["score"])
102
+ ```
103
+
104
+ ## Generate a progression embedding
105
+
106
+ The checkpoint does not include a trained sentence-pooling head. A practical
107
+ default is mean pooling over non-special tokens:
108
+
109
+ ```python
110
+ import torch
111
+ from transformers import AutoModel, AutoTokenizer
112
+
113
+ model_id = "YOUR_USERNAME/YOUR_MODEL_NAME"
114
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
115
+ model = AutoModel.from_pretrained(model_id).eval()
116
+
117
+ progressions = [
118
+ "C G Amin F",
119
+ "Dmin7 G7 Cmaj7",
120
+ ]
121
+
122
+ batch = tokenizer(
123
+ progressions,
124
+ padding=True,
125
+ truncation=True,
126
+ max_length=256,
127
+ return_tensors="pt",
128
+ )
129
+
130
+ with torch.inference_mode():
131
+ hidden = model(**batch).last_hidden_state
132
+
133
+ pool_mask = batch["attention_mask"].bool()
134
+ for special_id in tokenizer.all_special_ids:
135
+ pool_mask &= batch["input_ids"] != special_id
136
+
137
+ weights = pool_mask.unsqueeze(-1).to(hidden.dtype)
138
+ embeddings = (hidden * weights).sum(dim=1) / weights.sum(dim=1).clamp(min=1)
139
+
140
+ print(embeddings.shape) # torch.Size([2, 256])
141
+ ```
142
+
143
+ The resulting vectors are not normalized. Apply L2 normalization if cosine
144
+ similarity is the downstream comparison:
145
+
146
+ ```python
147
+ embeddings = torch.nn.functional.normalize(embeddings, p=2, dim=1)
148
+ ```
149
+
150
+ ## Long sequences
151
+
152
+ For progressions longer than 254 chord tokens:
153
+
154
+ 1. split the sequence into chunks of at most 254 tokens;
155
+ 2. embed each chunk with the pooling procedure above;
156
+ 3. combine chunk embeddings using the number of chord tokens as weights.
157
+
158
+ This leaves room for the two boundary tokens added by the tokenizer and matches
159
+ the evaluation setup used for this checkpoint.
160
+
161
+ ## Evaluation
162
+
163
+ The checkpoint was evaluated on a leakage-audited validation partition derived
164
+ from DCML corpora v2.3:
165
+
166
+ - 367 musical records;
167
+ - 7 composers;
168
+ - 77,482 chord tokens before evaluation chunking;
169
+ - overlaps with the 2,000-work Cross-era production corpus removed;
170
+ - random seed 42.
171
+
172
+ These are local research evaluations, not standardized Hugging Face benchmark
173
+ scores.
174
+
175
+ ### Masked language modeling
176
+
177
+ Fifteen percent of eligible tokens were selected using the standard
178
+ 80% mask / 10% random / 10% unchanged corruption scheme.
179
+
180
+ | Metric | ChordBERT | Randomly initialized DeBERTa |
181
+ |---|---:|---:|
182
+ | Loss | 2.0286 | 8.1270 |
183
+ | Perplexity | 7.6035 | 3,384.7431 |
184
+ | Top-1 accuracy | 53.26% | 0.00% |
185
+ | Top-5 accuracy | 76.60% | 0.00% |
186
+ | Top-10 accuracy | 84.92% | 0.03% |
187
+ | Mean reciprocal rank | 0.6391 | 0.0014 |
188
+
189
+ The MLM evaluation contains 11,552 masked target tokens.
190
+
191
+ ### Embedding retrieval
192
+
193
+ Embeddings used non-special-token mean pooling and token-count-weighted chunk
194
+ aggregation.
195
+
196
+ | Task | R@1 | R@5 | R@10 | MRR |
197
+ |---|---:|---:|---:|---:|
198
+ | Retrieve another movement from the same work | 30.56% | 69.44% | 82.94% | 0.4674 |
199
+ | Match the two halves of a sequence | 49.59% | 73.57% | 85.56% | 0.6082 |
200
+
201
+ Same-work movement retrieval additionally obtained MAP@10 = 0.2843.
202
+
203
+ ## Limitations
204
+
205
+ - The model represents tokenized chord labels and ignores melody, rhythm,
206
+ instrumentation, dynamics, voicing, and audio timbre.
207
+ - Embedding quality depends strongly on chord-recognition quality and agreement
208
+ with the tokenizer's spelling conventions.
209
+ - The vocabulary is closed. Unsupported chord qualities and enharmonic
210
+ spellings may map to `<unk>` or require an explicit conversion policy.
211
+ - A 256-token context cannot represent long works in one pass. Chunk pooling
212
+ loses some long-range harmonic order.
213
+ - Mean pooling is a research convention, not a contrastively trained embedding
214
+ objective. Similarity scores should be validated for each downstream task.
215
+ - Training-corpus coverage may introduce genre, era, notation, and repertoire
216
+ biases. Results should not be interpreted as objective measures of musical
217
+ quality, influence, nationality, or authorship.
218
+
219
+ ## Training information
220
+
221
+ The supplied checkpoint is recorded in the project artifacts as a
222
+ Chordonomicon-pretrained masked language model. The original detailed training
223
+ hyperparameters and a complete training-data statement are not included with
224
+ this checkpoint; they should not be inferred from the later evaluation and
225
+ adaptation scripts.
226
+
227
+ The model configuration identifies the architecture as
228
+ `DebertaV2ForMaskedLM`. Weights are stored in `safetensors` format.
229
+
230
+ ## Reproducibility
231
+
232
+ Recommended dependencies:
233
+
234
+ ```text
235
+ torch
236
+ transformers
237
+ safetensors
238
+ ```
239
+
240
+ For deterministic comparisons, keep the same token conversion, maximum length,
241
+ special-token handling, pooling, chunk weighting, and vector normalization
242
+ across all corpora.
243
+
244
+ ## Citation
245
+
246
+ ```bibtex
247
+ @misc{dad,
248
+ title={XXX},
249
+ author={XXX},
250
+ year={XX},
251
+ eprint={XX},
252
+ archivePrefix={XX},
253
+ primaryClass={XX},
254
+ url={XX},
255
+ }
256
+ ```