Pointing out a single dot with text input

自作多情 提交于 2019-12-08 09:54:22

问题


i want to plot my gensim-word2vec model in kind of a "word-galaxy"(like here: http://www.anthonygarvan.com/wordgalaxy/) and flashing out a single dot by entering it's name in a search field and pressing a submit-button. I'm fairly new to all this python-stuff and so i actually 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) #load the trained model. (Game of Thrones script)

ts = TSNE(2)
vectors, words, x, y = []
form word in model.vocab:
    vectors.append(model[word]) #append my vector to "word"
    words.append(word) #append my 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 with this? Thank you, FFoDWindow

来源:https://stackoverflow.com/questions/37049640/pointing-out-a-single-dot-with-text-input

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!