0
我目前正在使用Tensorflow進行工作中正在開發的深度學習應用程序。我無法詳細瞭解應用程序的具體情況,但代碼類似於自定義的Word2Vec,但每個單詞 - 矢量表示的成本需要單獨計算。 :Tensorflow圖形變得太大
def cost_function(word_vector, other_word_vectors):
# cost for a single training example needs to be computed
# separately, and it depends on the vector representations
# of some other words, depending on the training instance
return tf.nn.tanh(some_mathematical_computation)
這種方法的問題是,圖形大小趨於炸燬了這麼多,該compute_gradients
操作需要大量的時間。不僅如此,compute_gradients
花費的時間隨着圖形大小線性增加。由於某種原因,tf.stop_gradients
不起作用。有幫助的是,爲每一個訓練實例初始化一個新的tf.Graph
和一個新的tf.Session()
(稱這是一個小批量),並行執行多個這樣的計算(稱爲小批量收集),然後將結果合併並保存他們爲下一個小批量收集。
def learning(mini_batch):
with tf.Graph().as_default() as g:
with tf.Session() as sess:
self.perform_learning_on_batch(mini_batch, sess)
return resultant_model
def collection_learn(mini_batch_collection):
models = run_learning_in_parallel()
return combine_model(models)
def master():
initial_model = something
for mini_batch_collection in dataset:
new_model = collection_learn(mini_batch_collection)
有沒有更好的方法來爲這樣的應用程序執行並行學習?
謝謝......我結束了使用一個簡單的傾盆樓梯下降的實現。無法用tensorflow解決它。任何想法,如果動態圖形框架(如pytorch)會有所幫助? –
傾斜梯度下降是tensorflow模型在默認情況下用於分佈式和平行訓練的模型。 –