【发布时间】:2019-12-01 05:49:58
【问题描述】:
我目前正在尝试优化 tensorflow 的 word2vec 实现,让它像原始的 gensim word2vec 实现一样工作。不过这里的教程
https://github.com/tensorflow/models/blob/master/tutorials/embedding/word2vec.py, 要求我首先向 tensorflow 添加一个新操作。
我已将存储库克隆到我的桌面,tensorflow/tensorflow-master 和 tensorflow/models-master 都位于名为 tensorflow 的目录中。 我尝试编译位于 models-master/tutorials/embeddings 中的 word2vec_ops.cc 和 word2vec_kernels.cc 文件(它们定义了新操作的实现和接口)
它给了我以下错误信息 -
In file included from word2vec_kernels.cc:16:0:
tensorflow/core/framework/op.h:23:54: fatal error:
tensorflow/core/framework/op_def_builder.h: No such file or directory
compilation terminated.
我还将 tensorflow-master/tensorflow/ 文件夹复制到 models-master/tutorials/embedding/ 中,以便所有需要的头文件都在同一个目录中(请参阅 github repo 以供参考,我在 windows 上有类似的目录树:https://github.com/tensorflow/tensorflow/tree/master/tensorflow/core)
原始编译过程:
TF_CFLAGS=( $(python -c 'import tensorflow as tf; print("
".join(tf.sysconfig.get_compile_flags()))') )
TF_LFLAGS=( $(python -c 'import tensorflow as tf; print("
".join(tf.sysconfig.get_link_flags()))') )
g++ -std=c++11 -shared word2vec_ops.cc word2vec_kernels.cc -o
word2vec_ops.so -fPIC ${TF_CFLAGS[@]} ${TF_LFLAGS[@]} -O2 -
D_GLIBCXX_USE_CXX11_ABI=0
此命令序列在 Windows 终端中不起作用(显然)。所以我还在代码本身中定义了标志
flags.DEFINE_string("save_path", 'C:\Users\Desktop\log_dir\gensim\22',
"Directory to write the model and "
"training summaries.")
flags.DEFINE_string("train_data", 'cmpl.txt', "Training text file. "
"E.g., unzipped file
http://mattmahoney.net/dc/text8.zip.")
flags.DEFINE_string(
"eval_data", 'questions-words.txt', "File consisting of analogies of four
tokens."
"embedding 2 - embedding 1 + embedding 3 should be close "
"to embedding 4."
"See README.md for how to get 'questions-words.txt'.")
,所以我不需要将它们传递给 sys.argv(),(所以前两个 命令不是必需的),但是,仍然使用 anaconda mingw,我无法为 implementation 构建动态库。由于前面提到的错误
【问题讨论】:
标签: python c++ c tensorflow