loading
open in
main.py
1
2
3
4
5
6
7
8
9
10
import mxnet as mx
import gluonnlp as nlp

glove = nlp.embedding.create('glove', source='glove.6B.50d')
baby, infant = glove['baby'], glove['infant']

def cos_similarity(vec1, vec2):
    return mx.nd.dot(vec1, vec2) / (vec1.norm() * vec2.norm())

print('Similarity between "baby" and "infant": ', cos_similarity(baby, infant).asnumpy()[0])
Python 3.6.1 (default, Dec 2015, 13:05:11) [GCC 4.8.2] on linux