

def cosine_similarity(x, y, eps=1e-06):
    '\n    Cosine similarity between a vector and each row of a base matrix.\n\n    Parameters\n    ----------\n    x: a 1D Theano variable\n        Vector to compare to each row of the matrix y.\n    y: a 2D Theano variable\n        Matrix to be compared to\n    eps: float\n        Precision of the operation (necessary for differentiability).\n\n    Return\n    ------\n    z: a 1D Theano variable\n        A vector whose components are the cosine similarities\n        between x and each row of y.\n    '

    def _cosine_similarity(x, y, eps=1e-06):
        y = y.dimshuffle(1, 0)
        z = T.dot(x, y)
        z /= T.sqrt(((T.sum((x * x)) * T.sum((y * y), axis=0)) + eps))
        return z

    def step(x_b, y_b):
        return _cosine_similarity(x_b, y_b, eps)
    (z, _) = theano.map(step, sequences=[x, y])
    return y

dataset/ETHPy150Open snipsco/ntm-lasagne/ntm/similarities.py cosine_similarity/VarMisuse@142/352 `z`->`y`