NegativeSampler¶
- class NegativeSampler(triples_factory, num_negs_per_pos=None, filtered=False, filterer=None, filterer_kwargs=None)[source]¶
Bases:
abc.ABCA negative sampler.
Initialize the negative sampler with the given entities.
- Parameters
triples_factory (
CoreTriplesFactory) – The factory holding the positive training triplesnum_negs_per_pos (
Optional[int]) – Number of negative samples to make per positive triple. Defaults to 1.filtered (
bool) – Whether proposed corrupted triples that are in the training data should be filtered. Defaults to False. See explanation infilter_negative_triples()for why this is a reasonable default.filterer (
Union[str,Filterer,Type[Filterer],None]) – If filtered is set to True, this can be used to choose which filter module frompykeen.sampling.filteringis used.filterer_kwargs (
Optional[Mapping[str,Any]]) – Additional keyword-based arguments passed to the filterer upon construction.
Attributes Summary
The default strategy for optimizing the negative sampler’s hyper-parameters
Methods Summary
corrupt_batch(positive_batch)Generate negative samples from the positive batch without application of any filter.
Get the normalized name of the negative sampler.
sample(positive_batch)Generate negative samples from the positive batch.
Attributes Documentation
- hpo_default: ClassVar[Mapping[str, Mapping[str, Any]]] = {'num_negs_per_pos': {'high': 100, 'log': True, 'low': 1, 'type': <class 'int'>}}¶
The default strategy for optimizing the negative sampler’s hyper-parameters
Methods Documentation
- abstract corrupt_batch(positive_batch)[source]¶
Generate negative samples from the positive batch without application of any filter.
- Parameters
positive_batch (
LongTensor) – shape: (batch_size, 3) The positive triples.- Return type
LongTensor- Returns
shape: (batch_size, num_negs_per_pos, 3) The negative triples.
result[i, :, :]contains the negative examples generated frompositive_batch[i, :].
- classmethod get_normalized_name()[source]¶
Get the normalized name of the negative sampler.
- Return type
- sample(positive_batch)[source]¶
Generate negative samples from the positive batch.
- Parameters
positive_batch (
LongTensor) – shape: (batch_size, 3) The positive triples.- Return type
- Returns
A pair (negative_batch, filter_mask) where
negative_batch: shape: (batch_size, num_negatives, 3) The negative batch.
negative_batch[i, :, :]contains the negative examples generated frompositive_batch[i, :].filter_mask: shape: (batch_size, num_negatives) An optional filter mask. True where negative samples are valid.