1

我正在尝试使用 CNN 进行文本分类。这是我的一些标签:dog, cat, bird, football, basketball... 由于这些类在某种程度上过于细粒度而无法获得良好的精度,再加上训练数据量相对较少,因此我将它们分组为animal, sports

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

 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

那么你们对设计这样的网络有什么想法或经验吗?欢迎大家提出意见,谢谢~

4

1 回答 1

2

老实说,我从未见过多任务训练会被用来提高细粒度分类的性能。您的两个任务都使用相同的网络唯一的区别是您的通用类 softmax 的输出作为细粒度类 softmax 的输入。

我看不出哪里会出现足以提高细粒度类分类性能的新信息。

的确,通常人们使用多任务学习一次学习两件事,但所学的东西是相互独立的。这是问题陈述的一个很好的例子:找到一朵花的颜色和类型。这是一个如何使用 MxNet 创建这样一个模型的示例,它比您的要简单一些,因为它不会将输出连接在一起。

希望能帮助到你。

于 2018-03-08T23:35:09.420 回答