Views
No views yet
+------------------+
| Raw Audio Wave |
+--------+---------+
|
+---------------------+---------------------+
| |
v v
+-----------------+ +-----------------+
| WavLM-Base | | CLAP Audio |
| (Speech/Vocal) | | (Acoustic/Sfx) |
+--------+--------+ +--------+--------+
| |
v v
+-----------------+ +-----------------+
| Linear Project | | Linear Project |
| (768 -> 512) | | (768 -> 512) |
+--------+--------+ +--------+--------+
| |
+---------------------+---------------------+
|
v
+-----------------+
| Feature Concat |
| (1024-dim) |
+--------+--------+
|
v
+-----------------+
| LayerNorm + Tanh|
+--------+--------+
|
+---------------------+---------------------+---------------------+
| | | |
v v v v
+-----------------+ +-----------------+ +-----------------+ +-----------------+
| Emotion Head | | Vibe Head | | Intensity Head | | Tempo Head |
| (28 Classes) | | (4 Classes) | | (3 Classes) | | (3 Classes) |
+-----------------+ +-----------------+ +-----------------+ +-----------------+microsoft/wavlm-base processes raw waveforms to capture structural temporal context, pitch contours, and vocal delivery dynamics.laion/clap-htsat-unfused processes raw waveforms via an unfused HTSAT topology to capture global acoustic textures, instrumental signatures, and overall arrangement timbre.wlm_proj, clp_proj) to a stabilized 512-dimensional subspace before concatenation.LayerNorm $\rightarrow$ Tanh $\rightarrow$ Dropout(0.3) projection pipeline to prevent intermediate feature exploding.admiration, amusement, anger, annoyance, approval, caring, confusion, curiosity, desire, disappointment, disapproval, disgust, embarrassment, excitement, fear, gratitude, grief, joy, love, nervousness, optimism, pride, realization, relief, remorse, sadness, surprise, neutral.aggressive, atmospheric, melancholic, technical.low, medium, high.slow, moderate, fast.AdamW with discriminative learning rates ($3\times10^{-5}$ for base transformers, $1\times10^{-4}$ for projection blocks and multi-task heads) and a weight decay coefficient of $0.01$.torch.amp.1import torch
2import torch.nn as nn
3import torch.nn.functional as F
4from transformers import WavLMModel, ClapAudioModel
5
6class AudioMathRockModel(nn.Module):
7 def __init__(self) -> None:
8 super().__init__()
9 # Initialize pretrained dual backbone transformers
10 self.wavlm = WavLMModel.from_pretrained("microsoft/wavlm-base")
11 self.clap = ClapAudioModel.from_pretrained("laion/clap-htsat-unfused")
12
13 # Downstream embedding projection layers
14 self.wlm_proj = nn.Linear(768, 512)
15 self.clp_proj = nn.Linear(768, 512)
16
17 # Non-linear fusion pipeline
18 self.fusion = nn.Sequential(
19 nn.Linear(1024, 512),
20 nn.LayerNorm(512),
21 nn.Tanh(),
22 nn.Dropout(0.3),
23 )
24
25 # Multi-task classification networks
26 self.emo_head = nn.Sequential(
27 nn.Linear(512, 256), nn.GELU(), nn.Dropout(0.2),
28 nn.Linear(256, 28), # 28 independent multi-label emotions
29 )
30 self.vibe_head = nn.Linear(512, 4) # 4 acoustic vibes
31 self.int_head = nn.Linear(512, 3) # 3 intensity classes
32 self.tmp_head = nn.Linear(512, 3) # 3 tempo classes
33
34 def forward(self, wavlm_values: torch.Tensor, clap_values: torch.Tensor) -> tuple:
35 # Extract temporal mean features from WavLM and pooled features from CLAP
36 wlm_feats = self.wavlm(wavlm_values).last_hidden_state.mean(dim=1)
37 clp_feats = self.clap(clap_values).pooler_output
38
39 # Project features into balanced dimension space
40 wlm_p = F.gelu(self.wlm_proj(wlm_feats))
41 clp_p = F.gelu(self.clp_proj(clp_feats))
42
43 # Perform feature concatenation and multi-head prediction
44 fused = self.fusion(torch.cat([wlm_p, clp_p], dim=-1))
45 return self.emo_head(fused), self.vibe_head(fused), self.int_head(fused), self.tmp_head(fused)
46
47# Initialize and load model checkpoints
48device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
49model = AudioMathRockModel().to(device)
50
51checkpoint = torch.load("model.pth", map_location=device)
52model.load_state_dict(checkpoint["model_state_dict"])
53model.eval()