Implementation:Speechbrain Speechbrain Train LMAC
| Knowledge Sources | |
|---|---|
| Domains | Sound_Classification, Interpretability |
| Last Updated | 2026-02-09 00:00 GMT |
Overview
Concrete tool for training the L-MAC interpreter model for audio classifiers provided by the SpeechBrain library.
Description
This recipe defines the LMAC class (subclass of InterpreterBrain) for training the L-MAC (Listenable Maps for Audio Classifiers) interpreter. L-MAC generates interpretation masks that isolate class-relevant regions in audio spectrograms. It includes a cross-correlation metric (supporting both convolution-based and dot-product variants) for fine-tuning, total variation (TV) loss for mask smoothness, and support for NMF-based spectrogram decomposition. The interpretation pipeline produces listenable audio excerpts highlighting the most salient regions for each class prediction.
Usage
Use this recipe to train an L-MAC interpreter on the ESC-50 dataset. Requires the ESC-50 data folder and a pre-trained classifier checkpoint. Supports WHAM! noise augmentation as used in the L-MAC paper. Configure with lmac_cnn14.yaml.
Code Reference
Source Location
- Repository: SpeechBrain
- File: recipes/ESC50/interpret/train_lmac.py
Signature
class LMAC(InterpreterBrain):
def crosscor(self, spectrogram, template):
...
def interpret_computation_steps(self, wavs_batch):
...
def compute_forward(self, batch, stage):
...
def compute_objectives(self, predictions, batch, stage):
...
Import
python recipes/ESC50/interpret/train_lmac.py hparams/lmac_cnn14.yaml --data_folder /path/to/ESC50 --add_wham_noise True --wham_folder /path/to/wham_noise
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| batch | PaddedBatch | Yes | Batch containing sig (waveforms) and class_string_encoded (labels) |
| stage | sb.Stage | Yes | TRAIN, VALID, or TEST |
Outputs
| Name | Type | Description |
|---|---|---|
| predictions | tuple | Interpretation spectrogram, mask, STFT phase, classifier predictions |
| loss | torch.Tensor | Combined interpretation fidelity, TV loss, and classification loss |
Usage Examples
python train_lmac.py hparams/lmac_cnn14.yaml --data_folder /path/to/ESC50 --add_wham_noise True --wham_folder /path/to/wham_noise