2017-05-26 32 views
0

我rying,以可視化word2vec的結果,以使用tensorboard的嵌入頁面。經過調試,挖掘大量代碼的我來到這tensorboard成功運行,讀取confguration文件,讀取文件TSV但現在的嵌入頁面不顯示數據點。
(打開頁面時,我可以看到菜單,項目等),這是我的配置文件: 的嵌入{ tensor_name: 'word_embedding' metadata_path: 'C:\ DATA \ metadata.tsv' tensor_path:「C :\ DATA \ tensors2.tsv」 }tensorboard的嵌入不顯示數據

可以採取什麼問題嗎?

張量文件最初是1GB。在大小上,如果我嘗試該文件,應用程序崩潰,因爲內存。所以我複製並粘貼原始文件的1或2頁到tensor2.tsv並使用此文件。可能是這個問題。可能是我需要通過複製/粘貼來創建更多數據。

THX 托爾加

回答

0

嘗試下面的代碼片段得到顯現字tensorboard嵌入。使用logdir打開tensorboard,檢查localhost:6006以查看您的嵌入。

tensorboard --logdir = 「視覺/ 1」

# code 
fname = "word2vec_model_1000" 
model = gensim.models.keyedvectors.KeyedVectors.load(fname) 
# project part of vocab, max of 100 dimension 
max = 1000 

w2v = np.zeros((max,100)) 
with open("prefix_metadata.tsv", 'w+') as file_metadata: 
    for i,word in enumerate(model.wv.index2word[:max]): 
     w2v[i] = model.wv[word] 
     file_metadata.write(word + '\n') 

# define the model without training 
sess = tf.InteractiveSession() 

with tf.device("/cpu:0"): 
    embedding = tf.Variable(w2v, trainable=False, name='prefix_embedding') 

tf.global_variables_initializer().run() 

path = 'visual/1' 
saver = tf.train.Saver() 
writer = tf.summary.FileWriter(path, sess.graph) 

# adding into projector 
config = projector.ProjectorConfig() 
embed= config.embeddings.add() 
embed.tensor_name = 'prefix_embedding' 
embed.metadata_path = 'prefix_metadata.tsv' 

# Specify the width and height of a single thumbnail. 
projector.visualize_embeddings(writer, config) 

saver.save(sess, path+'/prefix_model.ckpt', global_step=max)