现在,我正在学习CNN for nlp,不久之前,我尝试修改Yoon Kim的代码,github链接是(https://github.com/Joyce94/cnn-text-classification-pytorch),我尝试在模型中添加一层卷积的.py。
但是,我遇到了一个维度问题,换句话说,第一个卷积层的输出作为第二个卷积层的输入,它告诉我维度不合适。
任何人都可以帮我解决这个问题吗?
# one layer
self.conv13 = nn.Conv2d(Ci, 100, (3, D))
self.conv14 = nn.Conv2d(Ci, 100, (4, D))
self.conv15 = nn.Conv2d(Ci, 100, (5, D))
# two layer
self.conv23 = nn.Conv2d(100, Co, (D, Co))
self.conv24 = nn.Conv2d(100, Co, (D, Co))
self.conv25 = nn.Conv2d(100, Co, (D, Co))
x1 = self.conv(x, self.conv13) #(N,Co)
print("convvv", x1)
# two layer
if self.args.cuda:
self.conv23 = [model.cuda() for model in self.conv23]
self.conv24 = [model.cuda() for model in self.conv24]
self.conv25 = [model.cuda() for model in self.conv25]
x1 = x1.unsqueeze(1)
x4 = self.conv(x1, self.conv23) #(N,Co)
x = self.pool(x4)