KG2E
- class KG2E(*, embedding_dim=50, dist_similarity=None, c_min=0.05, c_max=5.0, entity_initializer=<function uniform_>, entity_constrainer=<function clamp_norm>, entity_constrainer_kwargs=None, relation_initializer=<function uniform_>, relation_constrainer=<function clamp_norm>, relation_constrainer_kwargs=None, **kwargs)[source]
Bases:
ERModel
An implementation of KG2E from [he2015].
KG2E aims to explicitly model (un)certainties in entities and relations (e.g. influenced by the number of triples observed for these entities and relations). Therefore, entities and relations are represented by probability distributions, in particular by multi-variate Gaussian distributions \(\mathcal{N}_i(\mu_i,\Sigma_i)\) where the mean \(\mu_i \in \mathbb{R}^d\) denotes the position in the vector space and the diagonal variance \(\Sigma_i \in \mathbb{R}^{d \times d}\) models the uncertainty. Inspired by the
pykeen.models.TransE
model, relations are modeled as transformations from head to tail entities: \(\mathcal{H} - \mathcal{T} \approx \mathcal{R}\) where \(\mathcal{H} \sim \mathcal{N}_h(\mu_h,\Sigma_h)\), \(\mathcal{H} \sim \mathcal{N}_t(\mu_t,\Sigma_t)\), \(\mathcal{R} \sim \mathcal{P}_r = \mathcal{N}_r(\mu_r,\Sigma_r)\), and \(\mathcal{H} - \mathcal{T} \sim \mathcal{P}_e = \mathcal{N}_{h-t}(\mu_h - \mu_t,\Sigma_h + \Sigma_t)\) (since head and tail entities are considered to be independent with regards to the relations). The interaction model measures the similarity between \(\mathcal{P}_e\) and \(\mathcal{P}_r\) by means of the Kullback-Liebler Divergence (KG2E.kullback_leibler_similarity()
).\[f(h,r,t) = \mathcal{D_{KL}}(\mathcal{P}_e, \mathcal{P}_r)\]Besides the asymmetric KL divergence, the authors propose a symmetric variant which uses the expected likelihood (
KG2E.expected_likelihood()
)\[f(h,r,t) = \mathcal{D_{EL}}(\mathcal{P}_e, \mathcal{P}_r)\]Initialize KG2E.
- Parameters:
embedding_dim (
int
) – The entity embedding dimension \(d\). Is usually \(d \in [50, 350]\).dist_similarity (
Optional
[str
]) – Either ‘KL’ for Kullback-Leibler or ‘EL’ for expected likelihood. Defaults to KL.c_min (
float
) – covariance clamp minimum boundc_max (
float
) – covariance clamp maximum boundentity_initializer (
Union
[str
,Callable
[[FloatTensor
],FloatTensor
],None
]) – Entity initializer function. Defaults totorch.nn.init.uniform_()
entity_constrainer (
Union
[str
,Callable
[[FloatTensor
],FloatTensor
],None
]) – Entity constrainer function. Defaults topykeen.utils.clamp_norm()
entity_constrainer_kwargs (
Optional
[Mapping
[str
,Any
]]) – Keyword arguments to be used when calling the entity constrainerrelation_initializer (
Union
[str
,Callable
[[FloatTensor
],FloatTensor
],None
]) – Relation initializer function. Defaults totorch.nn.init.uniform_()
relation_constrainer (
Union
[str
,Callable
[[FloatTensor
],FloatTensor
],None
]) – Relation constrainer function. Defaults topykeen.utils.clamp_norm()
relation_constrainer_kwargs (
Optional
[Mapping
[str
,Any
]]) – Keyword arguments to be used when calling the relation constrainerkwargs – Remaining keyword arguments to forward to
pykeen.models.ERModel
Attributes Summary
The default settings for the entity constrainer
The default strategy for optimizing the model's hyper-parameters
Attributes Documentation
- constrainer_default_kwargs = {'dim': -1, 'maxnorm': 1.0, 'p': 2}
The default settings for the entity constrainer
- hpo_default: ClassVar[Mapping[str, Any]] = {'c_max': {'high': 10.0, 'low': 1.0, 'type': <class 'float'>}, 'c_min': {'high': 0.1, 'low': 0.01, 'scale': 'log', 'type': <class 'float'>}, 'embedding_dim': {'high': 256, 'low': 16, 'q': 16, 'type': <class 'int'>}}
The default strategy for optimizing the model’s hyper-parameters