tempo_classification¶
Tempo-as-classification: a softmax over BPM bins with a Gaussian soft target.
Instead of regressing a number, the model scores a discrete grid of BPM bins.
The target is not one-hot but a Gaussian centred on the true tempo, which
gives the bin grid back its ordinal structure — a neighbouring bin is a near
miss, not an unrelated class. Selected by loss: classification and
dispatched by TempoModule, which
also supplies the bin grid and sigma.
Functions
|
Cross-entropy between predicted softmax and Gaussian soft target. |
|
Soft target distribution over tempo bins. |
- classification_tempo_loss(logits, tempo, bin_centers, sigma)[source]¶
Cross-entropy between predicted softmax and Gaussian soft target.
\[\mathcal{L} = -\frac{1}{B} \sum_{i=1}^{B} \sum_{j=1}^{n_{\text{bins}}} p_{i,j} \log \hat{p}_{i,j}\]where \(p_{i,j}\) is the Gaussian soft target from
gaussian_soft_target()and \(\hat{p}_{i,j}\) is the model’s softmax probability for bin \(j\).- Parameters:
logits (Tensor) – Model logits over BPM bins, shape
(B, n_bins).tempo (Tensor) – True BPM values, shape
(B,).bin_centers (Tensor) – BPM at the centre of each bin, shape
(n_bins,).sigma (float) – Gaussian standard deviation in BPM units.
- Returns:
Scalar mean loss, shape
().- Return type:
Tensor
- gaussian_soft_target(tempo, bin_centers, sigma)[source]¶
Soft target distribution over tempo bins.
For each sample, places a Gaussian centred on the true tempo across the discrete bin grid, then normalises to a probability distribution. Bins near the true tempo receive non-zero target mass, which gives the model a smoother gradient than a one-hot target and bakes in the ordinal structure of the bin grid.
\[p_{i,j} = \frac{\exp\left(-\frac{1}{2}\left(\frac{c_j - y_i}{\sigma}\right)^2\right)} {\sum_{k=1}^{n_{\text{bins}}} \exp\left(-\frac{1}{2}\left(\frac{c_k - y_i}{\sigma}\right)^2\right)}\]where \(c_j\) is the centre of bin \(j\) and \(y_i\) is the true tempo of sample \(i\).
- Parameters:
tempo (Tensor) – True BPM values, shape
(B,).bin_centers (Tensor) – BPM at the centre of each bin, shape
(n_bins,).sigma (float) – Gaussian standard deviation in BPM units.
- Returns:
Soft target distribution, shape
(B, n_bins).- Return type:
Tensor