多任务学习网络结构设计

时间:2016-08-27 08:57:38

标签: deep-learning mxnet

我正在尝试使用CNN进行文本分类。以下是我的一些标签:dogcatbirdfootballbasketball ......因为这些类太精细而无法获得好处精确度,加上相对少量的训练数据,我将它们分组为animalsports

然后我设计了一个简单的多任务学习结构,如下面的,但它并没有提高我的细粒度标签上的最终性能

 18     data = mx.symbol.Variable('data')
 19     softmax_label = mx.symbol.Variable('softmax_label')
 20     softmax_label_finegrained = mx.symbol.Variable('softmax_label_finegrained')
 21
 22     # embedding layer
 23     if not with_embedding:
 24         word_embed = mx.symbol.Embedding(data=data, input_dim=vocab_size,
 25                                       output_dim=embedding_size, name='word_embedding')
 26         conv_input = mx.symbol.Reshape(data=word_embed, target_shape=(batch_size, 1, sentence_size, embedding_size))  # convolution layer needs 4D input.
 27     else:
 28         logging.info('with pretrained embedding.')
 29         conv_input = data
 30
 31     # convolution and pooling layer
 32     pooled_outputs = []
 33     for i, filter_size in enumerate(filter_list):
 34         convi = mx.symbol.Convolution(data=conv_input, kernel=(filter_size, embedding_size), num_filter=num_filter)
 35         acti  = mx.symbol.Activation(data=convi, act_type='relu')
 36         pooli = mx.symbol.Pooling(data=acti, pool_type='max', kernel=(sentence_size - filter_size + 1, 1), stride=(1,1))  # max pooling on entire sentence feature ma    p.
 37         pooled_outputs.append(pooli)
 38
 39     # combine all pooled outputs
 40     num_feature_maps = num_filter * len(filter_list)
 41     concat = mx.symbol.Concat(*pooled_outputs, dim=1)  # max-overtime pooling. concat all feature maps into a long feature before feeding into final dropout and full    y connected layer.
 42     h_pool = mx.symbol.Reshape(data=concat, shape=(batch_size, num_feature_maps))  # make it flat/horizontal
 43
 44     # dropout
 45     if dropout > 0.0:
 46         logging.info('use dropout.')
 47         drop = mx.symbol.Dropout(data=h_pool, p=dropout)
 48     else:
 49         logging.info('Do not use dropout.')
 50         drop = h_pool
 51
 52     # fully connected and softmax output.
 53     logging.info('num_classes: %d', num_classes)
 54     logging.info('num_fine_classes: %d', num_fine_classes)
 55     fc = mx.symbol.FullyConnected(data=drop, num_hidden= num_classes, name='fc')
 56     fc_fine = mx.symbol.FullyConnected(data=drop, num_hidden= num_fine_classes, name='fc_fine')
 57     softmax = mx.symbol.SoftmaxOutput(data= fc, label= softmax_label)
 58     softmax_fine = mx.symbol.SoftmaxOutput(data= fc_fine, label= softmax_label_finegrained)
 59
 60     return mx.symbol.Group([softmax, softmax_fine])

我还尝试通过在SoftmaxActivation之后添加内部fc图层来合并更多信息并且无效:

 52     # fully connected and softmax output.
 53     logging.info('num_classes: %d', num_classes)
 54     logging.info('num_fine_classes: %d', num_fine_classes)
 55     fc = mx.symbol.FullyConnected(data=drop, num_hidden= num_classes, name='fc')
 56     softmax = mx.symbol.SoftmaxOutput(data=fc, label= softmax_label)
 57     softmax_act = mx.symbol.SoftmaxActivation(data=fc)
 58     # make softmax_domain a internal layer for emitting activation, which we take it as a input into downstream task.
 59     drop_act = mx.symbol.Concat(drop, softmax_act, dim=1)
 60     fc_fine = mx.symbol.FullyConnected(data=drop_act, num_hidden= num_fine_classes, name='fc_fine')
 61     softmax_fine = mx.symbol.SoftmaxOutput(data=fc_fine, label= softmax_label_finegrained)
 62
 63     return mx.symbol.Group([softmax, softmax_fine])
 64

那么你们对设计这样的网络有什么想法或经验吗?欢迎任何想法,谢谢〜

1 个答案:

答案 0 :(得分:2)

说实话,我从未见过多任务培训会被用来提高细粒度分类的表现。你的任务都使用相同的网络唯一的区别是你的泛型类softmax的输出作为细粒度类softmax的输入。

我不知道哪些新信息可以出现,足以提高细粒度类别的分类效果。

确实,通常人们使用多任务学习一次学习2件事,但学到的东西彼此独立。这是a good example of a problem statement:找到花的颜色和类型。这里有一个example of how to create such a model using MxNet,它比你的更简单,因为它不会将输出连接在一起。

希望它有所帮助。