besskge.negative_sampler.RandomShardedNegativeSampler

class besskge.negative_sampler.RandomShardedNegativeSampler(n_negative, sharding, seed, corruption_scheme, local_sampling, flat_negative_format=False)[source]

Sample random negative entities for each triple in batch.

Initialize random negative sampler.

Parameters:
  • n_negative (int) – Number of negative samples per shard-pair (if flat_negative_format) or per triple.

  • sharding (Sharding) – Sharding of entities.

  • seed (int) – Seed of RNG.

  • corruption_scheme (str) – “h”: corrupt head entities; “t”: corrupt tail entities; “ht”: corrupt head entities for the first half of each triple partition, tail entities for the second half.

  • local_sampling (bool) – If True, sample negative entities only from the shard where the triple is processed.

  • flat_negative_format (bool) – If True, sample n_negative negative entities for each shard-pair, instead of each triple. If True, requires use of negative sample sharing. Default: False.

corruption_scheme: str

Which entity to corrupt; “h”, “t”, “ht”

flat_negative_format: bool

Sample negatives per triple partition, instead of per triple

local_sampling: bool

Sample negatives only from processing device

rng: Generator

RNG