class_docstr: Given a large set of sentences, this evaluator performs paraphrase (duplicate) mining and
  identifies the pairs with the highest similarity. It compare the extracted paraphrase pairs
  with a set of gold labels and computes the F1 score.
docstr: :param sentences_map: A dictionary that maps sentence-ids to sentences, i.e. sentences_map[id] => sentence.
  :param duplicates_list: Duplicates_list is a list with id pairs [(id1, id2), (id1, id5)] that identifies the duplicates / paraphrases in the sentences_map
  :param duplicates_dict: A default dictionary mapping [id1][id2] to true if id1 and id2 are duplicates. Must be symmetric, i.e., if [id1][id2] => True, then [id2][id1] => True.
  :param add_transitive_closure: If true, it adds a transitive closure, i.e. if dup[a][b] and dup[b][c], then dup[a][c]
  :param query_chunk_size: To identify the paraphrases, the cosine-similarity between all sentence-pairs will be computed. As this might require a lot of memory, we perform a batched computation.  #query_batch_size sentences will be compared against up to #corpus_batch_size sentences. In the default setting, 5000 sentences will be grouped together and compared up-to against 100k other sentences.
  :param corpus_chunk_size: The corpus will be batched, to reduce the memory requirement
  :param max_pairs: We will only extract up to #max_pairs potential paraphrase candidates.
  :param top_k: For each query, we extract the top_k most similar pairs and add it to a sorted list. I.e., for one sentence we cannot find more than top_k paraphrases
  :param show_progress_bar: Output a progress bar
  :param batch_size: Batch size for computing sentence embeddings
  :param name: Name of the experiment
  :param write_csv: Write results to CSV file
code: def __init__(
      self,
      sentences_map: Dict[str, str],
      duplicates_list: List[Tuple[str, str]] = None,
      duplicates_dict: Dict[str, Dict[str, bool]] = None,
      add_transitive_closure: bool = False,
      query_chunk_size: int = 5000,
      corpus_chunk_size: int = 100000,
      max_pairs: int = 500000,
      top_k: int = 100,
      show_progress_bar: bool = False,
      batch_size: int = 16,
      name: str = "",
      write_csv: bool = True,
  ):
      """
  
      :param sentences_map: A dictionary that maps sentence-ids to sentences, i.e. sentences_map[id] => sentence.
      :param duplicates_list: Duplicates_list is a list with id pairs [(id1, id2), (id1, id5)] that identifies the duplicates / paraphrases in the sentences_map
      :param duplicates_dict: A default dictionary mapping [id1][id2] to true if id1 and id2 are duplicates. Must be symmetric, i.e., if [id1][id2] => True, then [id2][id1] => True.
      :param add_transitive_closure: If true, it adds a transitive closure, i.e. if dup[a][b] and dup[b][c], then dup[a][c]
      :param query_chunk_size: To identify the paraphrases, the cosine-similarity between all sentence-pairs will be computed. As this might require a lot of memory, we perform a batched computation.  #query_batch_size sentences will be compared against up to #corpus_batch_size sentences. In the default setting, 5000 sentences will be grouped together and compared up-to against 100k other sentences.
      :param corpus_chunk_size: The corpus will be batched, to reduce the memory requirement
      :param max_pairs: We will only extract up to #max_pairs potential paraphrase candidates.
      :param top_k: For each query, we extract the top_k most similar pairs and add it to a sorted list. I.e., for one sentence we cannot find more than top_k paraphrases
      :param show_progress_bar: Output a progress bar
      :param batch_size: Batch size for computing sentence embeddings
      :param name: Name of the experiment
      :param write_csv: Write results to CSV file
      """
      self.sentences = []
      self.ids = []
  
      for id, sentence in sentences_map.items():
          self.sentences.append(sentence)
          self.ids.append(id)
  
      self.name = name
      self.show_progress_bar = show_progress_bar
      self.batch_size = batch_size
      self.query_chunk_size = query_chunk_size
      self.corpus_chunk_size = corpus_chunk_size
      self.max_pairs = max_pairs
      self.top_k = top_k
  
      self.duplicates = (
          duplicates_dict
          if duplicates_dict is not None
          else defaultdict(lambda: defaultdict(bool))
      )
      if duplicates_list is not None:
          for id1, id2 in duplicates_list:
              if id1 in sentences_map and id2 in sentences_map:
                  self.duplicates[id1][id2] = True
                  self.duplicates[id2][id1] = True
  
      # Add transitive closure
      if add_transitive_closure:
          self.duplicates = self.add_transitive_closure(self.duplicates)
  
      positive_key_pairs = set()
      for key1 in self.duplicates:
          for key2 in self.duplicates[key1]:
              if (
                  key1 in sentences_map
                  and key2 in sentences_map
                  and (
                      self.duplicates[key1][key2]
                      or self.duplicates[key2][key1]
                  )
              ):
                  positive_key_pairs.add(tuple(sorted([key1, key2])))
  
      self.total_num_duplicates = len(positive_key_pairs)
  
      if name:
          name = "_" + name
  
      self.csv_file: str = (
          "paraphrase_mining_evaluation" + name + "_results.csv"
      )
      self.csv_headers = [
          "epoch",
          "steps",
          "precision",
          "recall",
          "f1",
          "threshold",
          "average_precision",
      ]
      self.write_csv = write_csv
  
file_path: sentence-transformers/sentence_transformers/evaluation/ParaphraseMiningEvaluator.py
imports: from .None import SentenceEvaluator
  import logging
  from sentence_transformers.util import paraphrase_mining
  import os
  import csv
  from typing import List, Tuple, Dict
  from collections import defaultdict
label_desc: Use image node_id 1 to create a new ParaphraseMiningEvaluator object from inherited base classes: SentenceEvaluator with example: obj = ParaphraseMiningEvaluator(sentences_map, duplicates_list, duplicates_dict, add_transitive_closure, query_chunk_size, corpus_chunk_size, max_pairs, top_k, show_progress_bar, batch_size, name, write_csv)