BasicNegativeSampler
- class BasicNegativeSampler(*, corruption_scheme: Collection[Literal['head', 'relation', 'tail']] | None = None, **kwargs)[source]
Bases:
NegativeSampler
A basic negative sampler.
This negative sampler that corrupts positive triples \((h,r,t) \in \mathcal{K}\) by replacing either \(h\), \(r\) or \(t\) based on the chosen corruption scheme. The corruption scheme can contain \(h\), \(r\) and \(t\) or any subset of these.
Steps:
Randomly (uniformly) determine whether \(h\), \(r\) or \(t\) shall be corrupted for a positive triple \((h,r,t) \in \mathcal{K}\).
Randomly (uniformly) sample an entity \(e \in \mathcal{E}\) or relation \(r' \in \mathcal{R}\) for selection to corrupt the triple.
If \(h\) was selected before, the corrupted triple is \((e,r,t)\)
If \(r\) was selected before, the corrupted triple is \((h,r',t)\)
If \(t\) was selected before, the corrupted triple is \((h,r,e)\)
If
filtered
is set toTrue
, all proposed corrupted triples that also exist as actual positive triples \((h,r,t) \in \mathcal{K}\) will be removed.
Initialize the basic negative sampler with the given entities.
- Parameters:
corruption_scheme (Collection[Literal['head', 'relation', 'tail']] | None) – What sides (‘h’, ‘r’, ‘t’) should be corrupted. Defaults to head and tail (‘h’, ‘t’).
kwargs – Additional keyword based arguments passed to
pykeen.sampling.NegativeSampler
.
Methods Summary
corrupt_batch
(positive_batch)Generate negative samples from the positive batch without application of any filter.
Methods Documentation