Change to GMMv2b

This commit is contained in:
geneing 2020-01-03 23:59:20 -08:00
parent 48e4baf434
commit 20b4211af5
1 changed files with 6 additions and 4 deletions

View File

@ -159,20 +159,22 @@ class GravesAttention(nn.Module):
k_t = gbk_t[:, 2, :]
# attention GMM parameters
inv_sig_t = torch.exp(-torch.clamp(b_t, min=-6, max=9)) # variance
sig_t = torch.nn.functional.softplus(b_t)+self.eps
#inv_sig_t = torch.exp(-torch.clamp(b_t, min=-6, max=9)) # variance
mu_t = self.mu_prev + torch.nn.functional.softplus(k_t)
g_t = torch.softmax(g_t, dim=-1) * inv_sig_t + self.eps
g_t = torch.softmax(g_t, dim=-1) / sig_t + self.eps
# each B x K x T_in
g_t = g_t.unsqueeze(2).expand(g_t.size(0),
g_t.size(1),
inputs.size(1))
inv_sig_t = inv_sig_t.unsqueeze(2).expand_as(g_t)
sig_t = sig_t.unsqueeze(2).expand_as(g_t)
mu_t_ = mu_t.unsqueeze(2).expand_as(g_t)
j = self.J[:g_t.size(0), :, :inputs.size(1)]
# attention weights
phi_t = g_t * torch.exp(-0.5 * inv_sig_t * (mu_t_ - j)**2)
phi_t = g_t * torch.exp(-0.5 * (mu_t_ - j)**2 / (sig_t**2))
alpha_t = self.COEF * torch.sum(phi_t, 1)
# apply masking