(self, input_EEG_features, input_EEG_attn_mask, input_ids, input_text_attention_masks)
| 266 | self.logit_scale = nn.Parameter(torch.ones([]) * np.log(1 / 0.07)) |
| 267 | |
| 268 | def forward(self, input_EEG_features, input_EEG_attn_mask, input_ids, input_text_attention_masks): |
| 269 | # add positional embedding |
| 270 | input_EEG_features = self.positional_embedding(input_EEG_features) |
| 271 | # get EEG feature embedding |
| 272 | EEG_hiddenstates = self.EEG_Encoder(input_EEG_features, src_key_padding_mask = input_EEG_attn_mask) |
| 273 | EEG_hiddenstates = self.ln_final(EEG_hiddenstates) |
| 274 | EEG_features = self.EEG_pooler(EEG_hiddenstates) # [N, 840] |
| 275 | |
| 276 | # project to text embed size |
| 277 | EEG_features = EEG_features @ self.EEG_projection # [N, 768] |
| 278 | |
| 279 | # get text feature embedding |
| 280 | Text_features = self.TextEncoder(input_ids = input_ids, attention_mask = input_text_attention_masks, return_dict = True).pooler_output # [N, 768] |
| 281 | |
| 282 | # normalized features |
| 283 | EEG_features = EEG_features / EEG_features.norm(dim=-1, keepdim=True) # [N, 768] |
| 284 | Text_features = Text_features / Text_features.norm(dim=-1, keepdim=True) # [N, 768] |
| 285 | |
| 286 | # cosine similarity as logits |
| 287 | logit_scale = self.logit_scale.exp() |
| 288 | logits_per_EEG = logit_scale * EEG_features @ Text_features.t() # [N, N] |
| 289 | logits_per_text = logit_scale * Text_features @ EEG_features.t() # [N, N] |
| 290 | |
| 291 | return logits_per_EEG, logits_per_text |
nothing calls this directly
no outgoing calls
no test coverage detected