Sampling

Negative sampling.

Name

Reference

basic

pykeen.sampling.BasicNegativeSampler

bernoulli

pykeen.sampling.BernoulliNegativeSampler

Note

This table can be re-generated with pykeen ls samplers -f rst

class pykeen.sampling.BasicNegativeSampler(triples_factory, num_negs_per_pos=None)[source]

A basic negative sampler.

Initialize the negative sampler with the given entities.

Parameters
  • triples_factory (TriplesFactory) – The factory holding the triples to sample from

  • num_negs_per_pos (Optional[int]) – Number of negative samples to make per positive triple. Defaults to 1.

hpo_default: ClassVar[Mapping[str, Mapping[str, Any]]] = {'num_negs_per_pos': {'high': 100, 'low': 1, 'q': 10, 'type': <class 'int'>}}

The default strategy for optimizing the negative sampler’s hyper-parameters

sample(positive_batch)[source]

Generate negative samples from the positive batch.

Return type

LongTensor

class pykeen.sampling.BernoulliNegativeSampler(triples_factory, num_negs_per_pos=None)[source]

An implementation of the bernoulli negative sampling approach proposed by [wang2014].

Initialize the negative sampler with the given entities.

Parameters
  • triples_factory (TriplesFactory) – The factory holding the triples to sample from

  • num_negs_per_pos (Optional[int]) – Number of negative samples to make per positive triple. Defaults to 1.

hpo_default: ClassVar[Mapping[str, Mapping[str, Any]]] = {'num_negs_per_pos': {'high': 100, 'low': 1, 'q': 10, 'type': <class 'int'>}}

The default strategy for optimizing the negative sampler’s hyper-parameters

sample(positive_batch)[source]

Sample a negative batched based on the bern approach.

Return type

LongTensor

class pykeen.sampling.NegativeSampler(triples_factory, num_negs_per_pos=None)[source]

A negative sampler.

Initialize the negative sampler with the given entities.

Parameters
  • triples_factory (TriplesFactory) – The factory holding the triples to sample from

  • num_negs_per_pos (Optional[int]) – Number of negative samples to make per positive triple. Defaults to 1.

classmethod get_normalized_name()[source]

Get the normalized name of the negative sampler.

Return type

str

hpo_default: ClassVar[Mapping[str, Mapping[str, Any]]]

The default strategy for optimizing the negative sampler’s hyper-parameters

property num_entities

The number of entities to sample from.

Return type

int

abstract sample(positive_batch)[source]

Generate negative samples from the positive batch.

Return type

LongTensor

pykeen.sampling.get_negative_sampler_cls(query)[source]

Get the negative sampler class.

Return type

Type[NegativeSampler]

pykeen.sampling.negative_samplers: Mapping[str, Type[pykeen.sampling.negative_sampler.NegativeSampler]] = {'basic': <class 'pykeen.sampling.basic_negative_sampler.BasicNegativeSampler'>, 'bernoulli': <class 'pykeen.sampling.bernoulli_negative_sampler.BernoulliNegativeSampler'>}

A mapping of negative samplers’ names to their implementations