class_docstr: This class evaluates a SentenceTransformer model for the task of re-ranking.
  
  Given a query and a list of documents, it computes the score [query, doc_i] for all possible
  documents and sorts them in decreasing order. Then, MRR@10 and MAP is compute to measure the quality of the ranking.
  
  :param samples: Must be a list and each element is of the form: {'query': '', 'positive': [], 'negative': []}. Query is the search query,
   positive is a list of positive (relevant) documents, negative is a list of negative (irrelevant) documents.
docstr: Embeds every (query, positive, negative) tuple individually.
  Is slower than the batched version, but saves memory as only the
  embeddings for one tuple are needed. Useful when you have
  a really large test set
docstr_tok: ["Embeds","every","(","query",",","positive",",","negative",")","tuple","individually",".","Is","slower","than","the","batched","version",",","but","saves","memory","as","only","the","embeddings","for","one","tuple","are","needed",".","Useful","when","you","have","a","really","large","test","set"]
code: def compute_metrices_individual(self, model):
      """
      Embeds every (query, positive, negative) tuple individually.
      Is slower than the batched version, but saves memory as only the
      embeddings for one tuple are needed. Useful when you have
      a really large test set
      """
      all_mrr_scores = []
      all_ap_scores = []
  
      for instance in tqdm.tqdm(
          self.samples,
          disable=not self.show_progress_bar,
          desc="Samples",
      ):
          query = instance["query"]
          positive = list(instance["positive"])
          negative = list(instance["negative"])
  
          if len(positive) == 0 or len(negative) == 0:
              continue
  
          docs = positive + negative
          is_relevant = [True] * len(positive) + [False] * len(negative)
  
          query_emb = model.encode(
              [query],
              convert_to_tensor=True,
              batch_size=self.batch_size,
              show_progress_bar=False,
          )
          docs_emb = model.encode(
              docs,
              convert_to_tensor=True,
              batch_size=self.batch_size,
              show_progress_bar=False,
          )
  
          pred_scores = self.similarity_fct(query_emb, docs_emb)
          if len(pred_scores.shape) > 1:
              pred_scores = pred_scores[0]
  
          pred_scores_argsort = torch.argsort(
              -pred_scores
          )  # Sort in decreasing order
  
          # Compute MRR score
          mrr_score = 0
          for rank, index in enumerate(
              pred_scores_argsort[0 : self.mrr_at_k]
          ):
              if is_relevant[index]:
                  mrr_score = 1 / (rank + 1)
                  break
          all_mrr_scores.append(mrr_score)
  
          # Compute AP
          all_ap_scores.append(
              average_precision_score(
                  is_relevant, pred_scores.cpu().tolist()
              )
          )
  
      mean_ap = np.mean(all_ap_scores)
      mean_mrr = np.mean(all_mrr_scores)
  
      return {"map": mean_ap, "mrr": mean_mrr}
  
file_path: sentence-transformers/sentence_transformers/evaluation/RerankingEvaluator.py
imports: from .None import SentenceEvaluator
  import logging
  import numpy
  import os
  import csv
  from ..util import cos_sim
  import torch
  from sklearn.metrics import average_precision_score
  import tqdm
label_desc: Use image node_id 5 for calling the RerankingEvaluator obj's underlying member method code with example usage: obj.compute_metrices_individual(model) and returns: dict