2016-06-16 3 views
2

誰かがTensorFlowでマルチタスクディープ学習を行う方法を知っていますか?すなわち、最下層を共有しないで最下層を共有する。いくつかのサンプルコードを親切に共有できますか?テンソルフローでマルチタスクディープ学習を行う方法

+0

[Tensorflowによるマルチタスクの深い学習]の可能な複製(http://stackoverflow.com/questions/34591195/multitask-deep-learning-with-tensorflow) – Seanny123

答えて

4

TensorFlowバックエンドを持つKerasはこれを簡単に実行できます。機能的なAPIは、これらのユースケース用に設計されています。ここでfunctional API guide.を見てみましょうすると、上記ガイドから取られ、レイヤーを共有LSTMの例である:あなたが複数の出力を持つKerasモデルを訓練するとき

# this layer can take as input a matrix 
# and will return a vector of size 64 
shared_lstm = LSTM(64) 

# when we reuse the same layer instance 
# multiple times, the weights of the layer 
# are also being reused 
# (it is effectively *the same* layer) 
encoded_a = shared_lstm(tweet_a) 
encoded_b = shared_lstm(tweet_b) 

# we can then concatenate the two vectors: 
merged_vector = merge([encoded_a, encoded_b], mode='concat', concat_axis=-1) 

# and add a logistic regression on top 
predictions = Dense(1, activation='sigmoid')(merged_vector) 

# we define a trainable model linking the 
# tweet inputs to the predictions 
model = Model(input=[tweet_a, tweet_b], output=predictions) 

model.compile(optimizer='rmsprop', 
       loss='binary_crossentropy', 
       metrics=['accuracy']) 
model.fit([data_a, data_b], labels, nb_epoch=10) 

は、あなたが各出力の損失関数を定義することができ、かつKerasすべての損失の合計に対して最適化します。これはかなり有用です。

関連する問題