tempo_regression

Regression losses on a single BPM value per clip.

Both are mean absolute error; they differ only in whether predicting a metrical multiple of the annotated tempo is treated as an error. Selected by loss: absolute / loss: relative and dispatched by TempoModule.

Functions

absolute_tempo_loss(pred, target)

Plain MAE between predicted and target BPM values.

relative_tempo_loss(pred, target[, factors])

MAE loss invariant to metrical octave errors.

absolute_tempo_loss(pred, target)[source]

Plain MAE between predicted and target BPM values.

Unlike relative_tempo_loss(), this penalises octave errors in full, so the model is pushed to predict the exact annotated tempo.

\[\mathcal{L} = \frac{1}{B} \sum_{i=1}^{B} \left| \hat{y}_i - y_i \right|\]
Parameters:
  • pred (Tensor) – Predicted BPM values, shape (B,).

  • target (Tensor) – Ground-truth BPM values, shape (B,).

Returns:

Scalar mean loss, shape ().

Return type:

Tensor

relative_tempo_loss(pred, target, factors=(0.5, 1.0, 2.0))[source]

MAE loss invariant to metrical octave errors.

For each sample, computes the absolute error between the prediction and each factor × target, then takes the minimum. Predicting double or half the annotated tempo incurs zero penalty — both are musically valid metrical interpretations of the same groove.

\[\mathcal{L} = \frac{1}{B} \sum_{i=1}^{B} \min_{f \in \text{factors}} \left| \hat{y}_i - f \cdot y_i \right|\]
Parameters:
  • pred (Tensor) – Predicted BPM values, shape (B,).

  • target (Tensor) – Ground-truth BPM values, shape (B,).

  • factors (tuple) – Metrical multiples to consider (default: 0.5×, 1×, 2×).

Returns:

Scalar mean loss, shape ().

Return type:

Tensor