quaterion.eval.samplers.base_sampler module¶
- class BaseSampler(sample_size=-1, device: Optional[Union[device, str]] = None, log_progress: bool = True)[source]¶
Bases:
object
Sample part of embeddings and targets to perform metric calculation on a part of the data
Sampler allows reducing amount of time and resources to calculate a distance matrix. Instead of calculation of squared matrix with shape (num_embeddings, num_embeddings), it selects embeddings and computes matrix of a rectangle shape.
- Args:
sample_size: amount of objects to select.
- sample(dataset: Sized, metric: BaseMetric, model: SimilarityModel) Tuple[Tensor, Tensor] [source]¶
Sample objects and labels to calculate metrics
- Parameters:
dataset – Sized object, like list, tuple, torch.utils.data.Dataset, etc. to sample
metric – metric instance to compute final labels representation
model – model to encode objects
- Returns:
Tensor, Tensor – metrics labels and computed distance matrix