- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我只看到几个问题问这个问题,但还没有一个有答案,所以我想我不妨试试。我一直在使用 gensim 的 word2vec 模型来创建一些向量。我将它们导出为文本,并尝试将其导入到嵌入投影仪的 tensorflow 实时模型中。一个问题。 没用。它告诉我张量格式不正确。因此,作为初学者,我想我应该向一些更有经验的人请教可能的解决方案。
相当于我的代码:
import gensim
corpus = [["words","in","sentence","one"],["words","in","sentence","two"]]
model = gensim.models.Word2Vec(iter = 5,size = 64)
model.build_vocab(corpus)
# save memory
vectors = model.wv
del model
vectors.save_word2vec_format("vect.txt",binary = False)
创建模型,保存向量,然后在制表符分隔的文件中漂亮漂亮地打印结果,其中包含所有维度的值。我知道如何做我正在做的事情,但我无法弄清楚我将它放入 tensorflow 的方式有什么问题,因为据我所知,与此相关的文档非常稀缺。
向我提出的一个想法是实现适当的 tensorflow 代码,但我不知道如何编写代码,只需在现场演示中导入文件即可。
编辑:我现在有一个新问题。我的向量所在的对象是不可迭代的,因为 gensim 显然决定制作自己的数据结构,而这些数据结构与我正在尝试做的不兼容。
好的。也完成了!感谢您的帮助!
最佳答案
您所描述的是可能的。您必须牢记的是,Tensorboard 从保存的 tensorflow 二进制文件中读取,这些二进制文件代表您在磁盘上的变量。
More information on saving and restoring tensorflow graph and variables here
因此,主要任务是将嵌入作为保存的 tf 变量获取。
Assumptions:
in the following code
embeddings
is a python dict{word:np.array (np.shape==[embedding_size])}
python version is 3.5+
used libraries are
numpy as np
,tensorflow as tf
the directory to store the tf variables is
model_dir/
np.array
embeddings_vectors = np.stack(list(embeddings.values(), axis=0))
# shape [n_words, embedding_size]
tf.Variable
保存到磁盘上# Create some variables.
emb = tf.Variable(embeddings_vectors, name='word_embeddings')
# Add an op to initialize the variable.
init_op = tf.global_variables_initializer()
# Add ops to save and restore all the variables.
saver = tf.train.Saver()
# Later, launch the model, initialize the variables and save the
# variables to disk.
with tf.Session() as sess:
sess.run(init_op)
# Save the variables to disk.
save_path = saver.save(sess, "model_dir/model.ckpt")
print("Model saved in path: %s" % save_path)
model_dir
should contain filescheckpoint
,model.ckpt-1.data-00000-of-00001
,model.ckpt-1.index
,model.ckpt-1.meta
metadata.tsv
要拥有漂亮的带标签的嵌入云,您可以为张量板提供制表符分隔值 (tsv) 形式的元数据(cf. here)。
words = '\n'.join(list(embeddings.keys()))
with open(os.path.join('model_dir', 'metadata.tsv'), 'w') as f:
f.write(words)
# .tsv file written in model_dir/metadata.tsv
运行 $ tensorboard --logdir model_dir
-> Projector。
要加载元数据,魔术就发生在这里:
提醒一下,一些 word2vec 嵌入投影也可以在 http://projector.tensorflow.org/ 上找到。
关于python - 在 Tensorboard Projector 中可视化 Gensim Word2vec 嵌入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50492676/
我正在使用张量板可视化句子嵌入。我有每个句子嵌入的标签。如何为每个标签设置颜色?例如 embedding vector Labels [0.234
在 Tensorboard 中有一个按钮将计算图保存为 png,有没有办法将其导出为矢量图形,如 eps? 最佳答案 您可以使用 SVG Crowbar 以 svg 格式保存 为“SVG Crowba
在使用 Keras Tuner 完成的超参数搜索期间,我遇到了明显的循环依赖,试图将日志数据用于 TensorBoard。 , 对于使用 TF2 构建的模型。后者的典型设置需要在调谐器的 search
我正在关注 Sentdex's DQN tutorial .我一直在尝试在 TF 2.0 中重写自定义 TensorBoard。重点是在文件中添加**stats,例如:{'reward_avg': -
我正在尝试启动 tensorboard 并查看我创建的图表。 import tensorflow as tf logPath = "C:\\path\\to\\log" -- can also be
最近的 TensorFlow 构建似乎有问题。 TensorBoard 可视化工具在从源代码编译以用于 GPU 时不会运行。错误如下: $ tensorboard Traceback (most re
我按照 pytorch.org 中的教程进行操作出现错误:TensorBoard logging requires TensorBoard version 1.15 or above ,但我已经安装了
我使用 tensorboard 创建了一些日志文件,但我无法访问它们。 使用 tensorboard 或 tensorboard --logdir=logs/ 命令提示符 出现以下错误:- C:\Us
我正在使用 Win10Pro、gpu (CUDA 10.1)、Python 3.7.5、Tensorflow 2.1.0 和 Tensorboard 2.1.0 在 ipython 中使用以下代码运行
在我执行的 Python 代码中train_writer = tf.summary.FileWriter(TBOARD_LOGS_DIR)train_writer.add_graph(sess.gra
我正在使用 Tensorboard 为我的实验绘制损失图。 我还想将测试结果添加到 Tensorboard 以便于进行实验比较,但我找不到执行此操作的函数。 我只需要一个简单的表格,例如: | Exp
当运行一个 mnist 分类程序以在 tensorboard 中查看时,它会显示多个图,即使只有一个图。我收到错误消息: 图表如下所示: 最佳答案 这看起来好像是由于同一目录中存在多个张量板文件。想必
关闭。这个问题不满足Stack Overflow guidelines .它目前不接受答案。 想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。 3年前关闭。 Improve thi
pre { line-height: 125% } td.linenos .normal { color: inherit; background-c
有人让 TensorBoard 工作了吗?似乎找不到我的 ScalarSummary 文件。我正在使用: $ python /Users/nikhilbuduma/tensorflow/lib/pyt
我正在运行一个云 ML 引擎作业,我的张量板图显示隐藏层的零值比例随着步数的增加稳步增加到 1。这个情节应该如何解释?我相信这是一件好事,因为更多的零值表明该模型对其所做的预测越来越“确定”。 最佳答
我正在使用 TensorBoard 来可视化网络指标和图表。 我创建了一个 session sess = tf.InteractiveSession()并在 Jupyter Notebook 中构建图
我在 Anaconda 环境中使用 Python(jupyter notebook) 操作系统:Ubuntu tensorflow 版本:1.14.0 Python版本:3.6 https://git
可以在同一台机器上运行多个 tensorboard 实例(具有不同的日志目录)。甚至还有可以启动/重用 TB 进程的 tensorboard.manager 类。 问题是所有这些 TB 都在不同的端口
我构建了一个网络来尝试预测表面温度的光栅图像。网络的输出是一个 (1000, 1000) 大小的数组,代表一个光栅图像。为了训练和测试,将这些与各自样本的真实栅格进行比较。我明白如何add the t
我是一名优秀的程序员,十分优秀!