sander-wood
commited on
Commit
•
acf010e
1
Parent(s):
66f0767
Update README.md
Browse files
README.md
CHANGED
@@ -6,87 +6,140 @@ widget:
|
|
6 |
tags:
|
7 |
- music
|
8 |
datasets:
|
9 |
-
- sander-wood/
|
10 |
---
|
11 |
|
12 |
# TunesFormer
|
13 |
|
14 |
## Model description
|
15 |
|
16 |
-
TunesFormer is
|
17 |
|
18 |
-
|
19 |
|
20 |
-
This music generation model is available for online use and experience on [
|
21 |
|
22 |
-
##
|
23 |
|
24 |
-
|
25 |
|
26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
|
28 |
### How to use
|
29 |
|
30 |
1. Install dependencies for the code released in [this repository](https://github.com/sander-wood/tunesformer):
|
31 |
```
|
32 |
-
|
|
|
33 |
samplings 0.1.7
|
34 |
transformers 4.18.0
|
35 |
```
|
36 |
|
37 |
-
2. Set the
|
38 |
```
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
|
|
|
|
|
|
44 |
```
|
45 |
-
For TunesFormer, the input is a concatenation of `control_codes` and `prompt`. Both `control_codes` and `prompt` are optional. However, if you need to set the prompt, you must set the control codes.
|
46 |
|
47 |
-
3. Run the script `
|
48 |
|
49 |
```
|
50 |
-
python
|
51 |
```
|
52 |
|
53 |
-
4. Enjoy tunes in the folder `output_tunes`! If you want to convert these ABC tunes to sheet music or audio, please refer to `
|
54 |
```
|
55 |
X:1
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
|
|
|
|
|
|
|
|
|
|
61 |
|
62 |
X:2
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
|
|
|
|
|
|
|
|
|
|
68 |
|
69 |
X:3
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
|
|
|
|
|
|
|
|
|
|
75 |
```
|
76 |
|
77 |
### Usage
|
78 |
```
|
|
|
|
|
|
|
|
|
79 |
optional arguments:
|
80 |
-h, --help show this help message and exit
|
81 |
-num_tunes NUM_TUNES the number of independently computed returned tunes
|
82 |
-
-
|
83 |
-
integer to define the maximum length in tokens of each
|
84 |
tune
|
85 |
-top_p TOP_P float to define the tokens that are within the sample
|
86 |
operation of text generation
|
|
|
|
|
87 |
-temperature TEMPERATURE
|
88 |
the temperature of the sampling operation
|
89 |
-seed SEED seed for randomstate
|
|
|
|
|
90 |
```
|
91 |
|
92 |
### BibTeX entry and citation info
|
@@ -97,11 +150,11 @@ optional arguments:
|
|
97 |
|
98 |
url = {https://arxiv.org/abs/2301.02884},
|
99 |
|
100 |
-
author = {Wu, Shangda and Sun, Maosong},
|
101 |
|
102 |
keywords = {Sound (cs.SD), Audio and Speech Processing (eess.AS), FOS: Computer and information sciences, FOS: Computer and information sciences, FOS: Electrical engineering, electronic engineering, information engineering, FOS: Electrical engineering, electronic engineering, information engineering},
|
103 |
|
104 |
-
title = {TunesFormer: Forming Tunes with Control Codes},
|
105 |
|
106 |
publisher = {arXiv},
|
107 |
|
|
|
6 |
tags:
|
7 |
- music
|
8 |
datasets:
|
9 |
+
- sander-wood/irishman
|
10 |
---
|
11 |
|
12 |
# TunesFormer
|
13 |
|
14 |
## Model description
|
15 |
|
16 |
+
TunesFormer is an efficient Transformer-based dual-decoder model specifically designed for the generation of melodies that adhere to user-defined musical forms. It was introduced in the paper [TunesFormer: Forming Tunes with Control Codes](https://arxiv.org/abs/2301.02884) by Wu et al. The code is released in [this repository](https://github.com/sander-wood/tunesformer), and the dataset is released in [huggingface](https://huggingface.co/datasets/sander-wood/irishman).
|
17 |
|
18 |
+
Trained on 214,122 Irish tunes, TunesFormer utilizes techniques including bar patching and control codes. Bar patching reduces sequence length and generation time, while control codes guide TunesFormer in producing melodies that conform to desired musical forms.
|
19 |
|
20 |
+
This music generation model is available for online use and experience on [huggingface spaces](https://huggingface.co/spaces/sander-wood/tunesformer). With this online platform, you can freely explore TunesFormer and receive a generated sheet music output from the model.
|
21 |
|
22 |
+
## ABC Notation
|
23 |
|
24 |
+
ABC notation is an ASCII-based plain text musical notation system that is commonly used for transcribing traditional music and sharing sheet music online. It provides a simple and concise way to represent musical elements such as notes, rhythms, chords, and more.
|
25 |
|
26 |
+
For those looking to interact with ABC notation in various ways, there are several tools available:
|
27 |
+
|
28 |
+
1. **[Online ABC Player](https://abc.rectanglered.com/):** This web-based tool allows you to input ABC notation and hear the corresponding audio playback. By pasting your ABC code into the player, you can instantly listen to the tune as it would sound when played.
|
29 |
+
|
30 |
+
2. **[ABC Sheet Music Editor - EasyABC](https://easyabc.sourceforge.net/):** EasyABC is a user-friendly software application designed for creating, editing, and formatting ABC notation. Its graphical interface enables you to input your ABC code, preview the sheet music, and make adjustments as necessary.
|
31 |
+
|
32 |
+
## Dataset
|
33 |
+
|
34 |
+
The **Irish Massive ABC Notation ([IrishMAN](https://huggingface.co/datasets/sander-wood/irishman))** dataset includes 216,284 Irish tunes in ABC notation, divided into 99\% (214,122 tunes) for training and 1\% (2,162 tunes) for validation. These tunes were collected from thesession.org and abcnotation.com, both renowned for sharing traditional music. To ensure uniformity in formatting, all tunes were converted to XML and then back to ABC using [scripts](https://wim.vree.org/svgParse/), and fields containing natural language (e.g., titles and lyrics) were removed.
|
35 |
+
|
36 |
+
Each tune is automatically annotated with control codes derived from ABC symbols, as described in Section 2.2. These control codes offer insights into the musical forms and structures of each composition.
|
37 |
+
|
38 |
+
In the IrishMAN dataset, a [music21](https://web.mit.edu/music21/doc/index.html#)-filtered [subset](https://huggingface.co/datasets/sander-wood/irishman/blob/main/leadsheet.json) includes 34,211 lead sheets, each human-annotated with chord symbols. It is from this very subset that [TunesFormer](https://huggingface.co/sander-wood/tunesformer) developed its capacity to generate melodies with harmonies.
|
39 |
+
|
40 |
+
A noteworthy aspect is the copyright status. All tunes in the dataset are in the public domain, ensuring ethical and legal usage for research and creative projects.
|
41 |
+
|
42 |
+
## Control codes
|
43 |
+
|
44 |
+
Inspired by [CTRL](https://huggingface.co/ctrl), we incorporate control codes into TunesFormer to represent musical forms. These codes, positioned ahead of the ABC notation, enable users to specify the structures of the generated tunes. The following control codes are introduced:
|
45 |
+
|
46 |
+
- **S:number of sections**: determines the number of sections in the entire melody. It counts on several symbols that can be used to represent section boundaries: `[|`, `||`, `|]`, `|:`, `::`, and `:|`. In our dataset, the range is 1 to 8 (e.g., `S:1` for a single-section melody, and `S:8` for a melody with eight sections).
|
47 |
+
|
48 |
+
- **B:number of bars**: specifies the desired number of bars within a section. It counts on the bar symbol `|`. In our dataset, the range is 1 to 32 (e.g., `B:1` for a one-bar section, and `B:32` for a section with 32 bars).
|
49 |
+
|
50 |
+
- **E:edit distance similarity**: controls the similarity level between the current section $c$ and a previous section $p$ in the melody. It is based on the Levenshtein distance $lev(c,p)$ , quantifying the difference between sections for creating variations or contrasts. Mathematically, it can be expressed as:
|
51 |
+
```
|
52 |
+
eds(c,p) = 1 - lev(c,p) / max(|c|,|p|)
|
53 |
+
```
|
54 |
+
where $|c|$ and $|p|$ are the string lengths of the two sections. It is discretized into 11 levels, ranging from no match at all to an exact match (e.g., `E:0` for no similarity, and `E:10` for an exact match).
|
55 |
|
56 |
### How to use
|
57 |
|
58 |
1. Install dependencies for the code released in [this repository](https://github.com/sander-wood/tunesformer):
|
59 |
```
|
60 |
+
unidecode 1.3.6
|
61 |
+
torch 1.13.1+cu116
|
62 |
samplings 0.1.7
|
63 |
transformers 4.18.0
|
64 |
```
|
65 |
|
66 |
+
2. Set the prompt in `prompt.txt` for conditional music generation.
|
67 |
```
|
68 |
+
S:2
|
69 |
+
B:9
|
70 |
+
E:4
|
71 |
+
B:9
|
72 |
+
L:1/8
|
73 |
+
M:3/4
|
74 |
+
K:D
|
75 |
+
de |"D" """
|
76 |
```
|
|
|
77 |
|
78 |
+
3. Run the script `generate.py`. When running a script for the first time, the downloaded weights will be cached for future reuse.
|
79 |
|
80 |
```
|
81 |
+
python generate.py -num_tunes 3 -max_patch 128 -top_p 0.8 -top_k 8 -temperature 1.2 -seed 0 -show_control_code True
|
82 |
```
|
83 |
|
84 |
+
4. Enjoy tunes in the folder `output_tunes`! If you want to convert these ABC tunes to sheet music or audio, please refer to `ABC Notation`.
|
85 |
```
|
86 |
X:1
|
87 |
+
S:2
|
88 |
+
B:9
|
89 |
+
E:4
|
90 |
+
B:9
|
91 |
+
L:1/8
|
92 |
+
M:3/4
|
93 |
+
K:D
|
94 |
+
de |"D" f2 fedB | A2 AF A2 |"G" B2 Bd B2 |"D" A2 AF A2 |"D" f2 fedB | A2 AF A2 |"G" B2 Bd"A" ce |
|
95 |
+
"D" d4 :: de |"D" f2 fdfa |"Em" g2 gfed |"A7" cecA ce |"D" fdfafd |"D" f2 fdfa |"Em" g2 gfed |
|
96 |
+
"A7" cecA ce |"D" d4 :|
|
97 |
|
98 |
X:2
|
99 |
+
S:2
|
100 |
+
B:9
|
101 |
+
E:4
|
102 |
+
B:9
|
103 |
+
L:1/8
|
104 |
+
M:3/4
|
105 |
+
K:D
|
106 |
+
de |"D" fdcdBd |"D" AdFAdf |"A" gecAce |"D" fdAdde | fdcdBd |"D" AdFAdf |"A" gecAce |"D" d4 :: a2 |
|
107 |
+
"G" gfgbd'b |"D" fad'fad' |"A7" c'bagfe |"D" d'afd A2 |"G" gfgbd'b |"D" fad'fad' |"A7" c'bagfe |
|
108 |
+
"D" d4 :|
|
109 |
|
110 |
X:3
|
111 |
+
S:2
|
112 |
+
B:9
|
113 |
+
E:4
|
114 |
+
B:9
|
115 |
+
L:1/8
|
116 |
+
M:3/4
|
117 |
+
K:D
|
118 |
+
de |"D" f3 e dc |"G" d2 cB AG |"D" F2 A2 d2 |"A7" f4 e2 |"D" f3 e dc |"G" d2 c2 B2 |"A7" A2 B2 c2 |
|
119 |
+
"D" d4 :| FG |"D" A3 B A2 |"D" A3 G FG |"D" A2 d2 f2 |"A7" e4 AA |"G" B2 Bc de |"D" f2 d2 A2 |
|
120 |
+
"G" Bc d2"A7" c2 |"D" d4 :|
|
121 |
```
|
122 |
|
123 |
### Usage
|
124 |
```
|
125 |
+
usage: generate.py [-h] [-num_tunes NUM_TUNES] [-max_patch MAX_PATCH]
|
126 |
+
[-top_p TOP_P] [-top_k TOP_K] [-temperature TEMPERATURE]
|
127 |
+
[-seed SEED] [-show_control_code SHOW_CONTROL_CODE]
|
128 |
+
|
129 |
optional arguments:
|
130 |
-h, --help show this help message and exit
|
131 |
-num_tunes NUM_TUNES the number of independently computed returned tunes
|
132 |
+
-max_patch MAX_PATCH integer to define the maximum length in tokens of each
|
|
|
133 |
tune
|
134 |
-top_p TOP_P float to define the tokens that are within the sample
|
135 |
operation of text generation
|
136 |
+
-top_k TOP_K integer to define the tokens that are within the
|
137 |
+
sample operation of text generation
|
138 |
-temperature TEMPERATURE
|
139 |
the temperature of the sampling operation
|
140 |
-seed SEED seed for randomstate
|
141 |
+
-show_control_code SHOW_CONTROL_CODE
|
142 |
+
whether to show control code
|
143 |
```
|
144 |
|
145 |
### BibTeX entry and citation info
|
|
|
150 |
|
151 |
url = {https://arxiv.org/abs/2301.02884},
|
152 |
|
153 |
+
author = {Wu, Shangda and Sun, Xiaobing Li, Feng Yu, Maosong},
|
154 |
|
155 |
keywords = {Sound (cs.SD), Audio and Speech Processing (eess.AS), FOS: Computer and information sciences, FOS: Computer and information sciences, FOS: Electrical engineering, electronic engineering, information engineering, FOS: Electrical engineering, electronic engineering, information engineering},
|
156 |
|
157 |
+
title = {TunesFormer: Forming Irish Tunes with Control Codes by Bar Patching},
|
158 |
|
159 |
publisher = {arXiv},
|
160 |
|