Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Speechbrain Speechbrain InterpreterBrain

From Leeroopedia


Knowledge Sources
Domains Sound_Classification, Interpretability
Last Updated 2026-02-09 00:00 GMT

Overview

Concrete tool providing the parent class for interpretability recipes in the SpeechBrain library.

Description

This module defines the InterpreterBrain class (subclass of sb.core.Brain) which serves as the shared parent class for all interpretability training recipes (L2I and LMAC). It provides common functionality including STFT inversion with phase reconstruction, audio preprocessing (STFT computation, mel-spectrogram, log-power features), classifier forward pass abstraction supporting multiple backbone architectures (CNN14, FocalNet, ViT, Conv2D), and quantitative evaluation using the Quantus library for faithfulness metrics. The class handles both standard spectral features and mel-spectrogram pathways.

Usage

This class is not intended to be used directly. Instead, it is subclassed by L2I and LMAC interpreter training recipes which implement the specific interpretation computation logic. It provides the shared infrastructure for preprocessing, classifier inference, and evaluation.

Code Reference

Source Location

Signature

class InterpreterBrain(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

from interpreter_brain import InterpreterBrain

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, phase, classifier outputs, and original features
loss torch.Tensor Interpretation fidelity loss value

Usage Examples

# Subclass InterpreterBrain for a custom interpreter:
from interpreter_brain import InterpreterBrain

class MyInterpreter(InterpreterBrain):
    def interpret_computation_steps(self, wavs_batch):
        # Custom interpretation logic
        ...

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment