TransformerNegativeSamplerBase

class rectools.models.nn.transformers.negative_sampler.TransformerNegativeSamplerBase(n_negatives: int, **kwargs: Any)[source]

Bases: object

Base class for negative sampler. To create custom sampling logic inherit from this class and pass your custom negative sampler to your model parameters.

Parameters
  • n_negatives (int) – Number of negatives.

  • kwargs (Any) –

Inherited-members

Methods

get_negatives(batch_dict, lowest_id, highest_id)

Return sampled negatives.

get_negatives(batch_dict: Dict, lowest_id: int, highest_id: int, session_len_limit: Optional[int] = None, **kwargs: Any) Tensor[source]

Return sampled negatives.

Parameters
  • batch_dict (Dict) –

  • lowest_id (int) –

  • highest_id (int) –

  • session_len_limit (Optional[int]) –

  • kwargs (Any) –

Return type

Tensor