1# credit to Stack Overflow user in the source link
2import numpy as np
3from sklearn.metrics.pairwise import cosine_distances
4
5# some dummy data
6word_vectors = np.random.random((77, 300))
7
8word_cosine = cosine_distances(word_vectors)
9affprop = AffinityPropagation(affinity = 'precomputed', damping = 0.5)
10af = affprop.fit(word_cosine)