liveBook · Manning

Time-shift event

As explained in Learn Generative AI with PyTorch

A musical event in the encoding that advances the represented time between note events.

A time-shift event advances the represented time between musical events. In performance-based music encoding, it replaces continuous timestamps with discrete timing increments so a MIDI performance can become a token sequence for a music Transformer. section 14.1.1 section 14.2.2

Read each time-shift value as a duration increment:

  • Durations longer than 1 second are split across multiple time-shift events. section 14.1.1
  • Time-shift events appear alongside note-on, note-off, and velocity events, preserving timing while separating pitch, release, and dynamics. section 14.1.1

Encoding the first note

A note beginning at approximately 1.0326 seconds follows two time-shift tokens with values 99 and 2. Together they represent 1 second plus 0.03 seconds, after which a velocity event and note-on event encode the note.

During conversion, the encoder generates time shifts from the gap between the previous event time and the current note time. The resulting events can then be converted to indexes for model training; the inverse mapping reconstructs event types and values.

How Learn Generative AI with PyTorch covers it

How deep it goes
Defines 0.01-second quantization and multi-token durations, while deferring detailed MIDI conversion internals.
Examples
Uses timestamped notes, the 99-and-2 token pair, and a generated sequence interleaving timing with velocity and note events.
What it assumes
Assumes familiarity with MIDI notes and timestamps, while defining the four event types and discretization scheme.
What you can do after
Apply via processor.py to convert MIDI timing into event sequences and indexes, then reconstruct event tokens.
How it connects
Connects MIDI, tokenization, note-on events, note-off events, velocity events, 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.