我正在使用CNN进行文本分类(遵循kim yoon方法) 但出现错误,我无法弄清
我查看了类似问题的帖子,但无法关注
inputs = Input(shape=(sequence_length,))
embedding = embedding_layer(inputs)
reshape = Reshape((sequence_length,embedding_dim,1))(embedding)
conv_0 = Conv2D(num_filters, (filter_sizes[0],
embedding_dim),activation='relu',kernel_regularizer=regularizers.l2(0.01))
(reshape)
conv_1 =
Conv2D(num_filters,filter_sizes[1],embedding_dim),activation='relu',
kernel_regularizer=regulari zers.l2(0.01))(reshape)
conv_2 = Conv2D(num_filters,
(filter_sizes[2],embedding_dim),activation='relu',kernel_regularizer=
regularizers.l2(0.01))(reshape)
maxpool_0 = MaxPooling2D((sequence_length - filter_sizes[0] + 1, 1),
strides=(1,1))(conv_0)
flat_0 = Flatten()(maxpool_0)
maxpool_1 = MaxPooling2D((sequence_length - filter_sizes[1] + 1, 1),
strides=(1,1))(conv_1)
flat_1 = Flatten()(maxpool_1)
maxpool_2 = MaxPooling2D((sequence_length - filter_sizes[2] + 1, 1),
strides=(1,1))(conv_2)
flat_2 = Flatten()(maxpool_2)
merged_tensor = concatenate([flat_0,flat_1, flat_2])
output = Dense(units=3,
activation='softmax',kernel_regularizer=regularizers.l2(0.01(merged_tensor)
ValueError跟踪(最近一次通话最近) 在 1个 ----> 2 model.fit(x_train,y_train,batch_size,epochs = 100,verbose = 1,callbacks = callback) 3#开始训练
ValueError:检查目标时出错:预期density_4的形状为(3,),但数组的形状为(2,)
当然,消息中还有更多数据,如有需要,我会予以整理
dence_4是最终输出