'x = batch * len * hdim
x_mask = batch * len'

def forward(self, x, x_mask):

    x_flat = x.view((-1), x.size((-1)))
    scores = self.linear(x_flat).view(x.size(0), x.size(1))
    scores.data.masked_fill_(x_mask.data, (- float('inf')))
    alpha = F.softmax(scores)
    return alpha
