'x = batch * len * h1
y = batch * h2
x_mask = batch * len'

def forward(self, x, y, x_mask):

    Wy = (self.linear(y) if (self.linear is not None) else y)
    xWy = x.bmm(Wy.unsqueeze(2)).squeeze(2)
    xWy.data.masked_fill_(x_mask.data, (- float('inf')))
    if self.training:
        alpha = F.log_softmax(xWy)
    else:
        alpha = F.softmax(xWy)
    return alpha
