class_docstr: The label model by `FlyingSquid <https://github.com/HazyResearch/flyingsquid>`__.
  
  .. note:: It is not suited for multi-label classification and does not support it!
  
  Args:
      weak_labels: A `WeakLabels` object containing the weak labels and records.
      **kwargs: Passed on to the init of the FlyingSquid's
          `LabelModel <https://github.com/HazyResearch/flyingsquid/blob/master/flyingsquid/label_model.py#L18>`__.
  
  Examples:
      >>> from argilla.labeling.text_classification import WeakLabels
      >>> weak_labels = WeakLabels(dataset="my_dataset")
      >>> label_model = FlyingSquid(weak_labels)
      >>> label_model.fit()
      >>> records = label_model.predict()
class_docstr_tok: ["The","label","model","by","`","FlyingSquid","<","https",":","\/\/github.com\/HazyResearch\/flyingsquid",">","`","__",".","..","note",":",":","It","is","not","suited","for","multi-label","classification","and","does","not","support","it","!","Args",":","weak_labels",":","A","`","WeakLabels","`","object","containing","the","weak","labels","and","records",".","*","*","kwargs",":","Passed","on","to","the","init","of","the","FlyingSquid's","`","LabelModel","<","https",":","\/\/github.com\/HazyResearch\/flyingsquid\/blob\/master\/flyingsquid\/label_model.py","#","L18",">","`","__",".","Examples",":",">",">",">","from","argilla.labeling.text_classification","import","WeakLabels",">",">",">","weak_labels","=","WeakLabels","(","dataset=","''","my_dataset","''",")",">",">",">","label_model","=","FlyingSquid","(","weak_labels",")",">",">",">","label_model.fit","(",")",">",">",">","records","=","label_model.predict","(",")"]
docstr: Applies the label model.
  
  Args:
      include_annotated_records: Whether to include annotated records.
      include_abstentions: Whether to include records in the output, for which the label model abstained.
      prediction_agent: String used for the ``prediction_agent`` in the returned records.
      verbose: If True, print out messages of the progress to stderr.
      tie_break_policy: Policy to break ties. You can choose among two policies:
  
          - `abstain`: Do not provide any prediction
          - `random`: randomly choose among tied option using deterministic hash
  
          The last policy can introduce quite a bit of noise, especially when the tie is among many labels,
          as is the case when all the labeling functions (rules) abstained.
  
  Returns:
      A dataset of records that include the predictions of the label model.
  
  Raises:
      NotFittedError: If the label model was still not fitted.
docstr_tok: ["Applies","the","label","model",".","Args",":","include_annotated_records",":","Whether","to","include","annotated","records",".","include_abstentions",":","Whether","to","include","records","in","the","output",",","for","which","the","label","model","abstained",".","prediction_agent",":","String","used","for","the","``","prediction_agent","``","in","the","returned","records",".","verbose",":","If","True",",","print","out","messages","of","the","progress","to","stderr",".","tie_break_policy",":","Policy","to","break","ties",".","You","can","choose","among","two","policies",":","-","`","abstain","`",":","Do","not","provide","any","prediction","-","`","random","`",":","randomly","choose","among","tied","option","using","deterministic","hash","The","last","policy","can","introduce","quite","a","bit","of","noise",",","especially","when","the","tie","is","among","many","labels",",","as","is","the","case","when","all","the","labeling","functions","(","rules",")","abstained",".","Returns",":","A","dataset","of","records","that","include","the","predictions","of","the","label","model",".","Raises",":","NotFittedError",":","If","the","label","model","was","still","not","fitted","."]
code: def predict(
      self,
      include_annotated_records: bool = False,
      include_abstentions: bool = False,
      prediction_agent: str = "FlyingSquid",
      verbose: bool = True,
      tie_break_policy: Union[TieBreakPolicy, str] = "abstain",
  ) -> DatasetForTextClassification:
      """Applies the label model.
  
      Args:
          include_annotated_records: Whether to include annotated records.
          include_abstentions: Whether to include records in the output, for which the label model abstained.
          prediction_agent: String used for the ``prediction_agent`` in the returned records.
          verbose: If True, print out messages of the progress to stderr.
          tie_break_policy: Policy to break ties. You can choose among two policies:
  
              - `abstain`: Do not provide any prediction
              - `random`: randomly choose among tied option using deterministic hash
  
              The last policy can introduce quite a bit of noise, especially when the tie is among many labels,
              as is the case when all the labeling functions (rules) abstained.
  
      Returns:
          A dataset of records that include the predictions of the label model.
  
      Raises:
          NotFittedError: If the label model was still not fitted.
      """
      if isinstance(tie_break_policy, str):
          tie_break_policy = TieBreakPolicy(tie_break_policy)
  
      wl_matrix = self._weak_labels.matrix(
          has_annotation=None if include_annotated_records else False
      )
      probabilities = self._predict(wl_matrix, verbose)
  
      # add predictions to records
      records_with_prediction = []
      for i, prob, rec in zip(
          range(len(probabilities)),
          probabilities,
          self._weak_labels.records(
              has_annotation=None
              if include_annotated_records
              else False
          ),
      ):
          # Check if model abstains, that is if the highest probability is assigned to more than one label
          # 1.e-8 is taken from the abs tolerance of np.isclose
          equal_prob_idx = np.nonzero(
              np.abs(prob.max() - prob) < 1.0e-8
          )[0]
          tie = False
          if len(equal_prob_idx) > 1:
              tie = True
  
          # maybe skip record
          if not include_abstentions and (
              tie and tie_break_policy is TieBreakPolicy.ABSTAIN
          ):
              continue
  
          if not tie:
              pred_for_rec = [
                  (self._weak_labels.labels[i], prob[i])
                  for i in np.argsort(prob)[::-1]
              ]
          # resolve ties following the tie break policy
          elif tie_break_policy is TieBreakPolicy.ABSTAIN:
              pred_for_rec = None
          elif tie_break_policy is TieBreakPolicy.RANDOM:
              random_idx = int(
                  hashlib.sha1(f"{i}".encode()).hexdigest(), 16
              ) % len(equal_prob_idx)
              for idx in equal_prob_idx:
                  if idx == random_idx:
                      prob[
                          idx
                      ] += self._PROBABILITY_INCREASE_ON_TIE_BREAK
                  else:
                      prob[
                          idx
                      ] -= self._PROBABILITY_INCREASE_ON_TIE_BREAK / (
                          len(equal_prob_idx) - 1
                      )
              pred_for_rec = [
                  (self._weak_labels.labels[i], prob[i])
                  for i in np.argsort(prob)[::-1]
              ]
          else:
              raise NotImplementedError(
                  f"The tie break policy '{tie_break_policy.value}' is not implemented for FlyingSquid!"
              )
  
          records_with_prediction.append(rec.copy(deep=True))
          records_with_prediction[-1].prediction = pred_for_rec
          records_with_prediction[
              -1
          ].prediction_agent = prediction_agent
  
      return DatasetForTextClassification(records_with_prediction)
  
imports: import hashlib
  import logging
  from enum import Enum
  from typing import Dict, List, Tuple, Union
  import numpy
  from argilla import DatasetForTextClassification, TextClassificationRecord
  from argilla.labeling.text_classification.weak_labels import WeakLabels, WeakMultiLabels
  from argilla.utils.dependency import requires_dependencies
label_desc: Use image node_id 4 for calling the FlyingSquid obj's underlying member method code with example usage: obj.predict(include_annotated_records, include_abstentions, prediction_agent, verbose, tie_break_policy) and returns: DatasetForTextClassification