In [7]:
%cd ~/NetBeansProjects/ExpLosion/
from notebooks.common_imports import *


/Users/miroslavbatchkarov/NetBeansProjects/ExpLosion

In [2]:
from discoutils.thesaurus_loader import Vectors
from random import sample

In [3]:
v = Vectors.from_tsv('/lustre/scratch/inf/mmb28/FeatureExtractionToolkit/word2vec_vectors/word2vec-wiki-nopos-15perc.unigr.strings.rep0')

In [5]:
v.init_sims(n_neighbors=5)

In [ ]:
words = random.sample(list(v.keys()), 10)
data = []
for w in words:
    neigh = v.get_nearest_neighbours(w)
    data.append([n[0] for n in neigh[:5]])

In [19]:
df = pd.DataFrame(data, index=words, columns=['Neigh %d'%d for d in range(1, 6)])

In [20]:
df


Out[20]:
Neigh 1 Neigh 2 Neigh 3 Neigh 4 Neigh 5
godmother betrothed lover spinster mother-in-law stepdaughter
performer musician artist entertainer dancer accompanist
confiscation expropriation forfeiture taking curtailment illegality
amal al-amin mukhtar nasrallah usama ashraf
alms penitent passer-by sainthood yagna repentant
pawnbroker thrifty bookie yusuke fleer buchalter
plas cupar vanden bodoni eastlake suk
menuhin yehudi caryl barenboim barone lalo
parent mother family live-in child carer
roden coy kempthorne orme porteous allred

In [21]:
print(df.to_latex())


\begin{tabular}{llllll}
\toprule
{} &        Neigh 1 &     Neigh 2 &      Neigh 3 &        Neigh 4 &       Neigh 5 \\
\midrule
godmother    &      betrothed &       lover &     spinster &  mother-in-law &  stepdaughter \\
performer    &       musician &      artist &  entertainer &         dancer &   accompanist \\
confiscation &  expropriation &  forfeiture &       taking &    curtailment &    illegality \\
amal         &        al-amin &     mukhtar &    nasrallah &          usama &        ashraf \\
alms         &       penitent &   passer-by &    sainthood &          yagna &     repentant \\
pawnbroker   &        thrifty &      bookie &       yusuke &          fleer &     buchalter \\
plas         &          cupar &      vanden &       bodoni &       eastlake &           suk \\
menuhin      &         yehudi &       caryl &    barenboim &         barone &          lalo \\
parent       &         mother &      family &      live-in &          child &         carer \\
roden        &            coy &  kempthorne &         orme &       porteous &        allred \\
\bottomrule
\end{tabular}