Update README.md
Browse files
README.md
CHANGED
@@ -55,7 +55,7 @@ The data encodes midi information as encoded text. Here are some examples of wha
|
|
55 |
|
56 |
Training was done through Google Colab's free tier, using a single 15GB Tesla T4 GPU.
|
57 |
Training was logged through Weights and Biases.
|
58 |
-
A link to the full training notebook can be found [here]
|
59 |
|
60 |
### Training hyperparameters
|
61 |
|
@@ -118,4 +118,123 @@ The following hyperparameters were used during training:
|
|
118 |
- Transformers 4.35.2
|
119 |
- Pytorch 2.1.0+cu118
|
120 |
- Datasets 2.15.0
|
121 |
-
- Tokenizers 0.15.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
|
56 |
Training was done through Google Colab's free tier, using a single 15GB Tesla T4 GPU.
|
57 |
Training was logged through Weights and Biases.
|
58 |
+
A link to the full training notebook can be found [here](https://colab.research.google.com/drive/1uvv-ChthIrmEJMBOVyL7mTm4dcf4QZq7#scrollTo=34kpyWSnaJE1)
|
59 |
|
60 |
### Training hyperparameters
|
61 |
|
|
|
118 |
- Transformers 4.35.2
|
119 |
- Pytorch 2.1.0+cu118
|
120 |
- Datasets 2.15.0
|
121 |
+
- Tokenizers 0.15.0
|
122 |
+
|
123 |
+
|
124 |
+
<hr/>
|
125 |
+
The sections below this point serve as a user guide for the Hugging Face space found [here](https://huggingface.co/spaces/Katpeeler/Midi_space2)
|
126 |
+
<hr/>
|
127 |
+
|
128 |
+
|
129 |
+
|
130 |
+
# Introduction
|
131 |
+
|
132 |
+
Midi_space2 allows the user to generate a four-bar musical progression, and listen back to it.
|
133 |
+
There are two sections to interact with: audio generation, and token generation.
|
134 |
+
|
135 |
+
- Audio generation contains 3 sliders:
|
136 |
+
- Inst number: a value that adjusts the tonality of the sound.
|
137 |
+
- Note number: a value that adjusts the reference pitch the sound is generated from.
|
138 |
+
- BPM: the beats per minute, or the speed of the sound.
|
139 |
+
|
140 |
+
- Token generation is a secondary function, and allows the user to see what the language model generated.
|
141 |
+
- Please note that this section will display an "error" if used before any audio is generated.
|
142 |
+
- This section shows the tokens that are responsible for the audio you hear in the audio generation section.
|
143 |
+
|
144 |
+
|
145 |
+
|
146 |
+
## Usage
|
147 |
+
|
148 |
+
To run the demo, click on the link [here](https://huggingface.co/spaces/Katpeeler/Midi_space2)
|
149 |
+
|
150 |
+
The demo will default to the "audio generation" tab. Here you will find the 3 sliders you can interact with. These are:
|
151 |
+
|
152 |
+
- Inst number
|
153 |
+
- Note number
|
154 |
+
- BPM
|
155 |
+
|
156 |
+
When you have selected values you want to try, click the "generate audio" button at the bottom.
|
157 |
+
When your audio is ready, you will see the audio waveform displayed within the "audio" box, found above the sliders.
|
158 |
+
**Note**
|
159 |
+
Due to how audio is handled in Google Chrome, you may have to generate the audio a few times, the first time you use this demo.
|
160 |
+
|
161 |
+
Additionaly, you may select the "Token Generation" tab, and click the "show generated tokens" button there to see the raw text data.
|
162 |
+
|
163 |
+
|
164 |
+
|
165 |
+
## Documentation
|
166 |
+
|
167 |
+
You can view the Google Colab notebook used for training [here](https://colab.research.google.com/drive/1uvv-ChthIrmEJMBOVyL7mTm4dcf4QZq7#scrollTo=qWq2lY0vWFTD)
|
168 |
+
|
169 |
+
|
170 |
+
- The demo is currently hosted as a Gradio application on Hugging Face Spaces.
|
171 |
+
- For audio to be heard, we use the soundfile package.
|
172 |
+
|
173 |
+
The core components are this gpt2 model, [js-fakes-4bars dataset](https://huggingface.co/datasets/TristanBehrens/js-fakes-4bars), and [note-seq](https://github.com/magenta/note-seq).
|
174 |
+
The dataset was created by [Tristan Behrens](https://huggingface.co/TristanBehrens), and is a relatively small size.
|
175 |
+
This made it perfect for training a gpt2 model through the free-tier of Google Colab. I selected this dataset after finding
|
176 |
+
a different dataset on Huggingface, [mmm_track_lmd_8bars_nots](https://huggingface.co/datasets/juancopi81/mmm_track_lmd_8bars_nots).
|
177 |
+
I initally used this dataset, but ran out of free-tier compute resources about 3 hours into training. This setback made me ultimately
|
178 |
+
decide on using a smaller dataset for the time being.
|
179 |
+
|
180 |
+
- Js-fakes dataset size: 13.7mb, 4,479 rows (The one I actually used)
|
181 |
+
- Juancopi81 dataset size: 490mb, 177,567 rows (The one I attempted to use first)
|
182 |
+
|
183 |
+
For the remained of this post, we will only discuss the js-fakes dataset.
|
184 |
+
|
185 |
+
After downloading, the training split contained 3614 rows, and the test split contained 402 rows. Each entry follows this format:
|
186 |
+
|
187 |
+
PIECE_START STYLE=JSFAKES GENRE=JSFAKES TRACK_START INST=48 BAR_START NOTE_ON=70 TIME_DELTA=2 NOTE_OFF=70 NOTE_ON=72 TIME_DELTA=2 NOTE_OFF=72 NOTE_ON=72 TIME_DELTA=2 NOTE_OFF=72 NOTE_ON=70 TIME_DELTA=4 NOTE_OFF=70 NOTE_ON=69 TIME_DELTA=2 NOTE
|
188 |
+
|
189 |
+
This data is in a very specific tokenized format, representing the information that is relevant to playing a note. Of note:
|
190 |
+
|
191 |
+
- NOTE_ON=## : represents the start of a musical note, and which note to play, (A, B, C, etc.)
|
192 |
+
- TIME_DELTA=4 : represents a quarter note. A half note is represented by TIME_DELTA=8, and an eigth note would be represented by TIME_DELTA=2.
|
193 |
+
- NOTE_OFF=## : represents the end of a musical note, and which note to end.
|
194 |
+
|
195 |
+
These text-based tokens contain the neccessary information to create Midi, a standard form of synthesized music data.
|
196 |
+
The dataset used has already transposed between MIDI files, and this text-based format.
|
197 |
+
This format is called "MMM", or Multi-Track Music Machine, proposed in the paper found [here](https://arxiv.org/abs/2008.06048).
|
198 |
+
|
199 |
+
**Note**
|
200 |
+
I created a tokenizer for this task, and uploaded it to my HuggingFace profile. However, I ended up using the auto-tokenizer from the fine-tuned model,
|
201 |
+
so I won't be exploring that further.
|
202 |
+
|
203 |
+
I used Tristan Behren's js-fakes-4bars tokenizer to tokenize the dataset for training. I selected a context length of 512, and truncated all text longer than that.
|
204 |
+
This helped with using limited resources.
|
205 |
+
|
206 |
+
The GPT-2 model used was 19.2M parameters. It was trained in steps of 300, through 10 epochs. This is the third iteration of models, and you can find the first two on my HuggingFace profile.
|
207 |
+
I ended up using a batch size of 4 to further reduce the VRAM requirements in Google Colab. Specifics for the training can be found at the top of this page, but some fun things to note are:
|
208 |
+
|
209 |
+
- Total training runtime: around 13 minutes
|
210 |
+
- Training samples per second: 45.91
|
211 |
+
- Training steps per second: 11.484
|
212 |
+
- Average GPU watt usage: 66W
|
213 |
+
- Average GPU temperature: 77C
|
214 |
+
|
215 |
+
I think it's important to note the power draw of the GPUs used for training any model, as we enter into this modern era of normalizing this technology.
|
216 |
+
I obtained those values through [Weights and Biases](https://wandb.ai/site), which I ran alongside my training.
|
217 |
+
The training method used is outlined in a blog post by Juancopi81 [here](https://huggingface.co/blog/juancopi81/using-hugging-face-to-train-a-gpt-2-model-for-musi#showcasing-the-model-in-a-%F0%9F%A4%97-space).
|
218 |
+
While I didn't follow that post exactly, it was of great help when learning how to do this.
|
219 |
+
|
220 |
+
The final component to talk about is Magenta's note_seq library. This is how token sequences are transposed to note sequences, and played.
|
221 |
+
This library is much more powerful than I am implementing, and I plan on expanding this project in the future to incorporate more features.
|
222 |
+
The main method call for this can be found in the app.py file on the HuggingFace space, but here is a snippet of the code for NOTE_ON:
|
223 |
+
|
224 |
+
elif token.startswith("NOTE_ON"):
|
225 |
+
pitch = int(token.split("=")[-1])
|
226 |
+
note = note_sequence.notes.add()
|
227 |
+
note.start_time = current_time
|
228 |
+
note.end_time = current_time + 4 * note_length_16th
|
229 |
+
note.pitch = pitch
|
230 |
+
note.instrument = current_instrument
|
231 |
+
note.program = current_program
|
232 |
+
note.velocity = 80
|
233 |
+
note.is_drum = current_is_drum
|
234 |
+
current_notes[pitch] = note
|
235 |
+
|
236 |
+
In short, there are instructions for each type of token that is used in the vocabulary, and once you identify what something is supposed to be,
|
237 |
+
it can be easily mapped to do whatever we want! Pretty cool, and it supports as many instruments as you want.
|
238 |
+
|
239 |
+
|
240 |
+
|