我正在解决文本分类问题。我用我自己的model_fn
使用Estimator
类定义了我的分类器。我想使用Google的预先训练好的word2vec
嵌入作为初始值,然后针对当前的任务对其进行进一步优化。加载预先训练好的word2vec在Estimator中初始化embedding_lookup model_fn
我看到这篇文章:Using a pre-trained word embedding (word2vec or Glove) in TensorFlow
它解释了如何在'原始'TensorFlow代码中去解决它。但是,我真的很想使用Estimator
类。
作为一个扩展,我想在Cloud ML引擎上训练这个代码,是否有一种很好的方式来传递具有初始值的相当大的文件?
比方说,我们有这样的事:
def build_model_fn():
def _model_fn(features, labels, mode, params):
input_layer = features['feat'] #shape=[-1, params["sequence_length"]]
#... what goes here to initialize W
embedded = tf.nn.embedding_lookup(W, input_layer)
...
return predictions
estimator = tf.contrib.learn.Estimator(
model_fn=build_model_fn(),
model_dir=MODEL_DIR,
params=params)
estimator.fit(input_fn=read_data, max_steps=2500)
谢谢,只是一个很小的事情:它应该是'tf.estimator.EstimatorSpec(...,支架= tf.train.Scaffold(init_feed_dict = {embed_ph:my_embedding_numpy_array})' – Tristan
感谢特里斯坦净距那语法,即使我有解释大声笑。 –