CrossE交互
- class CrossEInteraction(embedding_dim: int = 50, combination_activation: str | ~torch.nn.modules.module.Module | type[~torch.nn.modules.module.Module] | None = <class 'torch.nn.modules.activation.Tanh'>, combination_activation_kwargs: ~collections.abc.Mapping[str, ~typing.Any] | None = None, combination_dropout: float | None = 0.5)[source]
基础类:
Interaction[Tensor,tuple[Tensor,Tensor],Tensor]CrossE的有状态交互函数。
交互函数由以下给出
\[\textit{drop}( \textit{act}( \mathbf{c}_r \odot \mathbf{h} + \mathbf{c}_r \odot \mathbf{h} \odot \mathbf{r} + \mathbf{b}) ) )^T \mathbf{t}\]其中 \(\mathbf{h}, \mathbf{c}_r, \mathbf{r}, \mathbf{t} \in \mathbb{R}^d\) 分别是头嵌入、关系交互向量、关系嵌入和尾嵌入。 \(\mathbf{b} \in \mathbb{R}^d\) 是一个全局偏置向量(这使得这个交互函数具有状态)。 \(\textit{drop}\) 表示 dropout,而 \(\textit{act}\) 是激活函数。
注意
CrossE论文描述了作为交互函数一部分的额外sigmoid激活。由于使用对数似然损失可能会导致数值问题(由于在log之前显式调用sigmoid),我们在实现中不使用它,而是选择数值稳定的变体。然而,模型本身有一个选项
predict_with_sigmoid,可以在推理期间强制使用sigmoid。这也可能影响基于排名的评分,因为有限的数值精度可能导致多个选择得分完全相同。在这种情况下,排名的定义不明确,有几种竞争的方法可以打破平局。有关更多信息,请参见理解评估。实例化交互模块。
- Parameters:
注意
参数对
(combination_activation, combination_activation_kwargs)用于class_resolver.contrib.torch.activation_resolver解析器的解释及其使用方法在 https://class-resolver.readthedocs.io/en/latest/中给出。
属性摘要
关系表示的符号形状
方法总结
forward(h, r, t)评估交互函数。
属性文档
方法文档