liveBook · Manning

Velocity

As explained in Learn Generative AI with PyTorch

A musical performance attribute indicating how forcefully a note is played, represented as an event/value in the encoding.

Velocity measures how forcefully a musical note is played. In MIDI, it accompanies note-on and note-off messages and ranges from 0 to 127; higher values indicate louder or more forceful performance. section 14.1.1

Velocity differs from pitch: pitch identifies the note, while velocity captures its performance dynamics. During tokenization, original values are reduced to 32 bins, producing velocity events with values from 0 to 31. section 14.1.1 section 14.2.2

Use velocity in a performance-based music representation to:

  • Preserve expressive differences between forceful and gentle notes. section 14.1.1
  • Represent changing dynamics as separate velocity events alongside note-on, note-off, and time-shift events. section 14.1.1
  • Control vocabulary size by mapping each original velocity to a 32-bin token value. section 14.1.1 section 14.2.2

A velocity event in practice

A note-on event for pitch 74 with velocity 86 records a D5 played forcefully. After tokenization, velocity 86 becomes velocity value 21, followed by a note-on event with value 74.

Listing 14.1 Example notes in a performance-based music representation
<[SNote] time: 1.0325520833333333 type: note_on, value: 74, velocity: 86>
<[SNote] time: 1.0442708333333333 type: note_on, value: 38, velocity: 77>
<[SNote] time: 1.2265625 type: note_off, value: 74, velocity: None>
<[SNote] time: 1.2395833333333333 type: note_on, value: 73, velocity: 69>
<[SNote] time: 1.2408854166666665 type: note_on, value: 37, velocity: 64>

Inspect the first five performance events to see velocity attached to note-on events and absent from the note-off event. section 14.1.1

How Learn Generative AI with PyTorch covers it

How deep it goes
Defines forcefulness, shows MIDI values and 32-bin tokenization, but defers the detailed MIDI-to-event conversion.
Examples
Uses MIDI notes with velocity 86 and 77, then maps velocity 86 to token value 21.
What it assumes
Builds from MIDI note-on and note-off messages while defining velocity and its dynamics scale explicitly.
What you can do after
Apply it via processor.py by converting MIDI performance notes into velocity events and indexed music tokens.
How it connects
Connects velocity with MIDI, note-on events, note-off events, time-shift events, tokenization, and music Transformers.

This explainer was generated by Manning's knowledge graph from the text of Learn Generative AI with PyTorch. The section links point to the parts of the book it draws on.