File size: 5,481 Bytes
8e9b4ef
 
0a22924
 
 
 
 
 
 
 
 
 
8e9b4ef
0a22924
 
 
 
 
 
 
 
5e4b607
 
0a22924
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7b93597
 
 
 
 
 
 
 
0a22924
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
---
license: apache-2.0
library_name: transformers
pipeline_tag: fill-mask
tags:
  - music
  - symbolic-music
  - chords
  - chord-embeddings
  - deberta-v2
  - masked-language-modeling
  - feature-extraction
---

# ChordBERT

ChordBERT is a compact DeBERTa-v2 masked language model for symbolic chord
sequences. It can predict masked chords or act as an encoder that maps a chord
progression to a 256-dimensional embedding.


Model developed by [Lameusiwe](https://huggingface.co/Lameusiwe).

## Model details

| Property | Value |
|---|---|
| Architecture | DeBERTa-v2 masked language model |
| Transformer layers | 4 |
| Attention heads | 4 |
| Hidden size | 256 |
| Intermediate size | 1,024 |
| Vocabulary size | 3,230 |
| Parameters | 4,713,886 |
| Recommended maximum length | 256 tokens including boundary tokens |
| Training objective | Masked language modeling |
| Training domain | Chordonomicon chord sequences |
| License | Apache-2.0 |

This repository contains the original Chordonomicon-pretrained ChordBERT
checkpoint. It is not the separately adapted `ChordBERT + WIR` checkpoint.

## Intended uses

ChordBERT is intended for research with harmonic sequences, including:

- chord and progression embeddings;
- harmonic similarity and retrieval;
- clustering and visualization of musical works;
- masked-chord prediction;
- feature extraction for downstream music-information-retrieval models.

The model was not designed for audio transcription, music generation,
copyright detection, composer attribution, or high-stakes cultural and
historical judgments.

## Input format

Input must be a whitespace-separated sequence of tokens from the supplied
tokenizer vocabulary:

```text
C G Amin F
Cmaj7 Amin7 Dmin7 G7
Bb F Gmin Eb
```

Chord spelling follows the Chordonomicon convention:

- major triads use only the root, such as `C`;
- sharps use `s`, such as `Csmin` for C-sharp minor;
- flats use `b`, such as `Bb`;
- common suffixes include `min`, `7`, `maj7`, `min7`, `dim`, `dim7`, and
  `aug`;
- some structural markers, such as `<verse_1>`, are present in the vocabulary.

Unknown or differently formatted symbols may become `<unk>`. Check token
coverage before embedding a new corpus:

```python
from transformers import AutoTokenizer

model_id = "YOUR_USERNAME/YOUR_MODEL_NAME"
tokenizer = AutoTokenizer.from_pretrained(model_id)

tokens = "C G Amin F".split()
unknown = [token for token in tokens if token not in tokenizer.get_vocab()]
print("Unknown tokens:", unknown)
```

## Masked-chord prediction

```python
from transformers import pipeline

model_id = "YOUR_USERNAME/YOUR_MODEL_NAME"
fill_mask = pipeline("fill-mask", model=model_id, tokenizer=model_id)

predictions = fill_mask("C G <mask> F", top_k=5)
for prediction in predictions:
    print(prediction["token_str"], prediction["score"])
```

## Generate a progression embedding

The checkpoint does not include a trained sentence-pooling head. A practical
default is mean pooling over non-special tokens:

```python
import torch
from transformers import AutoModel, AutoTokenizer

model_id = "YOUR_USERNAME/YOUR_MODEL_NAME"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModel.from_pretrained(model_id).eval()

progressions = [
    "C G Amin F",
    "Dmin7 G7 Cmaj7",
]

batch = tokenizer(
    progressions,
    padding=True,
    truncation=True,
    max_length=256,
    return_tensors="pt",
)

with torch.inference_mode():
    hidden = model(**batch).last_hidden_state

pool_mask = batch["attention_mask"].bool()
for special_id in tokenizer.all_special_ids:
    pool_mask &= batch["input_ids"] != special_id

weights = pool_mask.unsqueeze(-1).to(hidden.dtype)
embeddings = (hidden * weights).sum(dim=1) / weights.sum(dim=1).clamp(min=1)

print(embeddings.shape)  # torch.Size([2, 256])
```

The resulting vectors are not normalized. Apply L2 normalization if cosine
similarity is the downstream comparison:

```python
embeddings = torch.nn.functional.normalize(embeddings, p=2, dim=1)
```

## Long sequences

For progressions longer than 254 chord tokens:

1. split the sequence into chunks of at most 254 tokens;
2. embed each chunk with the pooling procedure above;
3. combine chunk embeddings using the number of chord tokens as weights.

This leaves room for the two boundary tokens added by the tokenizer and matches
the evaluation setup used for this checkpoint.



## Training information

The supplied checkpoint is recorded in the project artifacts as a
Chordonomicon-pretrained masked language model. The original detailed training
hyperparameters and a complete training-data statement are not included with
this checkpoint; they should not be inferred from the later evaluation and
adaptation scripts.

The model configuration identifies the architecture as
`DebertaV2ForMaskedLM`. Weights are stored in `safetensors` format.

## Reproducibility

Recommended dependencies:

```text
torch
transformers
safetensors
```

For deterministic comparisons, keep the same token conversion, maximum length,
special-token handling, pooling, chunk weighting, and vector normalization
across all corpora.

## Citation

```bibtex
@misc{he2026modelingstylisticcoevolutionsymbolic,
      title={Modeling Stylistic Co-evolution in Symbolic Music Heritage Collections}, 
      author={Yulong He and Ivan Smirnov and Yanming Li},
      year={2026},
      eprint={2607.23957},
      archivePrefix={arXiv},
      primaryClass={cs.SD},
      url={https://arxiv.org/abs/2607.23957}, 
}
```