Speech & Audio AI Lab

Interactive labs for speech recognition, speech synthesis, and audio in general: in-browser DSP experiments, algorithms, datasets, and a learning path, without storing any recording.

43experiments

ECAPA-TDNN

ECAPA-TDNN

AdvancedSpeaker Recognition

Educational content in the form of a scientific draft that needs expert review before being adopted as an academic reference. No experimental result that was not actually run is shown here.

Definition

A speaker encoder that develops x-vectors with Res2Net blocks, SE channel attention, multi-layer feature aggregation, and attentive statistics pooling, and is usually trained with the AAM-softmax loss.

Mathematical Idea

SE-Res2Net blocks capture multi-scale temporal contexts and recalibrate channels. The outputs of the intermediate blocks are aggregated before attentive pooling, which gives each frame a weight according to its channel and context. Finally, the linear layer is trained with an angular margin to bring embeddings of the same speaker closer.

How It Works

  1. Mel features and an initial TDNN layer
  2. Stacked SE-Res2Net blocks
  3. Aggregate block outputs (MFA)
  4. Attentive statistics pooling
  5. Linear layer to embedding
  6. AAM-softmax classification for training

Stages Diagram

  1. Features
  2. TDNN
  3. SE-Res2Net blocks
  4. MFA
  5. Attentive pooling
  6. Embedding

Equations

$$\alpha_t=\mathrm{softmax}_t\big(v^{\top}f(Wh_t+b)+k\big),\quad \tilde\mu=\sum_t\alpha_t h_t$$

Attention weights and mean pooling.

$$\mathcal{L}=-\log\frac{e^{s\cos(\theta_y+m)}}{e^{s\cos(\theta_y+m)}+\sum_{j\ne y}e^{s\cos\theta_j}}$$

AAM-softmax; $m$ is the angular margin and $s$ is the scale.

Advantages

  • Strong discriminative speaker embeddings
  • Channel and frame attention
  • Modern standard architecture in verification

Limitations

  • Heavier model than x-vectors
  • Needs a lot of diverse data
  • Sensitive to domain, language, and channel

Use Cases

  • Educational speaker verification
  • Speaker diarization
  • Diagnosing speaker-related features

Applied Example

In the code, the margin m=0.2 makes the loss larger than m=0 on the same batch, and this is intended: it forces the model to separate the classes more clearly.

Code Example

PythonImplemented and Tested
import numpy as np
def aam_softmax_loss(emb, W, y, s=30.0, m=0.2):
    e = emb / np.linalg.norm(emb, axis=1, keepdims=True)
    w = W / np.linalg.norm(W, axis=1, keepdims=True)
    cos = np.clip(e @ w.T, -1, 1)                         # (B, C)
    theta = np.arccos(cos)
    idx = np.arange(len(y))
    logits = cos.copy()
    logits[idx, y] = np.cos(theta[idx, y] + m)            # angular margin for the correct class
    logits *= s
    logits -= logits.max(axis=1, keepdims=True)
    p = np.exp(logits); p /= p.sum(axis=1, keepdims=True)
    return -np.log(p[idx, y]).mean()
rng = np.random.default_rng(0)
emb = rng.normal(size=(8, 16)); W = rng.normal(size=(5, 16)); y = rng.integers(0, 5, 8)
print(aam_softmax_loss(emb, W, y, m=0.0) < aam_softmax_loss(emb, W, y, m=0.2))  # True: the margin increases the loss

References

  1. Desplanques et al.. ECAPA-TDNN: Emphasized Channel Attention, Propagation and Aggregation in TDNN Based Speaker Verification. arXiv (2020). DOI
  2. Snyder, Garcia-Romero, Sell, Povey, Khudanpur. X-Vectors: Robust DNN Embeddings for Speaker Recognition. 2018 IEEE International Conference on Acoustics, Speech and Signal Processing (ICASSP) (2018). DOI
  3. Ravanelli et al.. SpeechBrain: A General-Purpose Speech Toolkit. arXiv preprint (2021). DOI
  4. Chung et al.. VoxCeleb2: Deep Speaker Recognition (2018). Source

Audio processing in the experiments takes place inside your browser. Audio, texts, and conversations are not saved on the server. Privacy Policy