Implementation:Speechbrain Speechbrain Train L2I
| Knowledge Sources | |
|---|---|
| Domains | Sound_Classification, Interpretability |
| Last Updated | 2026-02-09 00:00 GMT |
Overview
Concrete tool for training the L2I (Listen to Interpret) model to interpret audio classifiers provided by the SpeechBrain library.
Description
This recipe defines the L2I class (subclass of InterpreterBrain) for training the L2I interpreter as described in the paper (https://arxiv.org/abs/2202.11479). The L2I model learns to generate interpretation spectrograms that highlight class-relevant regions in audio. It uses NMF (Non-negative Matrix Factorization) with a learned psi network to produce activation maps, which are combined with NMF dictionary components to form interpretation masks. The interpretation is applied to the original spectrogram and inverted back to audio via STFT phase reconstruction.
Usage
Use this recipe to train an L2I interpreter on the ESC-50 dataset. Requires the ESC-50 data folder and a pre-trained classifier checkpoint. Optionally supports WHAM! noise augmentation. Configure with l2i_cnn14.yaml or l2i_conv2d.yaml.
Code Reference
Source Location
- Repository: SpeechBrain
- File: recipes/ESC50/interpret/train_l2i.py
Signature
class L2I(InterpreterBrain):
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_l2i.py hparams/l2i_cnn14.yaml --data_folder /path/to/ESC50
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, NMF mask, STFT phase, classifier predictions |
| loss | torch.Tensor | Combined interpretation fidelity and classification loss |
Usage Examples
python train_l2i.py hparams/l2i_cnn14.yaml --data_folder /path/to/ESC50