class_docstr: Base class for the weak label classes.
  
  Tries to facilitate the implementations, avoids code duplications.
  
  Args:
      dataset: Name of the dataset to which the rules will be applied.
      rules: A list of rules (labeling functions). They must return a string, or ``None`` in case of abstention.
          If None, we will use the rules of the dataset (Default).
      ids: An optional list of record ids to filter the dataset before applying the rules.
      query: An optional ElasticSearch query with the
          `query string syntax <https://docs.argilla.io/en/latest/practical_guides/filter_dataset.html>`_
          to filter the dataset before applying the rules.
  
  Raises:
      NoRulesFoundError: When you do not provide rules, and the dataset has no rules either.
      DuplicatedRuleNameError: When you provided multiple rules with the same name.
      NoRecordsFoundError: When the filtered dataset is empty.
class_docstr_tok: ["Base","class","for","the","weak","label","classes",".","Tries","to","facilitate","the","implementations",",","avoids","code","duplications",".","Args",":","dataset",":","Name","of","the","dataset","to","which","the","rules","will","be","applied",".","rules",":","A","list","of","rules","(","labeling","functions",")",".","They","must","return","a","string",",","or","``","None","``","in","case","of","abstention",".","If","None",",","we","will","use","the","rules","of","the","dataset","(","Default",")",".","ids",":","An","optional","list","of","record","ids","to","filter","the","dataset","before","applying","the","rules",".","query",":","An","optional","ElasticSearch","query","with","the","`","query","string","syntax","<","https",":","\/\/docs.argilla.io\/en\/latest\/practical_guides\/filter_dataset.html",">","`","_","to","filter","the","dataset","before","applying","the","rules",".","Raises",":","NoRulesFoundError",":","When","you","do","not","provide","rules",",","and","the","dataset","has","no","rules","either",".","DuplicatedRuleNameError",":","When","you","provided","multiple","rules","with","the","same","name",".","NoRecordsFoundError",":","When","the","filtered","dataset","is","empty","."]
docstr: Helper method to extend the weak labels.
docstr_tok: ["Helper","method","to","extend","the","weak","labels","."]
code: def _find_dists_and_nearest(
      self,
      embeddings: np.ndarray,
      abstains: List[np.ndarray],
      support: List[np.ndarray],
      gpu: bool,
  ) -> Tuple[List[np.ndarray], List[np.ndarray]]:
      """Helper method to extend the weak labels."""
      try:
          import faiss
      except ModuleNotFoundError:
          raise ModuleNotFoundError(
              "'faiss' must be installed to extend a weak label matrix! "
              "You can install 'faiss' with the commands: `pip install faiss-cpu` or `pip install faiss-gpu`"
          )
      faiss.normalize_L2(embeddings)
      embeddings_length = embeddings.shape[1]
  
      label_fn_indexes = [
          faiss.IndexFlatIP(embeddings_length)
          for i in range(self._matrix.shape[1])
      ]
  
      if gpu:
          res = faiss.StandardGpuResources()
          label_fn_indexes = [
              faiss.index_cpu_to_gpu(res, 0, x)
              for x in label_fn_indexes
          ]
  
      for i in range(self._matrix.shape[1]):
          label_fn_indexes[i].add(embeddings[support[i]])
  
      dists_and_nearest = []
      for i in tqdm(
          range(self._matrix.shape[1]), total=self._matrix.shape[1]
      ):
          embs_query = np.copy(embeddings[abstains[i]])
          faiss.normalize_L2(embs_query)
          dists_and_nearest.append(
              label_fn_indexes[i].search(embs_query, 1)
          )
  
      dists = [
          dist_and_nearest[0].flatten()
          for dist_and_nearest in dists_and_nearest
      ]
      nearest = [
          dist_and_nearest[1].flatten()
          for dist_and_nearest in dists_and_nearest
      ]
  
      return dists, nearest
  
imports: import warnings
  from collections import Counter
  from typing import Callable, Dict, List, Optional, Tuple, Union
  import numpy
  import pandas
  from tqdm.auto import tqdm
  from argilla import load
  from argilla.client.datasets import DatasetForTextClassification
  from argilla.client.models import TextClassificationRecord
  from argilla.labeling.text_classification.rule import Rule, load_rules
label_desc: Use image node_id 12 for calling the WeakLabelsBase obj's underlying member method code with example usage: obj._find_dists_and_nearest(embeddings, abstains, support, gpu) and returns: dists,  nearest