nanguoshun / LSR

Pytorch Implementation of our ACL 2020 Paper "Reasoning with Latent Structure Refinement for Document-Level Relation Extraction"
127 stars 22 forks source link

关于StructInduction 类 #26

Open VinnyHu opened 3 years ago

VinnyHu commented 3 years ago

"""STEP1: Calculating Attention Matrix""" if (self.bidirectional): # bidirectional = True input = input.view(batch_size, token_size, 2, dim_size // 2) sem_v = torch.cat((input[:, :, 0, :self.sem_dim_size // 2], input[:, :, 1, :self.sem_dim_size // 2]), 2) str_v = torch.cat((input[:, :, 0, self.sem_dim_size // 2:], input[:, :, 1, self.sem_dim_size // 2:]), 2) else: sem_v = input[:, :, :self.sem_dim_size] str_v = input[:, :, self.sem_dim_size:]

您好,这里我没有看懂。 问题1:我理解的input的维度为 batch mention node-num + entity-node-num + mdp-node-num hidden-size,不知道这里是否正确。 问题2:这几行代码您根据 bidirectional 把 hidden-size 拆分成了2份了 input = input.view(batch_size, token_size, 2, dim_size // 2) 这里的bidirectional 是指的是什么呢? 和BiLSTM编码那里的一样吗?但是那里的拼接后的向量,不是又通过了linear层进行转换维度了呢? 问题3:sem-v 与 str-v分别是什么意思?

StructInduction 类的功能 应该是将 mention node entity node mdp node 通过18那那篇文章的计算方式,得到邻接矩阵,然后传给densely gcn层更新。

VinnyHu commented 3 years ago

https://github.com/vidhishanair/structured-text-representations 中的实现里面,是在encoder那里经过BiLSTM之后,把原来hidden-size 变为之前的2倍了,sem_dim_size 已经扩大了2倍了。 但是在您的实现里面,经过BiLSTM之后,又已经经过了
context_output = self.dropout_rate(torch.relu(self.linear_re(docs_rep))) 将维度从2*hidden-size 变成了hidden-size了,为什么还要经过 上面的切分呢? 那这样的切分不就是没有意义了嘛? 所以我想问下 您这里是否实现错误了?

nanguoshun commented 3 years ago

@VinnyHu 谢谢提问。 1)我原代码中的维度应该是没有问题的。 2)& 3) 这种切分是参考了 https://arxiv.org/abs/1705.09207中的做法,将vector分割成两部分,分别用于学习semantic information和structure attention,也可以不切分,我当时实验发现两者基本上没太多区别,代码中也保留了这个方法。如有兴趣可以 https://arxiv.org/abs/1705.09207中的Section 3.1

VinnyHu commented 3 years ago

@VinnyHu 谢谢提问。 1)我原代码中的维度应该是没有问题的。 2)& 3) 这种切分是参考了 https://arxiv.org/abs/1705.09207中的做法,将vector分割成两部分,分别用于学习semantic information和structure attention,也可以不切分,我当时实验发现两者基本上没太多区别,代码中也保留了这个方法。如有兴趣可以 https://arxiv.org/abs/1705.09207中的Section 3.1

好的,谢谢您的回复

nanguoshun commented 3 years ago

@VinnyHu 这儿也是参考了DocRED最初的代码,多1层FFN可以增加模型的拟合能力,所以保留没有变化,你可以尝试删除这层FFN后看看效果