2017-03-02 934 views
1

在我看到的所有神经网络分类示例中,他们都有训练数据,其中每个训练数据有一个类别作为主要类别或每个标签输入数据。神经网络分类:他们总是必须每个训练数据有一个标签

您可以提供具有多个标签的培训数据吗?例如:带有“猫”和“鼠标”的图片。

我明白(也许错了),如果你在输出层使用softmax进行概率/预测,它往往试图选择一个(最大化辨别力)。我猜这会伤害/阻止学习和预测输入数据的多个标签。

有什么方法/神经网络的体系结构,其中有多个标签在训练数据和多个输出预测?或者已经是这种情况,我错过了一些重要的理解。请澄清。

回答

1

大多数例子每个输入有一个类,所以没有你没有错过任何东西。然而,有可能做多类分类,在文献中有时称为联合分类。

你用softmax建议的幼稚实现将会很困难,因为最后一层的输出必须加起来为1,所以越多的类你就越难弄清楚网络想说什么。

您可以更改体系结构来实现您想要的。对于每个类,您都可以有一个二进制softmax分类器,它从倒数第二层分支出来,或者您可以使用一个sigmoid,即使每个神经元输出介于0和1之间,也不必加起来一个。注意使用sigmoid可能会使训练更加困难。

或者,您可以为每个班级培训多个网络,然后在最后将其组合成一个分类系统。这取决于你设想的任务有多复杂。

+0

二进制softmax和'一元'sigmoid几乎是相同的东西,并在输出中使用sigmoid不会让事情变得更加困难。 – lejlot

+0

谢谢卢卡,你的解释清楚而有帮助。但是,有一点仍然存在。我的直觉与@lejlot相同,因为只有两种可能性(是/否)。你能否澄清为什么你认为softmax会使它变得更容易或相反,为什么sigmoid会使它更难?以前的文献或实验数据? –

0

有什么方法/神经网络的架构,其中有多个标签在训练数据和多个输出的预测?

答案是YES。为了简要回答你的问题,我在一个高级神经网络库Keras的背景下给出了一个例子。

让我们考虑以下模型。我们想要预测Twitter上有多少转发和喜欢新闻标题。模型的主要输入将是标题本身,作为一系列词语,但为了增添趣味,我们的模型还会有一个辅助输入,可以接收额外的数据,例如标题发布日的时间等。

enter image description here

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

+0

我欣赏细节和流程图Wasi。请澄清一下,您的标题输入是否允许最多100个单词,每个单词的索引编号介于1到10,000之间?那是编码吗? –

+0

@SriramGopalakrishnan是的,这将是输入,但有一个嵌入层,将文字转换为较低维度。 –