1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
| """ 论文:BiCFlow-MER: Conditional Transport for Multimodal Emotion Recognition arXiv: 2609.27615
核心方法:双向条件流融合判别和生成 """
import torch import torch.nn as nn import torch.nn.functional as F
class BiCFlowMER(nn.Module): """ BiCFlow-MER: 双向条件流多模态情感识别 1. 从音频-文本中解耦情感证据(与说话风格、词汇内容分离) 2. 构建冲突感知情感条件 3. 通过双向整流流传输到显式情感空间 4. 自适应原型云评分 + 反向一致性验证 """ def __init__(self, audio_dim: int = 256, text_dim: int = 384, emotion_dim: int = 64, num_emotions: int = 7): super().__init__() self.emotion_encoder = nn.Sequential( nn.Linear(audio_dim + text_dim, 256), nn.GELU(), nn.Linear(256, emotion_dim) ) self.style_encoder = nn.Sequential( nn.Linear(audio_dim, 128), nn.GELU(), nn.Linear(128, 64) ) self.content_encoder = nn.Sequential( nn.Linear(text_dim, 128), nn.GELU(), nn.Linear(128, 64) ) self.condition_builder = ConditionBuilder( emotion_dim, style_dim=64, content_dim=64 ) self.flow = BidirectionalRectifiedFlow(emotion_dim) self.prototype_cloud = PrototypeCloud(num_emotions, emotion_dim) self.backward_consistency = BackwardConsistency( emotion_dim, style_dim=64, content_dim=64 ) def forward(self, audio_feat, text_feat): """ Args: audio_feat: (B, audio_dim) 音频特征 text_feat: (B, text_dim) 文本特征 Returns: emotion_logits: (B, num_emotions) """ emotion_evidence = self.emotion_encoder( torch.cat([audio_feat, text_feat], dim=-1) ) style = self.style_encoder(audio_feat) content = self.content_encoder(text_feat) condition = self.condition_builder(emotion_evidence, style, content) transported = self.flow(emotion_evidence, condition) logits = self.prototype_cloud(transported) return logits
class ConditionBuilder(nn.Module): """构建冲突感知情感条件""" def __init__(self, emotion_dim, style_dim, content_dim): super().__init__() self.fusion = nn.Sequential( nn.Linear(emotion_dim + style_dim + content_dim, 256), nn.GELU(), nn.Linear(256, emotion_dim), nn.LayerNorm(emotion_dim) ) def forward(self, emotion, style, content): concat = torch.cat([emotion, style, content], dim=-1) return self.fusion(concat)
class BidirectionalRectifiedFlow(nn.Module): """双向整 rectified flow""" def __init__(self, dim, num_steps=10): super().__init__() self.num_steps = num_steps self.velocity_net = nn.Sequential( nn.Linear(dim * 2, 256), nn.GELU(), nn.Linear(256, 256), nn.GELU(), nn.Linear(256, dim) ) def forward(self, x0, condition): """从x0传输到情感空间端点""" x = x0 dt = 1.0 / self.num_steps for _ in range(self.num_steps): v = self.velocity_net(torch.cat([x, condition], dim=-1)) x = x + v * dt return x
class PrototypeCloud(nn.Module): """自适应原型云评分""" def __init__(self, num_emotions, dim): super().__init__() self.prototypes = nn.Parameter(torch.randn(num_emotions, dim)) self.temperature = nn.Parameter(torch.ones(1)) def forward(self, x): dist = torch.cdist(x, self.prototypes) logits = -dist / self.temperature return F.softmax(logits, dim=-1)
class BackwardConsistency(nn.Module): """反向类别到条件一致性验证""" def __init__(self, emotion_dim, style_dim, content_dim): super().__init__() self.decoder = nn.Sequential( nn.Linear(emotion_dim + style_dim + content_dim, 256), nn.GELU(), nn.Linear(256, style_dim + content_dim) ) def forward(self, emotion, style, content): """验证传输后的情感是否与原始条件一致""" concat = torch.cat([emotion, style, content], dim=-1) reconstructed = self.decoder(concat) return reconstructed
if __name__ == "__main__": model = BiCFlowMER() audio = torch.randn(8, 256) text = torch.randn(8, 384) logits = model(audio, text) print(f"输入: audio={audio.shape}, text={text.shape}") print(f"输出: {logits.shape}") print(f"\n=== 论文结果 ===") print("IEMOCAP: 优于所有对比方法") print("MELD: 优于所有对比方法") print("CASE (零样本): 优于所有对比方法")
|