2016-06-16 2 views
2

TensorFlow를 사용하여 멀티 태스킹 학습을 수행하는 방법을 아는 사람이 있습니까? 즉, 맨 위 레이어를 공유하지 않으면 서 맨 아래 레이어를 공유합니다. 몇 가지 예제 코드를 친절하게 공유 할 수 있습니까?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 모든 손실의 합계에 대해 최적화 할 것이므로 매우 유용합니다.