(m, v)
return predictions
Computes a cosine similarity between batches of matrices and vectors.

    :param m: a #D tensor that contains a batch of matrices
    :param v: a 2D tensor that contains a batch of vectors
    :return: a 2D tensor with similarity values per vector * matrix row
Computes a cosine similarity between batches of matrices and vectors.
Computes a cosine similarity between batches of matrices and vectors .
def batchmv_cosine_similarity(m, v):
    """
    Computes a cosine similarity between batches of matrices and vectors.

    :param m: a #D tensor that contains a batch of matrices
    :param v: a 2D tensor that contains a batch of vectors
    :return: a 2D tensor with similarity values per vector * matrix row
    """
    predictions = torch.bmm(m, v.unsqueeze(2)).squeeze()
    w1 = torch.norm(m, 2, dim=-1)
    w2 = torch.norm(v, 2, dim=-1, keepdim=True)
    predictions = (predictions / (w1 * w2.expand_as(w1)).clamp(min=10e-8))
    return predictions
def batchmv_cosine_similarity ( m , v ) : predictions = torch . bmm ( m , v . unsqueeze ( 2 ) ) . squeeze ( ) w1 = torch . norm ( m , 2 , dim = - 1 ) w2 = torch . norm ( v , 2 , dim = - 1 , keepdim = True ) predictions = ( predictions / ( w1 * w2 . expand_as ( w1 ) ) . clamp ( min = 10e-8 ) ) return predictions