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: Extends the weak label matrix through embeddings according to the similarity thresholds for each rule.
  
  Implementation based on `Epoxy <https://github.com/HazyResearch/epoxy>`__.
  
  Args:
      thresholds: An array of thresholds between 0.0 and 1.0, one for each column of the weak labels matrix.
          Each one stands for the minimum cosine similarity between two sentences for a rule to be extended.
      embeddings: Embeddings for each row of the weak label matrix.
          If not provided, we will use the ones from the last ``WeakLabels.extend_matrix()`` call.
      gpu: If True, perform FAISS similarity queries on GPU.
  
  Examples:
      >>> # Choose any model to generate the embeddings.
      >>> from sentence_transformers import SentenceTransformer
      >>> model = SentenceTransformer('all-mpnet-base-v2', device='cuda')
      >>>
      >>> # Generate the embeddings and set the thresholds.
      >>> weak_labels = {class_name}(dataset="my_dataset")
      >>> embeddings = np.array([ model.encode(rec.text) for rec in weak_labels.records() ])
      >>> thresholds = [0.6] * len(weak_labels.rules)
      >>>
      >>> # Extend the weak labels matrix.
      >>> weak_labels.extend_matrix(thresholds, embeddings)
      >>>
      >>> # Calling the method below will now retrieve the extended matrix.
      >>> weak_labels.matrix()
      >>>
      >>> # Subsequent calls without the embeddings parameter will reutilize the faiss index built on the first call.
      >>> thresholds = [0.75] * len(weak_labels.rules)
      >>> weak_labels.extend_matrix(thresholds)
      >>> weak_labels.matrix()
docstr_tok: ["Extends","the","weak","label","matrix","through","embeddings","according","to","the","similarity","thresholds","for","each","rule",".","Implementation","based","on","`","Epoxy","<","https",":","\/\/github.com\/HazyResearch\/epoxy",">","`","__",".","Args",":","thresholds",":","An","array","of","thresholds","between","0.0","and","1.0",",","one","for","each","column","of","the","weak","labels","matrix",".","Each","one","stands","for","the","minimum","cosine","similarity","between","two","sentences","for","a","rule","to","be","extended",".","embeddings",":","Embeddings","for","each","row","of","the","weak","label","matrix",".","If","not","provided",",","we","will","use","the","ones","from","the","last","``","WeakLabels.extend_matrix","(",")","``","call",".","gpu",":","If","True",",","perform","FAISS","similarity","queries","on","GPU",".","Examples",":",">",">",">","#","Choose","any","model","to","generate","the","embeddings",".",">",">",">","from","sentence_transformers","import","SentenceTransformer",">",">",">","model","=","SentenceTransformer","(","'all-mpnet-base-v2","'",",","device='cuda","'",")",">",">",">",">",">",">","#","Generate","the","embeddings","and","set","the","thresholds",".",">",">",">","weak_labels","=","{","class_name","}","(","dataset=","''","my_dataset","''",")",">",">",">","embeddings","=","np.array","(","[","model.encode","(","rec.text",")","for","rec","in","weak_labels.records","(",")","]",")",">",">",">","thresholds","=","[","0.6","]","*","len","(","weak_labels.rules",")",">",">",">",">",">",">","#","Extend","the","weak","labels","matrix",".",">",">",">","weak_labels.extend_matrix","(","thresholds",",","embeddings",")",">",">",">",">",">",">","#","Calling","the","method","below","will","now","retrieve","the","extended","matrix",".",">",">",">","weak_labels.matrix","(",")",">",">",">",">",">",">","#","Subsequent","calls","without","the","embeddings","parameter","will","reutilize","the","faiss","index","built","on","the","first","call",".",">",">",">","thresholds","=","[","0.75","]","*","len","(","weak_labels.rules",")",">",">",">","weak_labels.extend_matrix","(","thresholds",")",">",">",">","weak_labels.matrix","(",")"]
code: def extend_matrix(
      self,
      thresholds: Union[List[float], np.ndarray],
      embeddings: Optional[np.ndarray] = None,
      gpu: bool = False,
  ):
      """Extends the weak label matrix through embeddings according to the similarity thresholds for each rule.
  
      Implementation based on `Epoxy <https://github.com/HazyResearch/epoxy>`__.
  
      Args:
          thresholds: An array of thresholds between 0.0 and 1.0, one for each column of the weak labels matrix.
              Each one stands for the minimum cosine similarity between two sentences for a rule to be extended.
          embeddings: Embeddings for each row of the weak label matrix.
              If not provided, we will use the ones from the last ``WeakLabels.extend_matrix()`` call.
          gpu: If True, perform FAISS similarity queries on GPU.
  
      Examples:
          >>> # Choose any model to generate the embeddings.
          >>> from sentence_transformers import SentenceTransformer
          >>> model = SentenceTransformer('all-mpnet-base-v2', device='cuda')
          >>>
          >>> # Generate the embeddings and set the thresholds.
          >>> weak_labels = {class_name}(dataset="my_dataset")
          >>> embeddings = np.array([ model.encode(rec.text) for rec in weak_labels.records() ])
          >>> thresholds = [0.6] * len(weak_labels.rules)
          >>>
          >>> # Extend the weak labels matrix.
          >>> weak_labels.extend_matrix(thresholds, embeddings)
          >>>
          >>> # Calling the method below will now retrieve the extended matrix.
          >>> weak_labels.matrix()
          >>>
          >>> # Subsequent calls without the embeddings parameter will reutilize the faiss index built on the first call.
          >>> thresholds = [0.75] * len(weak_labels.rules)
          >>> weak_labels.extend_matrix(thresholds)
          >>> weak_labels.matrix()
      """
      abstains, supports = self._extend_matrix_preprocess()
  
      if embeddings is not None:
          self._extension_queries = self._find_dists_and_nearest(
              np.copy(embeddings).astype(np.float32),
              abstains,
              supports,
              gpu=gpu,
          )
      elif self._extension_queries is None:
          raise ValueError(
              "Embeddings are not optional the first time a matrix is extended."
          )
      dists, nearest = self._extension_queries
  
      self._extended_matrix = np.copy(self._matrix)
      new_points = [
          (dists[i] > thresholds[i])
          for i in range(self._matrix.shape[1])
      ]
      for i in range(self._matrix.shape[1]):
          self._extended_matrix[
              abstains[i][new_points[i]], i
          ] = self._matrix[supports[i], i][nearest[i][new_points[i]]]
  
      self._extend_matrix_postprocess()
  
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 11 for calling the WeakLabelsBase obj's underlying member method code with example usage: obj.extend_matrix(thresholds, embeddings, gpu) without return types