TransH
- class TransH(*, embedding_dim=50, scoring_fct_norm=2, entity_initializer=<function xavier_normal_>, entity_regularizer=None, entity_regularizer_kwargs=None, relation_initializer=<function xavier_normal_>, relation_regularizer=None, relation_regularizer_kwargs=None, **kwargs)[source]
Bases:
ERModel
An implementation of TransH [wang2014].
This model extends
pykeen.models.TransE
by applying the translation from head to tail entity in a relational-specific hyperplane in order to address its inability to model one-to-many, many-to-one, and many-to-many relations.In TransH, each relation is represented by a hyperplane, or more specifically a normal vector of this hyperplane \(\textbf{w}_{r} \in \mathbb{R}^d\) and a vector \(\textbf{d}_{r} \in \mathbb{R}^d\) that lies in the hyperplane. To compute the plausibility of a triple \((h,r,t)\in \mathbb{K}\), the head embedding \(\textbf{e}_h \in \mathbb{R}^d\) and the tail embedding \(\textbf{e}_t \in \mathbb{R}^d\) are first projected onto the relation-specific hyperplane:
\[ \begin{align}\begin{aligned}\textbf{e'}_{h,r} = \textbf{e}_h - \textbf{w}_{r}^\top \textbf{e}_h \textbf{w}_r\\\textbf{e'}_{t,r} = \textbf{e}_t - \textbf{w}_{r}^\top \textbf{e}_t \textbf{w}_r\end{aligned}\end{align} \]where \(\textbf{h}, \textbf{t} \in \mathbb{R}^d\). Then, the projected embeddings are used to compute the score for the triple \((h,r,t)\):
\[f(h, r, t) = -\|\textbf{e'}_{h,r} + \textbf{d}_r - \textbf{e'}_{t,r}\|_{p}^2\]See also
OpenKE implementation of TransH
Initialize TransH.
- Parameters
embedding_dim (
int
) – the entity embedding dimension \(d\). Is usually \(d \in [50, 300]\).scoring_fct_norm (
int
) – the \(l_p\) norm applied in the interaction function. Is usually1
or2.
.entity_initializer (
Union
[str
,Callable
[[FloatTensor
],FloatTensor
],None
]) – the entity initializer functionentity_regularizer (
Union
[str
,Regularizer
,Type
[Regularizer
],None
]) – the entity regularizer. Defaults topykeen.models.TransH.regularizer_default
entity_regularizer_kwargs (
Optional
[Mapping
[str
,Any
]]) – keyword-based parameters for the entity regularizer. If entity_regularizer is None, the default frompykeen.models.TransH.regularizer_default_kwargs
will be used insteadrelation_initializer (
Union
[str
,Callable
[[FloatTensor
],FloatTensor
],None
]) – relation initializer functionrelation_regularizer (
Union
[str
,Regularizer
,Type
[Regularizer
],None
]) – the relation regularizer. Defaults topykeen.models.TransH.relation_regularizer_default
relation_regularizer_kwargs (
Optional
[Mapping
[str
,Any
]]) – keyword-based parameters for the relation regularizer. If relation_regularizer is None, the default frompykeen.models.TransH.relation_regularizer_default_kwargs
will be used insteadkwargs – Remaining keyword arguments to forward to
pykeen.models.ERModel
Attributes Summary
The default strategy for optimizing the model's hyper-parameters
The default parameters for the default regularizer class
The settings used by [wang2014] for TransH
Attributes Documentation
- hpo_default: ClassVar[Mapping[str, Any]] = {'embedding_dim': {'high': 256, 'low': 16, 'q': 16, 'type': <class 'int'>}, 'scoring_fct_norm': {'high': 2, 'low': 1, 'type': <class 'int'>}}
The default strategy for optimizing the model’s hyper-parameters