intfloat / SimKGC

ACL 2022, SimKGC: Simple Contrastive Knowledge Graph Completion with Pre-trained Language Models
188 stars 36 forks source link

您好,这两行代码不是很明白,可以请教一下吗? #25

Closed YongqingQI closed 1 year ago

YongqingQI commented 1 year ago

https://github.com/intfloat/SimKGC/blob/97cc43e488f19ca5b0f6fbf60ffefd2ee56c0693/models.py#L31

https://github.com/intfloat/SimKGC/blob/97cc43e488f19ca5b0f6fbf60ffefd2ee56c0693/models.py#L94

这里self.log_inv_t = torch.nn.Parameter(torch.tensor(1.0 / args.t).log() 先进行取log(),然后在这一行代码中logits *= self.log_inv_t.exp()又取exp(),这样的话不是相当于没进行操作吗

intfloat commented 1 year ago

这样做主要是为了保证温度系数t始终是个正数,不管 log_inv_t 被更新到哪个数值。

YongqingQI commented 1 year ago

噢噢,感谢!