arXiv:2611.03769cs.SDNov 2026

Manuscript Offprint

arXiv:2611.03769

Metadata-Conditioned Audio Transformers for Adaptive Respiratory Sound Classification

George Kontogiannis, Pantelis Tzamalis, Sotiris Nikoletseas

George Kontogiannis, Pantelis Tzamalis, Sotiris Nikoletseas

Computer Engineering and Informatics Department

University of Patras, Patras, Greece

g.kontogiannis@ac.upatras.gr, tzamalis@ceid.upatras.gr, nikole@ceid.upatras.gr

Abstract—Respiratory sound classification from auscultation recordings is confounded by heterogeneous acquisition conditions, including recording device, auscultation site, and patient characteristics, that introduce systematic variability unrelated to the underlying pathology. Although such metadata is often available, existing approaches either ignore it or rely on naive fusion strategies that do not model how distinct metadata sources influence different components of the acoustic representation.

We propose a family of metadata-conditioning mechanisms for the Audio Spectrogram Transformer (AST), progressing from gated residual fusion to Feature-wise Linear Modulation (FiLM) adapted to the Transformer architecture. We further introduce two novel variants: Token-Aware FiLM (TAFiLM), which applies distinct modulation to classification and patch tokens, and Soft-Factorized FiLM (SoftFiLM), which learns soft masks to align metadata factors with disentangled feature subspaces.

Experiments on the ICBHI benchmark demonstrate consistent gains across all conditioning strategies. SoftFiLM achieves 64.11% on the official 4-class task (+3.94% over the baseline) and 72.40% on the 2-class task, establishing a new state-of-the-art on the 2-class task and competitive performance on the 4-class benchmark.

Index Terms—Respiratory sound classification, Audio Spectrogram Transformer (AST), metadata-conditioning, Feature-wise Linear Modulation (FiLM), ICBHI.

I. INTRODUCTION

Respiratory diseases remain a leading cause of morbidity and mortality worldwide, with auscultation serving as a fundamental diagnostic tool for identifying pulmonary abnormalities [1]. The advent of digital stethoscopes has enabled the collection of large-scale respiratory sound databases, paving the way for automated classification systems that could assist clinicians in resource-limited settings. The ICBHI 2017 Respiratory Sound Database [2] has emerged as the primary benchmark for this task.

Deep learning approaches have achieved substantial progress on this benchmark under the official 60-40% train-test split. Early CNN-based methods applied ResNet [3] and VGG architectures to mel-spectrogram representations, while hybrid CNN-RNN networks addressed temporal modeling of respiratory phases [4]–[6]. More recently, Transformer-based architectures have set new state-of-the-art results: the Audio Spectrogram Transformer (AST) [7] and its variants have demonstrated strong performance through transfer learning from large-scale audio pretraining [8], [9], while more recent approaches [10], [11], use multimodal audio-text models to achieve higher performances.

Despite these advances, a critical limitation persists: most methods treat the acoustic signal in isolation, ignoring the available metadata that accompanies each recording. The ICBHI dataset exhibits substantial acquisition heterogeneity arising from multiple sources: four different recording devices with distinct frequency responses and noise characteristics; seven anatomical auscultation sites spanning anterior, posterior, lateral chest, and tracheal positions; and diverse patient demographics including sex, age, BMI, and breathing cycle duration. This heterogeneity introduces acquisition-induced distributional bias that confound the underlying pathological signatures. Prior work [3] demonstrated that device distribution is highly skewed and classification performance correlates strongly with device-specific training set size, yet proposed only post-hoc device-specific fine-tuning rather than explicit conditioning. Our statistical analysis of the dataset (Section II) confirms these findings and further reveals significant effects of auscultation site and patient characteristics on classification difficulty.

Only a handful of recent works have attempted to leverage metadata for respiratory sound classification. The BTS framework [10] converts metadata into free-text descriptions (e.g., “recorded with Littmann stethoscope at the anterior left chest”) and fuses text embeddings with audio features via a CLAP-style architecture, achieving modest improvements (+1.17% Score over audio-only baseline). Contrastive learning approaches have used metadata for auxiliary objectives: sex and age were employed as pretext tasks for self-supervised pretraining [9], while stethoscope types were treated as separate domains for domain-adversarial training [12] or domain generalization [13].

However, these methods share common limitations: they either require expensive multimodal encoders, operate only at the representation learning stage without conditioning inference, address device and demographic factors in isolation, or employ naive fusion strategies (e.g., feature concatenation) that fail to capture how different metadata sources affect distinct aspects of the acoustic representation. Crucially, no prior work applies feature-wise conditioning mechanisms that can dynam-

Funded by the Horizon Europe project PHOTOMIX, grant agreement ID: 101297290.

ically modulate the acoustic encoder's internal representations based on the full recording context.

Feature-wise Linear Modulation (FiLM) [14] offers an elegant solution to this gap. Originally proposed for visual question answering, FiLM enables a conditioning signal to modulate neural network activations through learned scale ( γ\gamma) and shift ( β\beta) parameters applied after normalization layers. However, while FiLM was originally designed for CNNs, its adaptation to Vision Transformers and Audio Spectrogram Transformers remains underexplored, and it has never been applied to respiratory sound classification or medical audio analysis more broadly.

Standard FiLM applies uniform modulation across all spatial positions (or Transformer tokens) and treats the conditioning signal as a single vector, which overlooks two key points. First, in Transformers, the classification token (CLS) aggregates global information while patch tokens capture local spectro-temporal patterns, yet standard FiLM modulates them identically. Second, different metadata sources (device, site, demographics) affect distinct aspects of the acoustic signal: device shapes spectral characteristics and noise, site determines audible lung sounds, and patient factors influence breath intensity and baseline. Uniform treatment of all metadata ignores this factor-specific structure.

In this paper, we formalize metadata conditioning as structured feature modulation within Transformer-based acoustic encoders. Rather than treating metadata as auxiliary inputs, we model acquisition context as a factorized conditioning signal that reshapes internal representations throughout the network hierarchy. Our main contributions are:

  1. We perform the first comprehensive metadata-level analysis of ICBHI, quantifying device bias, auscultation site effects, and demographic confounds. This reveals systematic domain shifts, motivates metadata conditioning, and identifies discriminative versus confounding factors.

  2. We provide the first systematic study of metadata conditioning for respiratory sound classification, adapting Feature-wise Linear Modulation (FiLM) to the Audio Spectrogram Transformer and demonstrating its effectiveness for encoding acquisition context.

  3. We introduce Token-Aware FiLM (TAFiLM) and Soft-Factorized FiLM (SoftFiLM). TAFiLM modulates classification vs. patch tokens separately, while SoftFiLM learns factor-aligned soft masks partitioning features into metadata-specific subspaces.

  4. We achieve competitive four-class and state-of-the-art two-class ICBHI results: SoftFiLM reaches 64.11% (+3.94%) and 72.40% (+2.32%) respectively. Ablations show full fine-tuning and conditioning all layers maximize gains, and qualitative analysis confirms interpretable factor disentanglement. Code is released for reproducibility. 1^{1}

References (27)