深度学习参数初始化

Pytorch中的Conv1d()函数

2020-06-08  本文已影响0人  寒露lu
Conv1d()
class torch.nn.Conv1d(
        in_channels, 
        out_channels, 
        kernel_size, 
        stride=1, 
        padding=0, 
        dilation=1, 
        groups=1, 
        bias=True)

举例:实体链接(x,y),x,y是两个实体,当x,y为同一实体,标注为1,否则标注为1。

conv1 = nn.Conv1d(in_channels=200,out_channels=50, kernel_size=2)
input = torch.randn(32,8,200)
# batch_size x entity_len x embedding_size -> batch_size x embedding_size x text_len
input = input.permute(0,2,1)
out = conv1(input)
print(out.size())

这里32为batch_size,8为实体中词的个数,200为词向量。50为卷积核的数量,2为卷积核的尺寸。
输入一维卷积的时候,需要将32*8*200变换为32*200*8,因为一维卷积是在最后维度上扫的,卷积核大小为200*2,最后out的大小即为:32*50*(8-2+1)=32*50*7,最大池化后的大小为:32*50*1

上一篇 下一篇

猜你喜欢

热点阅读