修改CNN的网络结构
Created by: daichengchao
参考文本分类的示例,修改了网络结构; http://paddlepaddle.org/docs/develop/models/text_classification/README.html 在原始text_cnn的最后一层中添加一些特征add_fea。
修改后网络结构为:
# input layers
81 data = paddle.layer.data("word",
82 paddle.data_type.integer_value_sequence(dict_dim))
83 lbl = paddle.layer.data("label", paddle.data_type.integer_value(class_dim))
84 add_feature = paddle.layer.data("znd_fea",paddle.data_type.dense_vector(5))
85 print add_feature,lbl
86 logger.info("add_feature is : %s." % (add_feature))
87 # embedding layer
88 emb = paddle.layer.embedding(input=data, size=emb_dim)
89
90 # convolution layers with max pooling
91 conv_3 = paddle.networks.sequence_conv_pool(
92 input=emb, context_len=3, hidden_size=hid_dim)
93 conv_4 = paddle.networks.sequence_conv_pool(
94 input=emb, context_len=4, hidden_size=hid_dim)
95
96 # fc and output layer
97 prob = paddle.layer.fc(
98 input=[conv_3, conv_4, add_feature], size=class_dim, act=paddle.activation.Softmax())
99 # input=[conv_3, conv_4,], size=class_dim, act=paddle.activation.Softmax())
添加了84行add_feature,修改了98行。请问代码中定义的网络结构是否反应上图中的结构?
在模型预估时,
57 test_batch = []
58 for idx, item in enumerate(test_reader):
59 test_batch.append([item[0]])
60 if len(test_batch) == batch_size:
61 _infer_a_batch(inferer, test_batch, word_reverse_dict,
62 label_reverse_dict)
63 test_batch = []
问题2:需要把label和添加的特征都加到test_batch吗?我测试了一下,仅仅需要添加 test_batch.append([item[0],item[2]]),item[2]标示add_feature,请问这样预估时正确的吗?