有什么方法/神经网络的架构,其中有多个标签在训练数据和多个输出的预测?
答案是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会使它更难?以前的文献或实验数据? –