(seq, cond, lens)
return context, scores
attend over the sequences `seq` using the condition `cond`.
attend over the sequences `seq` using the condition `cond`.
attend over the sequences seq using the condition cond .
def attend(seq, cond, lens):
    """
    attend over the sequences `seq` using the condition `cond`.
    """
    scores = cond.unsqueeze(1).expand_as(seq).mul(seq).sum(2)
    max_len = max(lens)
    for i, l in enumerate(lens):
        if l < max_len:
            scores.data[i, l:] = -np.inf
    scores = F.softmax(scores, dim=1)
    context = scores.unsqueeze(2).expand_as(seq).mul(seq).sum(1)
    return context, scores
def attend ( seq , cond , lens ) : scores = cond . unsqueeze ( 1 ) . expand_as ( seq ) . mul ( seq ) . sum ( 2 ) max_len = max ( lens ) for i , l in enumerate ( lens ) : if l < max_len : scores . data [ i , l : ] = - np . inf scores = F . softmax ( scores , dim = 1 ) context = scores . unsqueeze ( 2 ) . expand_as ( seq ) . mul ( seq ) . sum ( 1 ) return context , scores