class_docstr: Computes the weak labels of a single-label text classification dataset by applying a given list of rules.
  
  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.
      label2int: An optional dict, mapping the labels to integers. Remember that the return type ``None`` means
          abstention (e.g. ``{None: -1}``). By default, we will build a mapping on the fly when 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.
      MultiLabelError: When trying to get weak labels for a multi-label text classification task.
      MissingLabelError: When provided with a ``label2int`` dict, and a
          weak label or annotation label is not present in its keys.
  
  Examples:
      >>> # Get the weak label matrix from a dataset with rules:
      >>> weak_labels = WeakLabels(dataset="my_dataset")
      >>> weak_labels.matrix()
      >>> weak_labels.summary()
      >>>
      >>> # Get the weak label matrix from rules defined in Python:
      >>> def awesome_rule(record: TextClassificationRecord) -> str:
      ...     return "Positive" if "awesome" in record.text else None
      >>> another_rule = Rule(query="good OR best", label="Positive")
      >>> weak_labels = WeakLabels(dataset="my_dataset", rules=[awesome_rule, another_rule])
      >>> weak_labels.matrix()
      >>> weak_labels.summary()
      >>>
      >>> # Use the WeakLabels object with snorkel's LabelModel:
      >>> from snorkel.labeling.model import LabelModel
      >>> label_model = LabelModel()
      >>> label_model.fit(L_train=weak_labels.matrix(has_annotation=False))
      >>> label_model.score(L=weak_labels.matrix(has_annotation=True), Y=weak_labels.annotation())
      >>> label_model.predict(L=weak_labels.matrix(has_annotation=False))
      >>>
      >>> # For a builtin integration with Snorkel, see `argilla.labeling.text_classification.Snorkel`.
class_docstr_tok: ["Computes","the","weak","labels","of","a","single-label","text","classification","dataset","by","applying","a","given","list","of","rules",".","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",".","label2int",":","An","optional","dict",",","mapping","the","labels","to","integers",".","Remember","that","the","return","type","``","None","``","means","abstention","(","e.g",".","``","{","None",":","-1","}","``",")",".","By","default",",","we","will","build","a","mapping","on","the","fly","when","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",".","MultiLabelError",":","When","trying","to","get","weak","labels","for","a","multi-label","text","classification","task",".","MissingLabelError",":","When","provided","with","a","``","label2int","``","dict",",","and","a","weak","label","or","annotation","label","is","not","present","in","its","keys",".","Examples",":",">",">",">","#","Get","the","weak","label","matrix","from","a","dataset","with","rules",":",">",">",">","weak_labels","=","WeakLabels","(","dataset=","''","my_dataset","''",")",">",">",">","weak_labels.matrix","(",")",">",">",">","weak_labels.summary","(",")",">",">",">",">",">",">","#","Get","the","weak","label","matrix","from","rules","defined","in","Python",":",">",">",">","def","awesome_rule","(","record",":","TextClassificationRecord",")","-",">","str",":","...","return","``","Positive","''","if","``","awesome","''","in","record.text","else","None",">",">",">","another_rule","=","Rule","(","query=","''","good","OR","best","''",",","label=","''","Positive","''",")",">",">",">","weak_labels","=","WeakLabels","(","dataset=","''","my_dataset","''",",","rules=","[","awesome_rule",",","another_rule","]",")",">",">",">","weak_labels.matrix","(",")",">",">",">","weak_labels.summary","(",")",">",">",">",">",">",">","#","Use","the","WeakLabels","object","with","snorkel","'s","LabelModel",":",">",">",">","from","snorkel.labeling.model","import","LabelModel",">",">",">","label_model","=","LabelModel","(",")",">",">",">","label_model.fit","(","L_train=weak_labels.matrix","(","has_annotation=False",")",")",">",">",">","label_model.score","(","L=weak_labels.matrix","(","has_annotation=True",")",",","Y=weak_labels.annotation","(",")",")",">",">",">","label_model.predict","(","L=weak_labels.matrix","(","has_annotation=False",")",")",">",">",">",">",">",">","#","For","a","builtin","integration","with","Snorkel",",","see","`","argilla.labeling.text_classification.Snorkel","`","."]
docstr: Allows you to change the mapping between labels and integers.
  
  This will update the ``self.matrix`` as well as the ``self.annotation``.
  
  Args:
      label2int: New label to integer mapping. Must cover all previous labels.
docstr_tok: ["Allows","you","to","change","the","mapping","between","labels","and","integers",".","This","will","update","the","``","self.matrix","``","as","well","as","the","``","self.annotation","``",".","Args",":","label2int",":","New","label","to","integer","mapping",".","Must","cover","all","previous","labels","."]
code: def change_mapping(self, label2int: Dict[str, int]):
      """Allows you to change the mapping between labels and integers.
  
      This will update the ``self.matrix`` as well as the ``self.annotation``.
  
      Args:
          label2int: New label to integer mapping. Must cover all previous labels.
      """
      # save masks for swapping
      label_masks = {}
      annotation_masks = {}
  
      for label in self._label2int:
          # Check new label2int mapping
          if label not in label2int:
              raise MissingLabelError(
                  f"The label '{label}' is missing in the new mapping."
              )
          # compute masks
          label_masks[label] = self.matrix() == self._label2int[label]
          annotation_masks[label] = (
              self._annotation == self._label2int[label]
          )
  
      # swap integers
      for label in self._label2int:
          self.matrix()[label_masks[label]] = label2int[label]
          self._annotation[annotation_masks[label]] = label2int[label]
  
      # update mapping dicts
      self._label2int = label2int.copy()
      self._int2label = {
          val: key for key, val in self._label2int.items()
      }
  
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 WeakLabels obj's underlying member method code with example usage: obj.change_mapping(label2int) without return types