skipthoughts.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:how_to_convert_text_to_images 作者: llSourcell 项目源码 文件源码
def nn(model, text, vectors, query, k=5):
    """
    Return the nearest neighbour sentences to query
    text: list of sentences
    vectors: the corresponding representations for text
    query: a string to search
    """
    qf = encode(model, [query])
    qf /= norm(qf)
    scores = numpy.dot(qf, vectors.T).flatten()
    sorted_args = numpy.argsort(scores)[::-1]
    sentences = [text[a] for a in sorted_args[:k]]
    print 'QUERY: ' + query
    print 'NEAREST: '
    for i, s in enumerate(sentences):
        print s, sorted_args[i]
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号