Implementation:Speechbrain Speechbrain Interpret AMT
| Knowledge Sources | |
|---|---|
| Domains | Sound_Classification, Interpretability |
| Last Updated | 2026-02-09 00:00 GMT |
Overview
Concrete tool for interpreting audio classifiers by-design via activation map thresholding (AMT) provided by the SpeechBrain library.
Description
This recipe defines the InterpreterESC50Brain class (subclass of sb.core.Brain) for interpreting audio classifiers using activation map thresholding. The approach extracts intermediate activation maps (modulators for FocalNet, attention maps for ViT) from a pre-trained classifier, aggregates them to form a saliency mask, and applies it to the input spectrogram to isolate class-relevant regions. The resulting interpretation spectrogram is inverted back to waveform using STFT phase reconstruction. Supports both FocalNet and ViT backbone architectures.
Usage
Use this recipe to generate interpretations of ESC-50 classifier predictions using activation map thresholding. Requires a pre-trained classifier checkpoint and the ESC-50 dataset. Configure with amt_focalnet.yaml or amt_vit.yaml depending on the backbone.
Code Reference
Source Location
- Repository: SpeechBrain
- File: recipes/ESC50/interpret/interpret_amt.py
Signature
class InterpreterESC50Brain(sb.core.Brain):
def invert_stft_with_phase(self, X_int, X_stft_phase):
...
def preprocess(self, wavs):
...
def classifier_forward(self, X_stft_logpower):
...
def compute_forward(self, batch, stage):
...
def compute_objectives(self, predictions, batch, stage):
...
Import
python recipes/ESC50/interpret/interpret_amt.py hparams/amt_focalnet.yaml --data_folder /path/to/ESC-50-master
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, STFT phase, classifier predictions, original spectrogram |
| loss | torch.Tensor | Interpretation fidelity loss value |
Usage Examples
python interpret_amt.py hparams/amt_focalnet.yaml --data_folder /path/to/ESC-50-master