§
    ™Štj°Ì  ã                  óþ   — d dl mZ d dlZd dlZd dlZd dlZd dlmZmZ d dl	Z
d dlZd dlmZ d dlmZ ddlmZ  ej        e¦  «        Zerd dlmZ d d	lmZ d d
lmZ 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d>d?d=„ZdS )@é    )ÚannotationsN)ÚTYPE_CHECKINGÚLiteral)Útrange)Útqdmé   )Úis_datasets_available©ÚDataset)ÚCrossEncoder)ÚSentenceTransformeré   ÚtopFÚtripleté    é @  TÚdatasetr   Úmodelr   Úanchor_column_nameú
str | NoneÚpositive_column_nameÚcorpusúlist[str] | NoneÚcross_encoderúCrossEncoder | NoneÚ	range_minÚintÚ	range_maxú
int | NoneÚ	max_scoreúfloat | NoneÚ	min_scoreÚabsolute_marginÚrelative_marginÚnum_negativesÚsampling_strategyúLiteral['random', 'top']Úquery_prompt_nameÚquery_promptÚcorpus_prompt_nameÚcorpus_promptÚinclude_positivesÚboolÚoutput_formatú=Literal['triplet', 'n-tuple', 'labeled-pair', 'labeled-list']Úoutput_scoresÚ
batch_sizeÚfaiss_batch_sizeÚ	use_faissÚuse_multi_processúlist[str] | boolÚverboseÚcache_folderÚas_tripletsúbool | NoneÚmarginÚreturnc                ó*5  ‡‡‡m‡n‡o‡p‡q‡r‡s‡t— t          ¦   «         st          d¦  «        ‚t          | ¦  «        dk    rt          d¦  «        ‚|dk    rt          d|› d�¦  «        ‚|r(	 ddl}n"# t          $ r}t          d¦  «        |‚d}~ww xY wddlm} | j        } |r|| vr| d         }|r|| vr| d	         }|s$|s"t          | ¦  «        d
k    rt          d¦  «        ‚|�$|rdnd}t           	                    d|› d�¦  «         |rN|dk    s|€
|€|€|dk    rt           	                    d¦  «         |dk    rt           	                    d¦  «         d}|dk    rt           	                    d¦  «         d}d}|dvrt          d|› d�¦  «        ‚|� |}
t           	                    d|
› d�¦  «         t          |                      ¦   «                              |¦  «                             ¦   «                              ¦   «         |                              ¦   «         ¦  «        }!t!          |!¦  «        }"‰d	k     rt          d‰› d�¦  «        ‚d}#|€x|
€|€|�|‰dz  z   |"z   }n|‰z   |"z   }|rG||"z   dk    r> t#          |dd„ ¦  «        ¦   «         dk    r d|"z
  }d |› d!�}#|rt%          d"|› d�¦  «         |rt%          d#|› d$�¦  «         |dk     rt          d%|› d�¦  «        ‚||k    rt          d&|› d'|› d|#› �¦  «        ‚‰||z
  k    r!t          d(‰› d)||z
  › d*|› d+|› d,|#› �
¦  «        ‚i }$t          | |         ¦  «        }%t          | |         ¦  «        Št‰du}&|&s‰tŠt          t&                               ‰‰tz   ¦  «        ¦  «        Šd-„ t+          ‰¦  «        D ¦   «         }'|%                     ¦   «         Šmt          t&                               |%¦  «        ¦  «        }%d.„ t+          |%¦  «        D ¦   «         }(t          |%¦  «        })t/          j        |)¦  «                             d/¦  «        }*|j        Šn|)t          ‰m¦  «        k    r%|r#t%          d0|)› d1t          ‰m¦  «        › d2�¦  «         |"d	k    r(t7          j        |!¦  «        }+t%          d3|+d4›d5�¦  «         d},d}-|�r¢t;          j        |d¬6¦  «         |j        j         pd}.tC          j"        tG          |.|||%f¦  «         $                    ¦   «         d7¬8¦  «         %                    ¦   «         }/tC          j"        tG          |.||‰f¦  «         $                    ¦   «         d7¬8¦  «         %                    ¦   «         }0t:          j&         '                    |d9|/› d:�¦  «        }1t:          j&         '                    |d;|0› d:�¦  «        }2t:          j&         (                    |1¦  «        r1t7          j)        |1¦  «        }-|rt%          d<|1› d=|-j*        › d>�¦  «         t:          j&         (                    |2¦  «        r1t7          j)        |2¦  «        },|rt%          d?|2› d=|,j*        › d>�¦  «         |,�|-€‡|r.| +                    tY          |tZ          ¦  «        rdn|¬@¦  «        }3nd}3|,€| .                    ‰|3|ddd||¬A¦  «        },|-€| /                    |%|3|ddd||¬A¦  «        }-|r| 0                    |3¦  «         |r�t:          j&         (                    |1¦  «        s)t7          j1        |1|-¦  «         |rt%          dB|1› �¦  «         t:          j&         (                    |2¦  «        s)t7          j1        |2|,¦  «         |rt%          dC|2› �¦  «         |�rz| 2                    | 3                    ¦   «         ¦  «        }4	 | 4                    ¦   «         }5d|5_5        d|5_6        | 7                    |4|5¬D¦  «        }4n# tp          $ r Y nw xY w|4 9                    |,¦  «         g }6g }7tu          dt          |-¦  «        |dE¬F¦  «        D ]V}8|-|8|8|z   …         }9|4 ;                    |9||"z   ¬G¦  «        \  }:Šo|6 <                    |:¦  «         |7 <                    ‰o¦  «         ŒWt/          j=        t7          j>        |6d¬H¦  «        ¦  «         ?                    ‰n¦  «        }:t/          j=        t7          j>        |7d¬H¦  «        ¦  «         ?                    ‰n¦  «        Šo�n°g }6g }7t/          j@        |,¦  «        },tƒ          ||"z   t          ‰¦  «        ¦  «        };tu          dt          |-¦  «        |dI¬F¦  «        D ]z}8| B                    |-|8|8|z   …         |,¦  «         ?                    ‰n¦  «        }<t/          jC        |<|;d	¬J¦  «        \  }<}=|6 <                    |<¦  «         |7 <                    |=¦  «         Œ{t/          jD        |6d¬K¦  «        }:t/          jD        |7d¬K¦  «        Šo||"z   |: E                    d	¦  «        z
  }>|>dk    r�t/          jD        |:|: F                    |: E                    d¦  «        |>ft�          dL¦  «         ¦  «        gd	¬K¦  «        }:t/          jD        ‰o‰o F                    ‰o E                    d¦  «        |>fd/¦  «        gd	¬K¦  «        ŠodM„ t‘          |)¦  «        D ¦   «         Šrt“          ‰m‰t¦  «        D ]>\  }?}@|(|?         }A|'|@         ‰r|A         vr!‰r|A          <                    |'|@         ¦  «         Œ?dN„ ‰rD ¦   «         Špg Štg Šmt‘          |)¦  «        D ]N}B‰t J                    ˆfdO„‰r|B         D ¦   «         ¦  «         ‰m J                    |%|B         g‰p|B         z  ¦  «         ŒOˆnfdP„‰rD ¦   «         Šr|-ˆpfdQ„t‘          |)¦  «        D ¦   «                  }-|,t/          jD        ‰r¦  «         K                    ¦   «                  }C| L                    |-|C¦  «         ?                    ‰n¦  «        Šs~-~C~,|��>|
€|€|��7|r.| +                    tY          |tZ          ¦  «        rdn|¬@¦  «        }3nd}3t›          t+          ‰o¦  «        dRt          ‰o¦  «        ¬S¦  «        D ]z\  }B}D|%|B         }?ˆfdT„|DD ¦   «         }Et          |E¦  «        }F| N                    t          t“          |?g|Fz  |E¦  «        ¦  «        |d|3¬U¦  «         ?                    ‰n¦  «        }G|G|:|B<   Œ{| N                    t          t“          ‰m‰t¦  «        ¦  «        |d|3¬U¦  «         ?                    ‰n¦  «        Šs|r| 0                    |3¦  «         t�          dL¦  «         |:‰od/k    <   |sAt/          jO        ˆoˆrfdV„t‘          |)¦  «        D ¦   «         ¦  «        }Ht�          dL¦  «         |:|H<   |: P                    ¦   «         }F|
€|��ƒt/          jQ        |)‰sj        ‰sjR        ¬W¦  «        }Id}Jt‘          |)¦  «        D ]5}Kt/          jA        ‰s|J|J‰p|K         z   …         ¦  «        |I|K<   |J‰p|K         z  }JŒ6|
�€|:|
z   |I S                    |: E                    d	¦  «        d	¦  «        jT        k    }Lt�          dL¦  «         |:|L<   |L U                    ¦   «          V                    ¦   «         }M|Mr|M|M|Fz  dXœ|$dY<   |F|Mz  }F|�—|I|I W                    ¦   «         |z  z
  }N|:|N S                    |: E                    d	¦  «        d	¦  «        jT        k    }Lt�          dL¦  «         |:|L<   |L U                    ¦   «          V                    ¦   «         }M|Mr|M|M|Fz  dXœ|$dZ<   |F|Mz  }F|�L|:|k    }Lt�          dL¦  «         |:|L<   |L U                    ¦   «          V                    ¦   «         }M|Mr|M|M|Fz  dXœ|$d[<   |	�L|:|	k     }Lt�          dL¦  «         |:|L<   |L U                    ¦   «          V                    ¦   «         }M|Mr|M|M|Fz  dXœ|$d\<   t/          jC        |:|d	¬J¦  «        \  Šq}O‰o|*|Of         Šo|r‰odd…|d…f         Šo‰qdd…|d…f         Šq|dk    r‰odd…d‰…f         Šo‰qdd…d‰…f         ŠqnŸ|d]k    r™‰o E                    d	¦  «        ‰q X                    ¦   «          U                    d	¦  «        z
  }P|P Y                    ‰¬^¦  «        }Pˆfd_„|PD ¦   «         }Q‰o|*|Qf         Šo‰q|*|Qf         Šq‰q Z                    d	d¬`¦  «        \  Šq}O‰o|*|Of         Šo|rt%          da¦  «         |dk    �rOt/          jD        ˆoˆpfdb„t‘          |)¦  «        D ¦   «         ¦  «        Šot/          jD        ˆpˆqfdc„t‘          |)¦  «        D ¦   «         ¦  «        Šq‰qt�          dL¦  «         k    }Rt/          j[        ‰o¦  «        }St/          j[        ‰o¦  «        }T‰o|R         Šo‰q|R         Šqd}Ut‘          |)¦  «        D ]x}Kt/          j\        |K¦  «         S                    ‰p|K         ‰¦  «        |S|U|U‰p|K         z   …<   ‰r|K          S                    ‰d	¦  «        jT        |T|U|U‰p|K         z   …<   |U‰p|K         z  }UŒy|S|R         }S|T|R         Šr‰s S                    ‰d	¦  «        jT        |R         }V|g |g ddg i}W|rg |Wde<   t“          |S‰r‰o|V‰q¦  «        D ]®\  }X}Y}Z}[}\|W|          <                    |%|X         ¦  «         |W|          <                    ‰|Y         ¦  «         |Wdd          <                    ‰|Z         ¦  «         |rA|Wde          <                    |[ V                    ¦   «         |\ V                    ¦   «         g¦  «         Œ¯|V‰qz
  }]|R P                    ¦   «         }^�nì|dfk    �r|g |g i}W|rg |Wdg<   ng |Wdh<   d}Jt‘          |)¦  «        D �]l}A‰r|A         D ]œ}Y|W|          <                    |%|A         ¦  «         |W|          <                    ‰|Y         ¦  «         |r6‰s|J          V                    ¦   «         }[|Wdg          <                    |[¦  «         n|Wdh          <                    d	¦  «         |Jd	z  }JŒ�t“          ‰o|A         ‰q|A         ¦  «        D ]§\  }Z}_|_t�          dL¦  «         k    rŒ|W|          <                    |%|A         ¦  «         |W|          <                    ‰|Z         ¦  «         |r.|Wdg          <                    |_ V                    ¦   «         ¦  «         ŒŒ|Wdh          <                    d¦  «         Œ¨�Œnt/          jD        ˆpˆqfdi„t‘          |)¦  «        D ¦   «         ¦  «        Šq‰qt�          dL¦  «         k    }R‰q|R         Šq‰s S                    ‰d	¦  «        jT        |R         ‰qz
  }]|)‰z  t          | ¦  «        z   }^�nÎ|dk    �r—t/          jD        ˆoˆpfdj„t‘          |)¦  «        D ¦   «         ¦  «        Šot/          jD        ˆpˆqfdk„t‘          |)¦  «        D ¦   «         ¦  «        Šq‰qt�          dL¦  «         k     ]                    d	¬K¦  «        }R‰q|R         Šq‰o|R         Šo|ˆmfdl„t+          |R¦  «        D ¦   «         |ˆtfdm„t+          |R¦  «        D ¦   «         iˆfdn„t+          ‰ojT        d	¬o¦  «        D ¦   «         ¥}W|rFt/          jD        ‰s|R                              d/¦  «        ‰qgd	¬K¦  «         K                    ¦   «         |Wde<   ‰q ^                    ¦   «         Šq‰s S                    ‰d	¦  «        jT        |R          ^                    ¦   «         ‰qz
  }]|R E                    d¦  «        }^�n0|dpk    �r)t/          jD        ˆoˆpfdq„t‘          |)¦  «        D ¦   «         ¦  «        Šot/          jD        ˆpˆqfdr„t‘          |)¦  «        D ¦   «         ¦  «        Šq‰qt�          dL¦  «         k    }R|ˆmfds„t+          |R¦  «        D ¦   «         |ˆˆtfdt„t+          t“          |R‰o¦  «        ¦  «        D ¦   «         i}W|r ˆqˆsfdu„t+          |R¦  «        D ¦   «         |Wde<   ndv„ |RD ¦   «         |Wdw<   ‰q|R         Šq‰s S                    ‰d	¦  «        jT        |R         ‰qz
  }]|R E                    d¦  «        }^ |j_        |W¦  «        }`|�rtdx}ady„ }bt%          |a `                    dzd{d|d}¦  «        ¦  «         t%          |a `                    d~ |bt          ‰s¦  «        ¦  «         |bt          ‰q¦  «        ¦  «        d¦  «        ¦  «         dt.          j        fd€t.          ja        fd�t.          jb        fd‚dƒ„ fd„d…„ fd†d‡„ fdˆd‰„ fdŠd‹„ ffD ]r\  }c}dt%          |a `                    |c c                    ¦   «          |b |d‰s¦  «        ¦  «         |b |d‰q¦  «        ¦  «         |b |d|]¦  «        ¦  «        ¦  «        ¦  «         ŒsdY|
fdZ|fd[|fd\|	ffD ]C\  }e}f|e|$v r:|$|e         dŒ         }g|$|e         d�         }ht%          dŽ|gd�›d�|hd‘›d’|e› d“|f› d�	¦  «         ŒD|^t          |`¦  «        z
  }i|idk    rßd”g}j|dk    r|j <                    d•¦  «         |
�|j <                    dY¦  «         |�|j <                    dZ¦  «         |�|j <                    d[¦  «         t          |j¦  «        d	k    r*d– '                    |jdd/…         ¦  «        d—z   |jd/         z   }kn|jd         }k|i|^z  }lt%          d˜|i› d™|ld‘›dš|k› d›t          |j¦  «        d	k    rdœnd› d��	¦  «         |`S )žu+I  
    Add hard negatives to a dataset of (anchor, positive) pairs to create (anchor, positive, negative) triplets or
    (anchor, positive, negative_1, ..., negative_n) tuples.

    Hard negative mining is a technique to improve the quality of a dataset by adding hard negatives, which are
    texts that may appear similar to the anchor, but are not. Using hard negatives can improve the performance of
    models trained on the dataset.

    This function uses a SentenceTransformer model to embed the inputs in the dataset, and then finds the closest
    matches to each anchor input in the dataset. It then samples negatives from the closest matches, optionally
    using a CrossEncoder model to rescore the candidates.

    Supports prompt formatting for models that expect specific instruction-style input.

    You can influence the candidate negative selection in various ways:

    - **range_min**: Minimum rank of the closest matches to consider as negatives: useful to skip the most similar texts to
      avoid marking texts as negative that are actually positives.
    - **range_max**: Maximum rank of the closest matches to consider as negatives: useful to limit the number of candidates
      to sample negatives from. A lower value makes processing faster, but may result in less candidate negatives that
      satisfy the margin or max_score conditions.
    - **max_score**: Maximum score to consider as a negative: useful to skip candidates that are too similar to the anchor.
    - **min_score**: Minimum score to consider as a negative: useful to skip candidates that are too dissimilar to the anchor.
    - **absolute_margin**: Absolute margin for hard negative mining: useful to skip candidate negatives whose similarity
      to the anchor is within a certain margin of the positive pair. A value of 0 can be used to enforce that the negative
      is always further away from the anchor than the positive.
    - **relative_margin**: Relative margin for hard negative mining: useful to skip candidate negatives whose similarity
      to the anchor is within a certain margin of the positive pair. A value of 0.05 keeps a negative only if its
      similarity to the anchor is at least 5% of the positive score magnitude below the positive.
    - **sampling_strategy**: Sampling strategy for negatives: "top" or "random". "top" will always sample the top n
      candidates as negatives, while "random" will sample n negatives randomly from the candidates that satisfy the
      margin or max_score conditions.

    .. tip::

        The excellent `NV-Retriever paper <https://huggingface.co/papers/2407.15831>`_ is a great resource for understanding the
        details of hard negative mining and how to use it effectively. Notably, it reaches the strongest performance using
        these settings::

            dataset = mine_hard_negatives(
                dataset=dataset,
                model=model,
                relative_margin=0.05,         # keep negatives at least 5% of the positive score magnitude below the positive
                num_negatives=num_negatives,  # 10 or less is recommended
                sampling_strategy="top",      # "top" means that we sample the top candidates as negatives
                batch_size=batch_size,        # Adjust as needed
                use_faiss=True,               # Optional: Use faiss/faiss-gpu for faster similarity search
            )

        This corresponds with the `TopK-PercPos (95%)` mining method.

    Example:

        >>> from sentence_transformers.util import mine_hard_negatives
        >>> from sentence_transformers import SentenceTransformer
        >>> from datasets import load_dataset
        >>> # Load a Sentence Transformer model
        >>> model = SentenceTransformer("sentence-transformers/all-MiniLM-L6-v2")
        >>>
        >>> # Load a dataset to mine hard negatives from
        >>> dataset = load_dataset("sentence-transformers/natural-questions", split="train")
        >>> dataset
        Dataset({
            features: ['query', 'answer'],
            num_rows: 100231
        })
        >>> dataset = mine_hard_negatives(
        ...     dataset=dataset,
        ...     model=model,
        ...     range_min=10,
        ...     range_max=50,
        ...     max_score=0.8,
        ...     relative_margin=0.05,
        ...     num_negatives=5,
        ...     sampling_strategy="random",
        ...     batch_size=128,
        ...     use_faiss=True,
        ... )
        Batches: 100%|â–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆ| 588/588 [00:32<00:00, 18.07it/s]
        Batches: 100%|â–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆ| 784/784 [00:08<00:00, 96.41it/s]
        Querying FAISS index: 100%|â–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆ| 7/7 [00:06<00:00,  1.06it/s]
        Negative candidates mined, preparing dataset...
        Metric       Positive       Negative     Difference
        Count         100,231        487,865
        Mean           0.6866         0.4194         0.2752
        Median         0.7010         0.4102         0.2760
        Std            0.1125         0.0719         0.1136
        Min            0.0303         0.1702         0.0209
        25%            0.6221         0.3672         0.1899
        50%            0.7010         0.4102         0.2760
        75%            0.7667         0.4647         0.3590
        Max            0.9584         0.7621         0.7073
        Skipped 427,503 potential negatives (8.36%) due to the relative_margin of 0.05.
        Skipped 978 potential negatives (0.02%) due to the max_score of 0.8.
        Could not find enough negatives for 13290 samples (2.65%). Consider adjusting the range_max, range_min, relative_margin and max_score parameters if you'd like to find more valid negatives.
        >>> dataset
        Dataset({
            features: ['query', 'answer', 'negative'],
            num_rows: 487865
        })
        >>> dataset[0]
        {
            'query': 'when did richmond last play in a preliminary final',
            'answer': "Richmond Football Club Richmond began 2017 with 5 straight wins, a feat it had not achieved since 1995. A series of close losses hampered the Tigers throughout the middle of the season, including a 5-point loss to the Western Bulldogs, 2-point loss to Fremantle, and a 3-point loss to the Giants. Richmond ended the season strongly with convincing victories over Fremantle and St Kilda in the final two rounds, elevating the club to 3rd on the ladder. Richmond's first final of the season against the Cats at the MCG attracted a record qualifying final crowd of 95,028; the Tigers won by 51 points. Having advanced to the first preliminary finals for the first time since 2001, Richmond defeated Greater Western Sydney by 36 points in front of a crowd of 94,258 to progress to the Grand Final against Adelaide, their first Grand Final appearance since 1982. The attendance was 100,021, the largest crowd to a grand final since 1986. The Crows led at quarter time and led by as many as 13, but the Tigers took over the game as it progressed and scored seven straight goals at one point. They eventually would win by 48 points â€“ 16.12 (108) to Adelaide's 8.12 (60) â€“ to end their 37-year flag drought.[22] Dustin Martin also became the first player to win a Premiership medal, the Brownlow Medal and the Norm Smith Medal in the same season, while Damien Hardwick was named AFL Coaches Association Coach of the Year. Richmond's jump from 13th to premiers also marked the biggest jump from one AFL season to the next.",
            'negative': "2018 NRL Grand Final The 2018 NRL Grand Final was the conclusive and premiership-deciding game of the 2018 National Rugby League season and was played on Sunday September 30 at Sydney's ANZ Stadium.[1] The match was contested between minor premiers the Sydney Roosters and defending premiers the Melbourne Storm. In front of a crowd of 82,688, Sydney won the match 21Ã¢â‚¬â€œ6 to claim their 14th premiership title and their first since 2013. Roosters five-eighth Luke Keary was awarded the Clive Churchill Medal as the game's official man of the match."
        }
        >>> # To include similarity scores, use output_scores=True
        >>> dataset_with_scores = mine_hard_negatives(
        ...     dataset=dataset,
        ...     model=model,
        ...     output_scores=True,
        ...     # ... other parameters
        ... )
        >>> dataset_with_scores
        Dataset({
            features: ['query', 'answer', 'negative', 'scores'],
            num_rows: 487865
        })
        >>> dataset.push_to_hub("natural-questions-hard-negatives", "triplet-all")

    Args:
        dataset (Dataset): A dataset containing (anchor, positive) pairs.
        model (SentenceTransformer): A SentenceTransformer model to use for embedding the inputs.
        anchor_column_name (str, optional): The column name in `dataset` that contains the anchor/query. Defaults to None, in which case the first column in `dataset` will be used.
        positive_column_name (str, optional): The column name in `dataset` that contains the positive candidates. Defaults to None, in which case the second column in `dataset` will be used.
        corpus (List[str], optional): A list containing documents as strings that will be used as candidate negatives
            in addition to the second column in `dataset`. Defaults to None, in which case the second column in
            `dataset` will exclusively be used as the negative candidate corpus.
        cross_encoder (CrossEncoder, optional): A CrossEncoder model to use for rescoring the candidates. Defaults to None.
        range_min (int): Minimum rank of the closest matches to consider as negatives. Must be non-negative.
            Defaults to 0.
        range_max (int, optional): Maximum rank of the closest matches to consider as negatives. Must leave at least
            `num_negatives` candidates after `range_min`. Defaults to None.
        max_score (float, optional): Maximum score to consider as a negative. Defaults to None.
        min_score (float, optional): Minimum score to consider as a negative. Defaults to None.
        absolute_margin (float, optional): Absolute margin for hard negative mining, i.e. the minimum distance between
            the positive similarity and the negative similarity. Defaults to None.
        relative_margin (float, optional): Relative margin for hard negative mining, i.e. the minimum distance between
            the positive similarity and the negative similarity as a fraction of the positive score magnitude. A value
            of 0.05 discards negatives whose similarity is greater than ``positive_score - abs(positive_score) * 0.05``.
            Defaults to None.
        num_negatives (int): Number of negatives to sample. Must be at least 1, and must fit in the candidate
            window left by `range_min` and `range_max`. Defaults to 3.
        sampling_strategy (Literal["random", "top"]): Sampling strategy for negatives: "top" or "random". Defaults to "top".
        query_prompt_name (Optional[str], optional): The name of a predefined prompt to use when encoding the first/anchor dataset column.
            It must match a key in the ``model.prompts`` dictionary, which can be set during model initialization
            or loaded from the model configuration.

            For example, if ``query_prompt_name="query"`` and the model prompts dictionary includes {"query": "query: "},
            then the input "What is the capital of France?" is transformed into: "query: What is the capital of France?"
            before encoding. This is useful for models that were trained or fine-tuned with specific prompt formats.

            Ignored if ``query_prompt`` is provided. Defaults to None.

        query_prompt (Optional[str], optional): A raw prompt string to prepend directly to the first/anchor dataset column during encoding.

            For instance, `query_prompt="query: "` transforms the input "What is the capital of France?" into:
            "query: What is the capital of France?". Use this to override the prompt logic entirely and supply your own prefix.
            This takes precedence over ``query_prompt_name``. Defaults to None.
        corpus_prompt_name (Optional[str], optional): The name of a predefined prompt to use when encoding the corpus. See
            ``query_prompt_name`` for more information. Defaults to None.
        corpus_prompt (Optional[str], optional): A raw prompt string to prepend directly to the corpus during encoding.
            See ``query_prompt`` for more information. Defaults to None.
        include_positives (bool): Whether to include the positives in the negative candidates.
            Setting this to True is primarily useful for creating Reranking evaluation datasets for CrossEncoder models,
            where it can be useful to get a full ranking (including the positives) from a first-stage retrieval model.
            Defaults to False.
        output_format (Literal["triplet", "n-tuple", "labeled-pair", "labeled-list"]): Output format for the `datasets.Dataset`.
            When ``output_scores=False`` (default), options are:

            - "triplet": (anchor, positive, negative) triplets, i.e. 3 columns. Useful for e.g. :class:`~sentence_transformers.cross_encoder.losses.CachedMultipleNegativesRankingLoss`.
            - "n-tuple": (anchor, positive, negative_1, ..., negative_n) tuples, i.e. 2 + num_negatives columns. Useful for e.g. :class:`~sentence_transformers.cross_encoder.losses.CachedMultipleNegativesRankingLoss`.
            - "labeled-pair": (anchor, document, label) tuples with a label of 0 for negative and 1 for positive, i.e. 3 columns. Useful for e.g. :class:`~sentence_transformers.cross_encoder.losses.BinaryCrossEntropyLoss`.
            - "labeled-list": (anchor, [doc1, doc2, ..., docN], [label1, label2, ..., labelN]) tuples with labels of 0 for negative and 1 for positive, i.e. 3 columns. Useful for e.g. :class:`~sentence_transformers.cross_encoder.losses.LambdaLoss`.

            Defaults to "triplet". See ``output_scores`` for the output formats when ``output_scores=True``.
        output_scores (bool): Whether to include similarity scores in the output dataset. When True, adds score fields to the output:
            - For "triplet" format: adds `scores` column with query-positive and query-negative similarity scores, for 4 columns total.
            - For "n-tuple" format: adds `scores` column with a list of similarity scores for the query-positive and each of the query-negative pairs, for 3 + num_negatives columns total. Useful for e.g. :class:`~sentence_transformers.sparse_encoder.losses.SparseMarginMSELoss`.
            - For "labeled-pair" format: replaces the `label` column with a `score` column. Labels are binary (1 for positive, 0 for negative), but scores contain the actual similarity scores computed by the model or cross_encoder. The output has 3 columns.
            - For "labeled-list" format: replaces the `labels` column with a `scores` column. Labels are binary (1 for positive, 0 for negative), but scores contain the actual similarity scores computed by the model or cross_encoder. The output has 3 columns.
            Defaults to False.
        batch_size (int): Batch size for encoding the dataset. Defaults to 32.
        faiss_batch_size (int): Batch size of queries for the top-k similarity search, both with FAISS and without
            (``use_faiss=False``), where it bounds the size of the intermediate similarity matrix to
            ``faiss_batch_size * len(corpus)``. Defaults to 16384.
        use_faiss (bool): Whether to use FAISS for similarity search. May be recommended for large datasets. Requires
            the ``faiss-cpu`` or ``faiss-gpu`` package. On GPU, FAISS can retrieve at most 2048 documents per query,
            so an automatically derived ``range_max`` is capped to fit. Defaults to False.
        use_multi_process (bool | List[str], optional): Whether to use multi-GPU/CPU processing. If True, uses all GPUs if CUDA
            is available, and 4 CPU processes if it's not available. You can also pass a list of PyTorch devices like
            ["cuda:0", "cuda:1", ...] or ["cpu", "cpu", "cpu", "cpu"].
        verbose (bool): Whether to print statistics and logging. Defaults to True.
        cache_folder (str, optional): Directory path for caching embeddings. If provided, the function will save
            ``query_embeddings_{hash}.npy`` and ``corpus_embeddings_{hash}.npy`` under this folder after the first run,
            and on subsequent calls will load from these files if they exist to avoid recomputation. The hashes are
            computed based on the model name, the query/corpus prompts, and the queries/corpus, so changing the prompt
            arguments invalidates the cache rather than silently returning embeddings from a different prompt.
            Defaults to None.
        as_triplets (bool, optional): Deprecated. Use `output_format` instead. Defaults to None.
        margin (float, optional): Deprecated. Use `absolute_margin` or `relative_margin` instead. Defaults to None.

    Returns:
        Dataset: A dataset containing the specified output format. If `output_scores=False` (default), the formats are:

        - "triplet": (anchor, positive, negative)
        - "n-tuple": (anchor, positive, negative_1, ..., negative_n)
        - "labeled-pair": (anchor, document, label)
        - "labeled-list": (anchor, [documents], [labels])

        And if `output_scores=True`, the formats are:

        - "triplet": (anchor, positive, negative, [scores])
        - "n-tuple": (anchor, positive, negative_1, ..., negative_n, [scores])
        - "labeled-pair": (anchor, document, score)
        - "labeled-list": (anchor, [documents], [scores])
    zGPlease install `datasets` to use this function: `pip install datasets`.r   z9The dataset is empty. Please provide a non-empty dataset.z1faiss_batch_size must be a positive integer, got ú.NzlPlease install `faiss` to use this function with `use_faiss=True`: `pip install faiss-cpu` (or `faiss-gpu`).r
   r   é   z)Dataset must contain exactly two columns.r   ún-tuplezrThe `as_triplets` parameter is deprecated. Use the `output_format` parameter instead. Setting `output_format` to `z`.r   z´When using `include_positives=True`, updating `range_min`, `range_max`, `max_score`, `margin`, or `sampling_strategy` from the default values may still discard the positive values.z~When using `include_positives=True`, `output_format` will be set to `"n-tuple"` to ensure that the ranking order is preserved.zn-tuple-scoreszŽ`output_format="n-tuple-scores"` is deprecated. Use `output_format="n-tuple"` with `output_scores=True` instead for equivalent output formats.T)r   r?   úlabeled-pairúlabeled-listzInvalid output_format: zI. Must be one of 'triplet', 'n-tuple', 'labeled-pair', or 'labeled-list'.zŠThe `margin` parameter is deprecated. Use the `absolute_margin` and/or `relative_margin` parameter instead. Setting `absolute_margin` to `z4num_negatives must be at least 1, got num_negatives=Ú é
   i   Úget_num_gpusc                 ó   — dS )Nr   © rF   ó    úg/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/sentence_transformers/util/hard_negatives.pyú<lambda>z%mine_hard_negatives.<locals>.<lambda>t  s   € °a€ rG   z# Note that range_max was capped to zÅ because FAISS on GPU can only retrieve up to 2048 documents per query, some of which are reserved for the positives. Passing use_faiss=False lifts that cap, although it can cost a lot more memory.zŒUsing FAISS on GPU, we can only retrieve up to 2048 documents per query, some of which are reserved for the positives. Setting range_max to zSetting range_max to z" based on the provided parameters.z.range_min must be non-negative, got range_min=z8range_min must be smaller than range_max, got range_min=z and range_max=zCannot mine z negatives per query: only z6 candidates remain after skipping the first range_min=z of range_max=zJ. Consider decreasing num_negatives or range_min, or increasing range_max.c                ó   — i | ]\  }}||“Œ	S rF   rF   )Ú.0ÚidxÚtexts      rH   ú
<dictcomp>z'mine_hard_negatives.<locals>.<dictcomp>   s   € Ð?Ð?Ð?¡	  T�$˜Ð?Ð?Ð?rG   c                ó   — i | ]\  }}||“Œ	S rF   rF   )rK   rL   Úquerys      rH   rN   z'mine_hard_negatives.<locals>.<dictcomp>¥  s   € ÐCÐCÐC¡* # u�5˜#ÐCÐCÐCrG   éÿÿÿÿzFound z unique queries out of z total queries.zFound an average of z.3fz positives per query.)Úexist_okF)ÚusedforsecurityÚquery_embeddings_z.npyÚcorpus_embeddings_z%[Cache] Loaded query embeddings from z (shape=ú)z&[Cache] Loaded corpus embeddings from )Útarget_devices)Úpoolr1   Únormalize_embeddingsÚconvert_to_numpyÚshow_progress_barÚprompt_nameÚpromptz"[Cache] Saved query embeddings to z#[Cache] Saved corpus embeddings to )ÚcozQuerying FAISS index)Údesc©Úk)ÚaxiszComputing similarity scores)ra   Údim)rc   Úinfc                ó   — g | ]}g ‘ŒS rF   rF   )rK   Ú_s     rH   ú
<listcomp>z'mine_hard_negatives.<locals>.<listcomp>/  s   € Ð5Ð5Ð5˜q˜Ð5Ð5Ð5rG   c                ó,   — g | ]}t          |¦  «        ‘ŒS rF   )Úlen)rK   Úps     rH   rg   z'mine_hard_negatives.<locals>.<listcomp>6  s   € Ð4Ð4Ð4˜a•3�q‘6”6Ð4Ð4Ð4rG   c                ó    •— g | ]
}‰|         ‘ŒS rF   rF   )rK   Údoc_idxr   s     €rH   rg   z'mine_hard_negatives.<locals>.<listcomp><  s   ø€ ÐOÐOÐO¨g˜& œ/ÐOÐOÐOrG   c                ó<   •— g | ]}t          j        |‰¬ ¦  «        ‘ŒS ))Údevice)ÚtorchÚtensor)rK   rj   rn   s     €rH   rg   z'mine_hard_negatives.<locals>.<listcomp>?  s(   ø€ ÐQÐQÐQ¸1�œ Q¨vÐ6Ñ6Ô6ÐQÐQÐQrG   c                óD   •— g | ]}t          ‰|         ¦  «        D ]}|‘ŒŒS rF   )Úrange)rK   rL   rf   Ún_positivess      €rH   rg   z'mine_hard_negatives.<locals>.<listcomp>B  s6   ø€ Ð(jÐ(jÐ(j°ÕRWÐXcÐdgÔXhÑRiÔRiÐ(jÐ(jÈQ¨Ð(jÐ(jÐ(jÐ(jrG   zRescoring with CrossEncoder)r_   Útotalc                ó    •— g | ]
}‰|         ‘ŒS rF   rF   )rK   Ú_idxr   s     €rH   rg   z'mine_hard_negatives.<locals>.<listcomp>V  s   ø€ Ð!IÐ!IÐ!I°4 &¨¤,Ð!IÐ!IÐ!IrG   )r1   Úconvert_to_tensorrX   c                óR   •— g | ]#}t          j        ‰|         ‰|         ¦  «        ‘Œ$S rF   )ro   Úisin)rK   Úq_idxÚindicesÚpositive_indicess     €€rH   rg   z'mine_hard_negatives.<locals>.<listcomp>p  s/   ø€ Ð_Ð_Ð_ÀU�UŒZ˜ œÐ(8¸Ô(?Ñ@Ô@Ð_Ð_Ð_rG   )rn   Údtype)ÚskippedÚratior#   r$   r    r"   Úrandom)Úminc                óV   •— g | ]%}t          j        t          |¦  «        ‰¬ ¦  «        ‘Œ&S )r`   )r€   Úsamplerr   )rK   Úoptionsr%   s     €rH   rg   z'mine_hard_negatives.<locals>.<listcomp>Å  s.   ø€ ÐaÐaÐaÈ'•v”}¥U¨7¡^¤^°}ÐEÑEÔEÐaÐaÐarG   )rc   Ú
descendingz/Negative candidates mined, preparing dataset...c                óT   •— g | ]$}‰|                               ‰|         d ¦  «        ‘Œ%S ©r   ©Úrepeat©rK   rL   r{   rs   s     €€rH   rg   z'mine_hard_negatives.<locals>.<listcomp>Ñ  ó2   ø€ ÐbÐbÐbÈ#˜W Sœ\×0Ò0°¸SÔ1AÀ1ÑEÔEÐbÐbÐbrG   c                óT   •— g | ]$}‰|                               ‰|         d ¦  «        ‘Œ%S r‡   rˆ   ©rK   rL   rs   Únegative_scoress     €€rH   rg   z'mine_hard_negatives.<locals>.<listcomp>Ò  ó5   ø€ Ð$rÐ$rÐ$rÐZ] _°SÔ%9×%@Ò%@ÀÈSÔAQÐSTÑ%UÔ%UÐ$rÐ$rÐ$rrG   ÚnegativeÚscoresr@   ÚscoreÚlabelc                óT   •— g | ]$}‰|                               ‰|         d ¦  «        ‘Œ%S r‡   rˆ   r�   s     €€rH   rg   z'mine_hard_negatives.<locals>.<listcomp>%  r�   rG   c                óT   •— g | ]$}‰|                               ‰|         d ¦  «        ‘Œ%S r‡   rˆ   rŠ   s     €€rH   rg   z'mine_hard_negatives.<locals>.<listcomp>-  r‹   rG   c                óT   •— g | ]$}‰|                               ‰|         d ¦  «        ‘Œ%S r‡   rˆ   r�   s     €€rH   rg   z'mine_hard_negatives.<locals>.<listcomp>.  r�   rG   c                ó*   •— g | ]\  }}|¯‰|         ‘ŒS rF   rF   )rK   rL   ÚkeepÚall_queriess      €rH   rg   z'mine_hard_negatives.<locals>.<listcomp>7  s(   ø€ Ð fÐ fÐ f±i°c¸4ÐaeÐ f ¨SÔ!1Ð fÐ fÐ frG   c                ó*   •— g | ]\  }}|¯‰|         ‘ŒS rF   rF   )rK   rL   r˜   Ú	positivess      €rH   rg   z'mine_hard_negatives.<locals>.<listcomp>8  s'   ø€ Ð"fÐ"fÐ"f±i°c¸4ÐaeÐ"f 9¨S¤>Ð"fÐ"fÐ"frG   c                ó:   •— i | ]\  }}d |› �ˆfd„|D ¦   «         “ŒS )Ú	negative_c                ó    •— g | ]
}‰|         ‘ŒS rF   rF   )rK   Úneg_idxr   s     €rH   rg   z2mine_hard_negatives.<locals>.<dictcomp>.<listcomp>:  s   ø€ Ð!MÐ!MÐ!M°g &¨¤/Ð!MÐ!MÐ!MrG   rF   )rK   ÚiÚneg_indicesr   s      €rH   rN   z'mine_hard_negatives.<locals>.<dictcomp>9  sJ   ø€ ð ð ð á"�A�{ð  ˜A��Ð!MÐ!MÐ!MÐ!MÀÐ!MÑ!MÔ!Mðð ð rG   )ÚstartrA   c                óT   •— g | ]$}‰|                               ‰|         d ¦  «        ‘Œ%S r‡   rˆ   rŠ   s     €€rH   rg   z'mine_hard_negatives.<locals>.<listcomp>I  r‹   rG   c                óT   •— g | ]$}‰|                               ‰|         d ¦  «        ‘Œ%S r‡   rˆ   r�   s     €€rH   rg   z'mine_hard_negatives.<locals>.<listcomp>J  r�   rG   c                óN   •— g | ]!\  }}|                      ¦   «         ¯‰|         ‘Œ"S rF   )Úany)rK   rL   Úkeep_rowr™   s      €rH   rg   z'mine_hard_negatives.<locals>.<listcomp>O  s4   ø€ Ð tÐ tÐ t±m°c¸8Ðem×eqÒeqÑesÔesÐ t ¨SÔ!1Ð tÐ tÐ trG   c                ó�   •— g | ]B\  }\  }}|                      ¦   «         ¯‰|         gˆfd „t          ||¦  «        D ¦   «         z   ‘ŒCS )c                ó*   •— g | ]\  }}|¯‰|         ‘ŒS rF   rF   )rK   r˜   Úindexr   s      €rH   rg   z2mine_hard_negatives.<locals>.<listcomp>.<listcomp>Q  s'   ø€ Ð#hÐ#hÐ#h±k°d¸EÐcgÐ#h F¨5¤MÐ#hÐ#hÐ#hrG   )r¦   Úzip)rK   rL   r§   Úindices_rowr   r›   s       €€rH   rg   z'mine_hard_negatives.<locals>.<listcomp>P  sl   ø€ ð #ð #ð #á0�CÑ0˜( KØ—<’<‘>”>ð#Ø˜3”Ð Ð#hÐ#hÐ#hÐ#hÅSÈÐS^ÑE_ÔE_Ð#hÑ#hÔ#hÑhð#ð #ð #rG   c                ó¶   •— g | ]U\  }}|                      ¦   «         ¯‰|                              ¦   «         g‰|         |                              ¦   «         z   ‘ŒVS rF   )r¦   ÚitemÚtolist)rK   rL   r§   rŽ   Úpositive_scoress      €€rH   rg   z'mine_hard_negatives.<locals>.<listcomp>X  sj   ø€ ð &ð &ð &á!�C˜Ø—<’<‘>”>ð&Ø  Ô%×*Ò*Ñ,Ô,Ð-°ÀÔ0DÀXÔ0N×0UÒ0UÑ0WÔ0WÑWð&ð &ð &rG   c                ód   — g | ]-}|                      ¦   «         ¯d gdgt          |¦  «        z  z   ‘Œ.S )r   r   )r¦   Úsum)rK   r§   s     rH   rg   z'mine_hard_negatives.<locals>.<listcomp>^  s>   € Ð%rÐ%rÐ%rÀHÐck×coÒcoÑcqÔcqÐ%r q c¨Q¨Cµ#°h±-´-Ñ,?Ñ&?Ð%rÐ%rÐ%rrG   Úlabelsz{:<6} {:>14} {:>14} {:>14}c                ój   — t          | t          j        ¦  «        r|                      ¦   «         d›n| d›S )Nz.4fú,)Ú
isinstancero   ÚTensorr®   )Úvalues    rH   rI   z%mine_hard_negatives.<locals>.<lambda>i  s1   € ½:ÀeÍUÌ\Ñ;ZÔ;ZÐ"l U§Z¢Z¡\¤\Ð"7Ð"7Ð"7ÐchÐ`lÐ`l€ rG   ÚMetricÚPositiveÚNegativeÚ
DifferenceÚCountÚmeanÚmedianÚstdr�   c                óx   — |                       ¦   «         dk    rt          j        | ¦  «        nt          d¦  «        S )Nr   rd   )Únumelro   r�   Úfloat©r‘   s    rH   rI   z%mine_hard_negatives.<locals>.<lambda>w  s1   € ¸¿º¹¼ÈÒ8JÐ8J¥5¤9¨VÑ#4Ô#4Ð#4ÕPUÐV[ÑP\ÔP\€ rG   z25%c                ó    — |                       ¦   «         dk    r(t          j        |                      ¦   «         d¬¦  «        nt          d¦  «        S )Nr   g      Ð?©Úqrd   ©rÂ   ro   ÚquantilerÃ   rÄ   s    rH   rI   z%mine_hard_negatives.<locals>.<lambda>x  ó?   € ÈVÏ\Ê\É^Ì^Ð^_ÒM_ÐM_¥5¤>°&·,²,±.´.ÀDÐ#IÑ#IÔ#IÐ#IÕejÐkpÑeqÔeq€ rG   z50%c                ó    — |                       ¦   «         dk    r(t          j        |                      ¦   «         d¬¦  «        nt          d¦  «        S )Nr   g      à?rÆ   rd   rÈ   rÄ   s    rH   rI   z%mine_hard_negatives.<locals>.<lambda>y  s?   € ÈFÏLÊLÉNÌNÐ]^ÒL^ÐL^¥5¤>°&·,²,±.´.ÀCÐ#HÑ#HÔ#HÐ#HÕdiÐjoÑdpÔdp€ rG   z75%c                ó    — |                       ¦   «         dk    r(t          j        |                      ¦   «         d¬¦  «        nt          d¦  «        S )Nr   g      è?rÆ   rd   rÈ   rÄ   s    rH   rI   z%mine_hard_negatives.<locals>.<lambda>z  rÊ   rG   Úmaxc                óx   — |                       ¦   «         dk    rt          j        | ¦  «        nt          d¦  «        S )Nr   z-inf)rÂ   ro   rÍ   rÃ   rÄ   s    rH   rI   z%mine_hard_negatives.<locals>.<lambda>{  s1   € ¸¿º¹¼ÈÒ8JÐ8J¥5¤9¨VÑ#4Ô#4Ð#4ÕPUÐV\ÑP]ÔP]€ rG   r~   r   zSkipped rµ   z potential negatives (z.2%z) due to the z of r   r   z, z and z$Could not find enough negatives for z
 samples (z). Consider adjusting the z
 parameterÚsz, if you'd like to find more valid negatives.)dr	   ÚImportErrorri   Ú
ValueErrorÚfaissÚdatasetsr   Úcolumn_namesÚloggerÚwarningÚlistÚ	to_pandasÚgroupbyÚcountÚto_dictÚvaluesrÍ   ÚgetattrÚprintÚdictÚfromkeysÚ	enumerateÚcopyro   ÚarangeÚ	unsqueezern   Únpr¾   ÚosÚmakedirsÚmodel_card_dataÚ
base_modelÚhashlibÚsha256ÚreprÚencodeÚ	hexdigestÚpathÚjoinÚexistsÚloadÚshapeÚstart_multi_process_poolr¶   r-   Úencode_documentÚencode_queryÚstop_multi_process_poolÚsaveÚIndexFlatIPÚget_embedding_dimensionÚGpuMultipleClonerOptionsÚshardÚ
useFloat16Úindex_cpu_to_all_gpusÚ	ExceptionÚaddr   ÚsearchÚappendÚ
from_numpyÚconcatenateÚtoÚ	as_tensorr�   Ú
similarityÚtopkÚcatÚsizeÚnew_fullrÃ   rr   r«   Úextendr¯   Úsimilarity_pairwiser   ÚpredictÚstackrÂ   Úemptyr}   r‰   ÚTr²   r®   ÚabsÚisinfÚclampÚsortÚ
empty_likerp   ÚallÚflattenÚ	from_dictÚformatr¿   rÀ   Ú
capitalize)ur   r   r   r   r   r   r   r   r    r"   r#   r$   r%   r&   r(   r)   r*   r+   r,   r.   r0   r1   r2   r3   r4   r6   r7   r8   r:   rÒ   Úexcr   ÚcolumnsÚpositives_per_queryÚmax_positivesÚfaiss_cap_noteÚlog_countersÚqueriesÚseparate_corpusÚ
corpus_idxÚqueries_idxÚ	n_queriesÚ	batch_idxÚavg_positives_per_queryÚcorpus_embeddingsÚquery_embeddingsÚ
model_nameÚ
query_hashÚcorpus_hashÚquery_cache_fileÚcorpus_cache_filerX   rª   r^   Úscores_listÚindices_listr    Úquery_chunkr‘   ra   Úchunk_scoresÚchunk_indicesÚmissingrP   ÚpositiveÚ	query_idxrL   Úpositive_embeddingsÚcandidate_idxÚcandidate_passagesÚnum_candidatesÚpred_scoresÚpositive_maskÚmax_positive_scoresÚpositive_score_idxrz   Úremoved_indicesÚnum_skippedÚrelative_thresholdÚlocal_indicesÚnum_optionsÚsampled_idxÚindices_to_keepÚanchor_indicesÚpos_indicesÚ	start_idxÚpositive_triplet_scoresÚdataset_dataÚ
anchor_idxÚpositive_idxÚnegative_idxÚ	pos_scoreÚ	neg_scoreÚdifference_scoresÚmaximum_possible_samplesÚnegative_scoreÚoutput_datasetÚ
row_formatÚ	formatterÚmetricÚfunctionÚ
param_nameÚparam_valuer~   r   Úmissing_samplesÚ	solutionsÚconsiderationsÚmissing_samples_ratior™   rn   r{   rs   rŽ   r|   r°   r›   su       `       `                                                                                                @@@@@@@@rH   Úmine_hard_negativesr_     sÈ   øøøøøøøøøø€ õp !Ñ"Ô"ð eÝÐcÑdÔdÐdå
ˆ7�|„|�qÒÐÝÐTÑUÔUÐUà˜1ÒÐÝÐ`ÐM]Ð`Ð`Ð`ÑaÔaÐaàð ð	ØˆLˆLˆLˆLøÝð 	ð 	ð 	Ýð<ñô ð ðøøøøð	øøøð !Ð Ð Ð Ð Ð ð Ô"€Gàð (Ð!3¸7Ð!BÐ!BØ$ QœZÐàð *Ð#7¸wÐ#FÐ#FØ& qœzÐàð FÐ&:ð F½sÀ7¹|¼|ÈqÒ?PÐ?PÝÐDÑEÔEÐEàÐØ%0Ð?˜	˜	°iˆÝ�Šð=Ø+8ð=ð =ð =ñ	
ô 	
ð 	
ð
 ð &à˜ŠNˆNØÐ$ØÐ$ØÐ!Ø  EÒ)Ð)å�NŠNðeñô ð ð ˜IÒ%Ð%Ý�NŠNð Qñô ð ð &ˆMàÐ(Ò(Ð(Ý�ŠðJñ	
ô 	
ð 	
ð "ˆØˆàÐRÐRÐRÝØ~ mÐ~Ð~Ð~ñ
ô 
ð 	
ð ÐØ ˆÝ�ŠðAØ-<ðAð Að Añ	
ô 	
ð 	
õ Ø×ÒÑÔ×#Ò#Ð$6Ñ7Ô7×=Ò=Ñ?Ô?×GÒGÑIÔIÐJ^Ô_×fÒfÑhÔhñô Ðõ Ð+Ñ,Ô,€Mð �qÒÐÝÐ`ÐP]Ð`Ð`Ð`ÑaÔaÐaà€NØÐØÐ&¨/Ð*EÈÐI^à! ]°RÑ%7Ñ8¸=ÑHˆIˆIð " MÑ1°MÑAˆIØð 	˜ ]Ñ2°TÒ9Ð9ð 9�w�u˜n¨i¨iÑ8Ô8Ñ:Ô:¸QÒ>Ð>Ø  =Ñ0�	ðO¸)ð Oð Oð Oð ð
 ð Ýð]ØPYð]ð ]ð ]ñô ð ð ð 	YÝÐW¨)ÐWÐWÐWÑXÔXÐXà�1‚}€}ÝÐVÈ)ÐVÐVÐVÑWÔWÐWà�IÒÐÝðTØ&ðTð TØ7@ðTð TØCQðTð Tñ
ô 
ð 	
ð
 �y 9Ñ,Ò,Ð,ÝðF˜=ð Fð FÀYÐQZÑEZð Fð FØ,5ðFð FØENðFð Fà5CðFð Fñ
ô 
ð 	
ð €LÝ�7Ð-Ô.Ñ/Ô/€GÝ�WÐ1Ô2Ñ3Ô3€IØ DÐ(€OØð Øˆõ •$—-’- ¨Ñ 2Ñ3Ô3Ñ4Ô4€Fð @Ð?­Y°vÑ->Ô->Ð?Ñ?Ô?€Jð —,’,‘.”.€KÝ•4—=’= Ñ)Ô)Ñ*Ô*€GØCÐCµ	¸'Ñ0BÔ0BÐCÑCÔC€KÝ�G‘”€IÝ”˜YÑ'Ô'×1Ò1°"Ñ5Ô5€IàŒ\€Fà•C˜Ñ$Ô$Ò$Ð$¨Ð$ÝÐZ�yÐZÐZ½¸[Ñ9IÔ9IÐZÐZÐZÑ[Ô[Ð[à�qÒÐÝ"$¤'Ð*=Ñ">Ô">ÐÝÐWÐ%<ÐWÐWÐWÐWÑXÔXÐXàÐØÐàñ vÝ
Œ�L¨4Ð0Ñ0Ô0Ð0àÔ*Ô5Ð;¸ˆ
Ý”^Ý�*˜lÐ,=¸wÐGÑHÔH×OÒOÑQÔQØ!ð
ñ 
ô 
÷ Š)‰+Œ+ð 	õ ”nÝ�*˜mÐ-?ÀÐHÑIÔI×PÒPÑRÔRØ!ð
ñ 
ô 
÷ Š)‰+Œ+ð 	õ
 œ7Ÿ<š<¨Ð6ZÈ*Ð6ZÐ6ZÐ6ZÑ[Ô[ÐÝœGŸLšL¨Ð7]ÈKÐ7]Ð7]Ð7]Ñ^Ô^ÐåŒ7�>Š>Ð*Ñ+Ô+ð 	sÝ!œwÐ'7Ñ8Ô8ÐØð sÝÐqÐ>NÐqÐqÐXhÔXnÐqÐqÐqÑrÔrÐråŒ7�>Š>Ð+Ñ,Ô,ð 	vÝ "¤Ð(9Ñ :Ô :ÐØð vÝÐtÐ?PÐtÐtÐZkÔZqÐtÐtÐtÑuÔuÐuð Ð Ð$4Ð$<Øð 	Ø×1Ò1Ý'1Ð2CÅTÑ'JÔ'JÐa˜t˜tÐPað 2ñ ô ˆDˆDð ˆDØÐ$Ø %× 5Ò 5ØØØ%Ø%)Ø!%Ø"&Ø.Ø$ð !6ñ 	!ô 	!Ðð Ð#Ø$×1Ò1ØØØ%Ø%)Ø!%Ø"&Ø-Ø#ð  2ñ 	 ô 	 Ðð ð 	0Ø×)Ò)¨$Ñ/Ô/Ð/àð 	QÝŒw�~Š~Ð.Ñ/Ô/ð 	OÝŒGÐ$Ð&6Ñ7Ô7Ð7Øð OÝÐMÐ;KÐMÐMÑNÔNÐNåŒw�~Š~Ð/Ñ0Ô0ð 	QÝŒGÐ%Ð'8Ñ9Ô9Ð9Øð QÝÐOÐ<MÐOÐOÑPÔPÐPàñ /dØ×!Ò! %×"?Ò"?Ñ"AÔ"AÑBÔBˆð	Ø×/Ò/Ñ1Ô1ˆBØˆBŒHØ ˆBŒMØ',×'BÒ'BÀ5ÈRÐ'BÑ'PÔ'PˆEˆEøÝð 	ð 	ð 	ØˆDð	øøøð 	�	Š	Ð#Ñ$Ô$Ð$àˆØˆå˜�3Ð/Ñ0Ô0Ð2BÐI_Ð`Ñ`Ô`ð 	)ð 	)ˆAØ*¨1¨qÐ3CÑ/CÐ+CÔDˆKà#Ÿlšl¨;¸)ÀmÑ:S˜lÑTÔT‰OˆF�GØ×Ò˜vÑ&Ô&Ð&Ø×Ò Ñ(Ô(Ð(Ð(ÝÔ!¥"¤.°À1Ð"EÑ"EÔ"EÑFÔF×IÒIÈ&ÑQÔQˆÝÔ"¥2¤>°,ÀQÐ#GÑ#GÔ#GÑHÔH×KÒKÈFÑSÔSˆ‰ð ˆØˆÝ!œOÐ,=Ñ>Ô>Ðå�	˜MÑ)­3¨v©;¬;Ñ7Ô7ˆõ ˜�3Ð/Ñ0Ô0Ð2BÐIfÐgÑgÔgð 	/ð 	/ˆAØ ×+Ò+Ð,<¸QÀÐEUÑAUÐ=UÔ,VÐXiÑjÔj×mÒmÐntÑuÔuˆLõ +0¬*°\ÀQÈAÐ*NÑ*NÔ*NÑ'ˆL˜-Ø×Ò˜|Ñ,Ô,Ð,Ø×Ò Ñ.Ô.Ð.Ð.Ý”˜;¨AÐ.Ñ.Ô.ˆÝ”)˜L¨aÐ0Ñ0Ô0ˆð ˜}Ñ,°·²¸A±´Ñ>ˆØ�QŠ;ˆ;Ý”Y ¨¯ª¸¿ºÀQ¹¼ÈÐ8QÕTYÐZ_ÑT`ÔT`ÐS`Ñ(aÔ(aÐbÐhiÐjÑjÔjˆFÝ”i ¨'×*:Ò*:¸G¿LºLÈ¹O¼OÈWÐ;UÐWYÑ*ZÔ*ZÐ [ÐabÐcÑcÔcˆGð
 6Ð5¥E¨)Ñ$4Ô$4Ð5Ñ5Ô5Ðå˜{¨IÑ6Ô6ð Eð E‰ˆˆxØ Ô&ˆ	Ø�hÔÐ'7¸	Ô'BÐBÐBØ˜YÔ'×.Ò.¨z¸(Ô/CÑDÔDÐDøà4Ð4Ð#3Ð4Ñ4Ô4€Kð €IØ€KÝ�YÑÔð >ð >ˆØ×ÒÐOÐOÐOÐOÐ9IÈ#Ô9NÐOÑOÔOÑPÔPÐPØ×Ò˜G CœL˜>¨K¸Ô,<Ñ<Ñ=Ô=Ð=Ð=àQÐQÐQÐQÐ@PÐQÑQÔQÐð (Ð(jÐ(jÐ(jÐ(j½¸iÑ8HÔ8HÐ(jÑ(jÔ(jÔkÐØ+­E¬IÐ6FÑ,GÔ,G×,NÒ,NÑ,PÔ,PÔQÐØ×/Ò/Ð0@ÐBUÑVÔV×YÒYÐZ`ÑaÔa€OàØØð Ñ ØÐ# Ð'BÀiÑF[àð 	Ø ×9Ò9Ý'1Ð2CÅTÑ'JÔ'JÐa˜t˜tÐPað :ñ ô ˆDˆDð ˆDÝ"&¥y°Ñ'9Ô'9Ð@]ÕehÐipÑeqÔeqÐ"rÑ"rÔ"rð 
	&ð 
	&ÑˆC�Ø˜C”LˆEØ!IÐ!IÐ!IÐ!I¸=Ð!IÑ!IÔ!IÐÝ Ð!3Ñ4Ô4ˆNØ'×/Ò/Ý•S˜%˜ >Ñ1Ð3EÑFÔFÑGÔGØ%Ø"&Øð	 0ñ ô ÷
 Šb�‰jŒjð ð &ˆF�3‰KˆKØ'×/Ò/Ý•�[ )Ñ,Ô,Ñ-Ô-Ø!Ø"Øð	 0ñ 
ô 
÷
 Š"ˆV‰*Œ*ð 	ð ð 	8Ø×1Ò1°$Ñ7Ô7Ð7õ
 # 5™\œ\˜M€Fˆ7�bŠ=Ñàð .åœØ_Ð_Ð_Ð_Ð_ÍeÐT]ÑN^ÔN^Ð_Ñ_Ô_ñ
ô 
ˆõ "' u¡¤ ˆˆ}Ñà—\’\‘^”^€Nð Ð" oÑ&Aõ $œk¨)¸OÔ<RÐZiÔZoÐpÑpÔpÐØÐÝ˜9Ñ%Ô%ð 	5ð 	5ˆEÝ).¬ØÐ 2Ð5GÈ+ÐV[ÔJ\Ñ5\Ð \Ô]ñ*ô *Ð Ñ&ð  +¨eÔ"4Ñ4ÐÐàÐ&Ø$ Ñ6Ð9L×9SÒ9SÐTZ×T_ÒT_Ð`aÑTbÔTbÐdeÑ9fÔ9fÔ9hÒhˆOÝ',¨U¡|¤| mˆF�?Ñ#à)×-Ò-Ñ/Ô/×4Ò4Ñ6Ô6ˆKØð .Ø>IÐT_ÐbpÑTpÐ2qÐ2q�Ð.Ñ/Ø +Ñ-�àÐ&ð "5Ð7J×7NÒ7NÑ7PÔ7PÐSbÑ7bÑ!bÐØ$Ð'9×'@Ò'@ÀÇÂÈQÁÄÐQRÑ'SÔ'SÔ'UÒUˆOÝ',¨U¡|¤| mˆF�?Ñ#à)×-Ò-Ñ/Ô/×4Ò4Ñ6Ô6ˆKØð .Ø>IÐT_ÐbpÑTpÐ2qÐ2q�Ð.Ñ/Ø +Ñ-�ð ÐØ  9Ò,ˆÝ#(¨¡<¤< -ˆˆÑà%×)Ò)Ñ+Ô+×0Ò0Ñ2Ô2ˆØð 	à&Ø$ ~Ñ5ð)ð )ˆL˜Ñ%ð ÐØ  9Ò,ˆÝ#(¨¡<¤< -ˆˆÑà%×)Ò)Ñ+Ô+×0Ò0Ñ2Ô2ˆØð 	à&Ø$ ~Ñ5ð)ð )ˆL˜Ñ%õ &+¤Z°¸)ÈÐ%KÑ%KÔ%KÑ"€O�]Ø�i Ð.Ô/€Gàð 9Ø˜!˜!˜!˜Y˜Z˜Z˜-Ô(ˆØ)¨!¨!¨!¨Y¨Z¨Z¨-Ô8ˆð ˜EÒ!Ð!Ø˜!˜!˜!˜^˜m˜^Ð+Ô,ˆØ)¨!¨!¨!¨^¨m¨^Ð*;Ô<ˆˆà	˜hÒ	&Ð	&à—l’l 1‘o”o¨×(=Ò(=Ñ(?Ô(?×(CÒ(CÀAÑ(FÔ(FÑFˆØ!×'Ò'¨MÐ'Ñ:Ô:ˆàaÐaÐaÐaÐU`ÐaÑaÔaˆØ˜) [Ð0Ô1ˆØ)¨)°[Ð*@ÔAˆà)8×)=Ò)=À!ÐPTÐ)=Ñ)UÔ)UÑ&ˆ˜Ø˜) ]Ð2Ô3ˆàð AÝÐ?Ñ@Ô@Ð@à˜	Ò!Ñ!å”)ÐbÐbÐbÐbÐbÕQVÐW`ÑQaÔQaÐbÑbÔbÑcÔcˆÝœ)Ð$rÐ$rÐ$rÐ$rÐ$rÕafÐgpÑaqÔaqÐ$rÑ$rÔ$rÑsÔsˆð *­e°E©l¬l¨]Ò:ˆÝÔ)¨'Ñ2Ô2ˆÝÔ& wÑ/Ô/ˆà˜/Ô*ˆØ)¨/Ô:ˆð ˆ	Ý˜9Ñ%Ô%ð 	,ð 	,ˆEÝINÌÐV[ÑI\ÔI\×IcÒIcØ˜EÔ" MñJô JˆN˜9 y°;¸uÔ3EÑ'EÐEÑFð ! Ô'×.Ò.¨}¸aÑ@Ô@ÔBð ˜	 I°¸EÔ0BÑ$BÐBÑCð ˜ UÔ+Ñ+ˆIˆIà'¨Ô8ˆØ& Ô7Ðð #2×"8Ò"8¸ÈÑ"JÔ"JÔ"LÈ_Ô"]Ðð  Ø  "Ø˜ð
ˆð ð 	(à%'ˆL˜Ñ"åLOØÐ,¨gÐ7NÐP_ñM
ô M
ð 	Tð 	TÑHˆJ˜ l°I¸yð Ð+Ô,×3Ò3°G¸JÔ4GÑHÔHÐHØÐ-Ô.×5Ò5°f¸\Ô6JÑKÔKÐKØ˜Ô$×+Ò+¨F°<Ô,@ÑAÔAÐAØð TØ˜XÔ&×-Ò-¨y¯~ª~Ñ/?Ô/?ÀÇÂÑAQÔAQÐ.RÑSÔSÐSøØ3°oÑEÐØ#2×#8Ò#8Ñ#:Ô#:Ð Ñ à	˜.Ò	(Ñ	(ð  Ø  "ð
ˆð ð 	'Ø$&ˆL˜Ñ!Ð!à$&ˆL˜Ñ!àÐÝ˜yÑ)Ô)ð 	4ñ 	4ˆIØ 0°Ô ;ð (ð (�ØÐ/Ô0×7Ò7¸À	Ô8JÑKÔKÐKØÐ1Ô2×9Ò9¸&ÀÔ:NÑOÔOÐOØ ð 4Ø /Ð0BÔ C× HÒ HÑ JÔ J�IØ  Ô)×0Ò0°Ñ;Ô;Ð;Ð;à  Ô)×0Ò0°Ñ3Ô3Ð3Ø" aÑ'Ð"Ð"å03°G¸IÔ4FÈÐXaÔHbÑ0cÔ0cð 4ð 4Ñ,�˜nØ!¥e¨E¡l¤l ]Ò2Ð2ØØÐ/Ô0×7Ò7¸À	Ô8JÑKÔKÐKØÐ1Ô2×9Ò9¸&ÀÔ:NÑOÔOÐOØ ð 4Ø  Ô)×0Ò0°×1DÒ1DÑ1FÔ1FÑGÔGÐGÐGà  Ô)×0Ò0°Ñ3Ô3Ð3Ð3ñ4õ  œ)Ð$rÐ$rÐ$rÐ$rÐ$rÕafÐgpÑaqÔaqÐ$rÑ$rÔ$rÑsÔsˆØ)­e°E©l¬l¨]Ò:ˆØ)¨/Ô:ˆØ+×2Ò2°=À!ÑDÔDÔFÀÔWÐZiÑiÐØ#,¨}Ñ#<½sÀ7¹|¼|Ñ#KÐ Ñ à	˜)Ò	#Ñ	#å”)ÐbÐbÐbÐbÐbÕQVÐW`ÑQaÔQaÐbÑbÔbÑcÔcˆÝœ)Ð$rÐ$rÐ$rÐ$rÐ$rÕafÐgpÑaqÔaqÐ$rÑ$rÔ$rÑsÔsˆð +­u°U©|¬|¨mÒ;×@Ò@ÀQÐ@ÑGÔGˆØ)¨/Ô:ˆØ˜/Ô*ˆð Ð fÐ fÐ fÐ fÅ9È_ÑC]ÔC]Ð fÑ fÔ fØ Ð"fÐ"fÐ"fÐ"fÅ9È_ÑC]ÔC]Ð"fÑ"fÔ"fð
ðð ð ð å&/°´	ÀÐ&CÑ&CÔ&Cðñ ô ð
ˆð ð 	å%*¤YØ  Ô1×;Ò;¸BÑ?Ô?ÀÐQÐWXð&ñ &ô &çŠf‰hŒhð ˜Ñ"ð *×1Ò1Ñ3Ô3ˆØ+×2Ò2°=À!ÑDÔDÔFÀÔW×_Ò_ÑaÔaÐdsÑsÐØ#2×#7Ò#7¸Ñ#:Ô#:Ð Ñ à	˜.Ò	(Ñ	(å”)ÐbÐbÐbÐbÐbÕQVÐW`ÑQaÔQaÐbÑbÔbÑcÔcˆÝœ)Ð$rÐ$rÐ$rÐ$rÐ$rÕafÐgpÑaqÔaqÐ$rÑ$rÔ$rÑsÔsˆà)­e°E©l¬l¨]Ò:ˆð Ð tÐ tÐ tÐ tÅyÐQ`ÑGaÔGaÐ tÑ tÔ tØ ð #ð #ð #ð #ð #å4=½cÀ/ÐSZÑ>[Ô>[Ñ4\Ô4\ð#ñ #ô #ð
ˆð ð 	sð&ð &ð &ð &ð &å%.¨Ñ%?Ô%?ð&ñ &ô &ˆL˜Ñ"Ð"ð &sÐ%rÐP_Ð%rÑ%rÔ%rˆL˜Ñ"à)¨/Ô:ˆØ+×2Ò2°=À!ÑDÔDÔFÀÔWÐZiÑiÐØ#2×#7Ò#7¸Ñ#:Ô#:Ð à&�WÔ& |Ñ4Ô4€Nð ñ ?Ø1ˆ
ØlÐlˆ	Ýˆj×Ò ¨*°jÀ,ÑOÔOÑPÔPÐPÝØ×ÒØØ�	�#˜oÑ.Ô.Ñ/Ô/Ø�	�#˜oÑ.Ô.Ñ/Ô/Øñ	ô ñ	
ô 	
ð 	
ð •U”ZÐ Ø•u”|Ð$Ø•E”IÐØÐ\Ð\Ð]ØÐqÐqÐrØÐpÐpÐqØÐqÐqÐrØÐ]Ð]Ð^ð	!
ð 	ð 	ÑˆF�Hõ Ø×!Ò!Ø×%Ò%Ñ'Ô'Ø�I˜h˜h Ñ7Ô7Ñ8Ô8Ø�I˜h˜h Ñ7Ô7Ñ8Ô8Ø�I˜h˜hÐ'8Ñ9Ô9Ñ:Ô:ñ	ô ñô ð ð ð  Ð0Ø Ð0Ø˜)Ð$Ø˜)Ð$ð	(
ð 	ð 	Ñ#ˆJ˜ð ˜\Ð)Ð)Ø& zÔ2°9Ô=�Ø$ ZÔ0°Ô9�ÝØv˜wÐvÐvÐvÀÐvÐvÐvÐXbÐvÐvÐhsÐvÐvÐvñô ð øð 3µS¸Ñ5HÔ5HÑHˆØ˜QÒÐØ$˜ˆIØ˜1Š}ˆ}Ø× Ò  Ñ-Ô-Ð-ØÐ*Ø× Ò Ð!2Ñ3Ô3Ð3ØÐ*Ø× Ò Ð!2Ñ3Ô3Ð3ØÐ$Ø× Ò  Ñ-Ô-Ð-Ý�9‰~Œ~ Ò!Ð!Ø!%§¢¨9°S°b°S¬>Ñ!:Ô!:¸WÑ!DÀyÐQSÄ}Ñ!T��à!*¨1¤�Ø$3Ð6NÑ$NÐ!ÝðU°ð Uð UÐRgÐoð Uð UØ+9ðUð UÝLOÐPYÉNÌNÐ]^ÒL^ÐL^ÀSÀSÐdfðUð Uð Uñô ð ð
 Ðs*   Á&A+ Á+
B
Á5BÂB
Þ9^= Þ=
_
ß	_
)NNNNr   NNNNNr   r   NNNNFr   Fr   r   FFTNNN)<r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r!   r#   r!   r$   r!   r%   r   r&   r'   r(   r   r)   r   r*   r   r+   r   r,   r-   r.   r/   r0   r-   r1   r   r2   r   r3   r-   r4   r5   r6   r-   r7   r   r8   r9   r:   r!   r;   r   )Ú
__future__r   rê   Úloggingræ   r€   Útypingr   r   Únumpyrå   ro   r   r   Útqdm.autonotebookÚenvironmentr	   Ú	getLoggerÚ__name__rÕ   rÓ   r   Ú)sentence_transformers.cross_encoder.modelr   Ú0sentence_transformers.sentence_transformer.modelr   r_  rF   rG   rH   ú<module>rj     sl  ðØ "Ð "Ð "Ð "Ð "Ð "à €€€Ø €€€Ø 	€	€	€	Ø €€€Ø )Ð )Ð )Ð )Ð )Ð )Ð )Ð )à Ð Ð Ð Ø €€€Ø Ð Ð Ð Ð Ð Ø "Ð "Ð "Ð "Ð "Ð "à .Ð .Ð .Ð .Ð .Ð .à	ˆÔ	˜8Ñ	$Ô	$€àð UØ Ð Ð Ð Ð Ð àFÐFÐFÐFÐFÐFØTÐTÐTÐTÐTÐTð &*Ø'+Ø#Ø)-ØØ Ø"Ø"Ø$(Ø$(ØØ27Ø$(Ø#Ø%)Ø $Ø#ØS\ØØØ!ØØ*/ØØ#Ø#Øð;Oð Oð Oð Oð Oð Oð OrG   