kongdeqiang
6 天以前 28ccfbfc51068a663a80764e14074df5edf2b5ba
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
import torch
from torch.nn import functional as F
 
 
class DotScorer(torch.nn.Module):
    def __init__(self):
        super().__init__()
 
    def forward(
        self,
        xs_pad: torch.Tensor,
        spk_emb: torch.Tensor,
    ):
        # xs_pad: B, T, D
        # spk_emb: B, N, D
        scores = torch.matmul(xs_pad, spk_emb.transpose(1, 2))
        return scores
 
 
class CosScorer(torch.nn.Module):
    def __init__(self):
        super().__init__()
 
    def forward(
        self,
        xs_pad: torch.Tensor,
        spk_emb: torch.Tensor,
    ):
        # xs_pad: B, T, D
        # spk_emb: B, N, D
        scores = F.cosine_similarity(xs_pad.unsqueeze(2), spk_emb.unsqueeze(1), dim=-1)
        return scores