我正在解決文本分類問題。我用我自己的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
感謝特里斯坦淨距那語法,即使我有解釋大聲笑。 –