用文本输入指出一个点

时间:2016-05-05 11:38:23

标签: python plot bokeh word2vec

我想用一个" word-galaxy"(就像这里:http://www.anthonygarvan.com/wordgalaxy/)绘制我的gensim-word2vec模型,然后通过输入它的名字来闪烁一个点在搜索栏中按下提交按钮。我对所有这些python的东西都相当新,所以我实际上并不了解curdoc文档或这里的示例:https://github.com/bokeh/bokeh/tree/master/examples/app/movies。这是我的代码:

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")

你能帮我解决这个问题吗?谢谢, FFoDWindow

0 个答案:

没有答案