Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于头尾实体特征和关系特征的问题 #23

Closed
WangYao-GoGoGo opened this issue Aug 23, 2022 · 5 comments
Closed

关于头尾实体特征和关系特征的问题 #23

WangYao-GoGoGo opened this issue Aug 23, 2022 · 5 comments

Comments

@WangYao-GoGoGo
Copy link

WangYao-GoGoGo commented Aug 23, 2022

大佬您好,请教个问题:
我看实体特征里面,实体开始结束特征为什么这么定义,能说说您的想法吗?
为什么repeat(1, length, 1, 1)就表示开始特征,repeat(length, 1, 1, 1)表示结尾特征,有什么含义在里面吗?
`st = h_ner.unsqueeze(1).repeat(1, length, 1, 1)

en = h_ner.unsqueeze(0).repeat(length, 1, 1, 1)

ner = torch.cat((st, en, h_global), dim=-1)
`

以及,关系抽取的时候,关系特征,为什么会分为r1和r2两个子特征,是表示头实体对于关系r的特征和尾实体对于关系r的特征吗?
`r1 = h_re.unsqueeze(1).repeat(1, length, 1, 1)

r2 = h_re.unsqueeze(0).repeat(length, 1, 1, 1)

re = torch.cat((r1, r2, h_global), dim=-1)
`
多谢大佬指教!

@Coopercoppers
Copy link
Owner

这相当于在做笛卡尔积,sta和end的区分是看你concat的先后顺序来定的

@WangYao-GoGoGo
Copy link
Author

前辈请教一下, 上面您说的这种类似笛卡尔积的inference方法是在哪篇论文里面最开始提出来的?
能否给推荐一篇论文,我刚刚入门关系抽取,想学习学习,因为找了半天没找到,而您论文里面对这块也没有详细介绍。 万分谢谢!

@WangYao-GoGoGo
Copy link
Author

我基于您的模型做一些改动,但是在这块给卡住了

@kaifangDeng
Copy link

其实头和尾特征还是一样的东西,只不过通过维度扩展对齐了,比如说原来有1,2,3三个字符,通过扩展可以组成全部的组合11,12,13,21,22,。。。,这样就可以对三个字符组成的全部组合分类

@WangYao-GoGoGo
Copy link
Author

@kaifangDeng 谢谢您,这块的特征方法搞明白了。
之前对evaluate里面的关系预测还是有点生疏,今晚又看了一下,理解了一些。谢谢
` def get_trip_pred(self, ner_pred, re_pred):

    ner_mask = torch.sum(ner_pred, dim=1).float()
    ner_mask = torch.sum(ner_mask, dim=-1).float()
    ner_mask = torch.where(ner_mask > 0, torch.ones_like(ner_mask), torch.zeros_like(ner_mask))

    seq_len = ner_mask.size(0)
    e1 = ner_mask.unsqueeze(0).repeat(seq_len, 1, 1)
    e2 = ner_mask.unsqueeze(1).repeat(1, seq_len, 1)
    ner_mask = e1 * e2

    ner_mask = ner_mask.unsqueeze(-1).repeat(1, 1, 1, len(self.rel2idx))
    complete_re_pred = re_pred * ner_mask
    return complete_re_pred`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants