I want to build my gensim-word2vec model as a "word-galaxy" (for example, here http://www.anthonygarvan.com/wordgalaxy/ ) and blink, display one point by entering its name in the search field and clicking the submit button. I am new to all this python stuff, and therefore I really don't understand the curdoc documentation or the example here: https://github.com/bokeh/bokeh/tree/master/examples/app/movies . This is my code:
from bokeh.plotting import figure, output_file, show, ColumnDataSource
from bokeh.models.widgets import TextInput
from bokeh.models import HoverTool
from gensim.models import word2vec
from sklearn.manifold import TSNE
model = word2vec.Word2Vec.load_word2vec_format('GoT.model.vector', binary=True)
ts = TSNE(2)
vectors, words, x, y = []
form word in model.vocab:
vectors.append(model[word])
words.append(word)
reduced_vecs = ts.fit_transform(vectors)
for vec in reduced_vecs:
x.append(vec[0])
y.append(vec[1])
search_word=TextInput(title="Search")
source = ColumnDataSource(data = dict(x=x,y=y,words=words))
hover=HoverTool(tooltips=[("word", "@words")]
p = figure(plot_height=600, plot_width=800, title="word2vec", tools=[hover], logo=None)
p.circle('x','y', radius=0.1, source=source, line_color=None)
show(p)
output_file('plot.html', mode="cdn")
Can you help me? Thanks, FFoDWindow
source
share