# BasicNegativeSampler¶

class BasicNegativeSampler(*, corruption_scheme=None, **kwargs)[source]

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:

1. Randomly (uniformly) determine whether $$h$$, $$r$$ or $$t$$ shall be corrupted for a positive triple $$(h,r,t) \in \mathcal{K}$$.

2. 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)$$

3. If filtered is set to True, 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:

Methods Summary

 corrupt_batch(positive_batch) Generate negative samples from the positive batch without application of any filter.

Methods Documentation

corrupt_batch(positive_batch)[source]

Generate negative samples from the positive batch without application of any filter.

Parameters:

positive_batch (LongTensor) – shape: (*batch_dims, 3) The positive triples.

Return type:

LongTensor

Returns:

shape: (*batch_dims, num_negs_per_pos, 3) The negative triples. result[*bi, :, :] contains the negative examples generated from positive_batch[*bi, :].