有什麼方法/神經網絡的架構,其中有多個標籤在訓練數據和多個輸出的預測?
答案是YES。爲了簡要回答你的問題,我在一個高級神經網絡庫Keras的背景下給出了一個例子。
讓我們考慮以下模型。我們想要預測Twitter上有多少轉發和喜歡新聞標題。模型的主要輸入將是標題本身,作爲一系列詞語,但爲了增添趣味,我們的模型還會有一個輔助輸入,可以接收額外的數據,例如標題發佈日的時間等。
from keras.layers import Input, Embedding, LSTM, Dense, merge
from keras.models import Model
# headline input: meant to receive sequences of 100 integers, between 1 and 10000.
# note that we can name any layer by passing it a "name" argument.
main_input = Input(shape=(100,), dtype='int32', name='main_input')
# this embedding layer will encode the input sequence
# into a sequence of dense 512-dimensional vectors.
x = Embedding(output_dim=512, input_dim=10000, input_length=100)(main_input)
# a LSTM will transform the vector sequence into a single vector,
# containing information about the entire sequence
lstm_out = LSTM(32)(x)
auxiliary_output = Dense(1, activation='sigmoid', name='aux_output')(lstm_out)
auxiliary_input = Input(shape=(5,), name='aux_input')
x = merge([lstm_out, auxiliary_input], mode='concat')
# we stack a deep fully-connected network on top
x = Dense(64, activation='relu')(x)
x = Dense(64, activation='relu')(x)
x = Dense(64, activation='relu')(x)
# and finally we add the main logistic regression layer
main_output = Dense(1, activation='sigmoid', name='main_output')(x)
這定義具有兩個輸入和兩個輸出的模型:
model = Model(input=[main_input, auxiliary_input], output=[main_output, auxiliary_output])
現在,讓編譯和訓練模型如下:
model.compile(optimizer='rmsprop',
loss={'main_output': 'binary_crossentropy', 'aux_output': 'binary_crossentropy'},
loss_weights={'main_output': 1., 'aux_output': 0.2})
# and trained it via:
model.fit({'main_input': headline_data, 'aux_input': additional_data},
{'main_output': labels, 'aux_output': labels},
nb_epoch=50, batch_size=32)
參考: Multi-input and multi-output models in Keras
二進制softmax和'一元'sigmoid幾乎是相同的東西,並在輸出中使用sigmoid不會讓事情變得更加困難。 – lejlot
謝謝盧卡,你的解釋清楚而有幫助。但是,有一點仍然存在。我的直覺與@lejlot相同,因爲只有兩種可能性(是/否)。你能否澄清爲什麼你認爲softmax會使它變得更容易或相反,爲什麼sigmoid會使它更難?以前的文獻或實驗數據? –