transformer_rankers.negative_samplers.negative_sampling.RandomNegativeSampler

class transformer_rankers.negative_samplers.negative_sampling.RandomNegativeSampler(candidates, num_candidates_samples, seed=42)[source]

Bases: object

Randomly sample candidates from a list of candidates.

Parameters
  • candidates – list of str containing the candidates

  • num_candidates_samples – int containing the number of negative samples for each query.

__init__(candidates, num_candidates_samples, seed=42)[source]

Initialize self. See help(type(self)) for accurate signature.

Methods

__init__(candidates, num_candidates_samples)

Initialize self.

sample(query_str, relevant_docs)

Samples from a list of candidates randomly.

sample(query_str, relevant_docs)[source]

Samples from a list of candidates randomly.

If the samples match the relevant doc, then removes it and re-samples.

Parameters
  • query_str – the str of the query. Not used here.

  • relevant_docs – list with the str of the relevant documents, to avoid sampling them as negative sample.

Returns

First the sampled_documents, their respective scores and then indicators if the NS retrieved the relevant document, and if so at which position.