class_docstr: TARS model for text classification.
  
  In the backend, the model uses a BERT based binary text classifier which given a <label, text> pair predicts the
  probability of two classes "True", and "False". The input data is a usual Sentence object which is inflated
  by the model internally before pushing it through the transformer stack of BERT.
class_docstr_tok: ["TARS","model","for","text","classification",".","In","the","backend",",","the","model","uses","a","BERT","based","binary","text","classifier","which","given","a","<","label",",","text",">","pair","predicts","the","probability","of","two","classes","``","True","''",",","and","``","False","''",".","The","input","data","is","a","usual","Sentence","object","which","is","inflated","by","the","model","internally","before","pushing","it","through","the","transformer","stack","of","BERT","."]
docstr: Initializes a TarsClassifier.
  
  Args:
      task_name: a string depicting the name of the task.
      label_dictionary: dictionary of labels you want to predict.
      label_type: label_type: name of the label
      embeddings: name of the pre-trained transformer model e.g., 'bert-base-uncased'.
      num_negative_labels_to_sample: number of negative labels to sample for each positive labels against a
          sentence during training. Defaults to 2 negative labels for each positive label.
          The model would sample all the negative labels if None is passed.
          That slows down the training considerably.
      multi_label: auto-detected by default, but you can set this to True to force multi-label predictions
          or False to force single-label predictions.
      multi_label_threshold: If multi-label you can set the threshold to make predictions.
      beta: Parameter for F-beta score for evaluation and training annealing.
      prefix: if True, the label will be concatenated at the start, else on the end.
      **tagger_args: The arguments propagated to :meth:`FewshotClassifier.__init__`
docstr_tok: ["Initializes","a","TarsClassifier",".","Args",":","task_name",":","a","string","depicting","the","name","of","the","task",".","label_dictionary",":","dictionary","of","labels","you","want","to","predict",".","label_type",":","label_type",":","name","of","the","label","embeddings",":","name","of","the","pre-trained","transformer","model","e.g.",",","'bert-base-uncased","'",".","num_negative_labels_to_sample",":","number","of","negative","labels","to","sample","for","each","positive","labels","against","a","sentence","during","training",".","Defaults","to","2","negative","labels","for","each","positive","label",".","The","model","would","sample","all","the","negative","labels","if","None","is","passed",".","That","slows","down","the","training","considerably",".","multi_label",":","auto-detected","by","default",",","but","you","can","set","this","to","True","to","force","multi-label","predictions","or","False","to","force","single-label","predictions",".","multi_label_threshold",":","If","multi-label","you","can","set","the","threshold","to","make","predictions",".","beta",":","Parameter","for","F-beta","score","for","evaluation","and","training","annealing",".","prefix",":","if","True",",","the","label","will","be","concatenated","at","the","start",",","else","on","the","end",".","*","*","tagger_args",":","The","arguments","propagated","to",":","meth",":","`","FewshotClassifier.__init__","`"]
code: def __init__(
      self,
      task_name: Optional[str] = None,
      label_dictionary: Optional[Dictionary] = None,
      label_type: Optional[str] = None,
      embeddings: Union[
          TransformerDocumentEmbeddings, str
      ] = "bert-base-uncased",
      num_negative_labels_to_sample: Optional[int] = 2,
      prefix: bool = True,
      **tagger_args,
  ) -> None:
      """Initializes a TarsClassifier.
  
      Args:
          task_name: a string depicting the name of the task.
          label_dictionary: dictionary of labels you want to predict.
          label_type: label_type: name of the label
          embeddings: name of the pre-trained transformer model e.g., 'bert-base-uncased'.
          num_negative_labels_to_sample: number of negative labels to sample for each positive labels against a
              sentence during training. Defaults to 2 negative labels for each positive label.
              The model would sample all the negative labels if None is passed.
              That slows down the training considerably.
          multi_label: auto-detected by default, but you can set this to True to force multi-label predictions
              or False to force single-label predictions.
          multi_label_threshold: If multi-label you can set the threshold to make predictions.
          beta: Parameter for F-beta score for evaluation and training annealing.
          prefix: if True, the label will be concatenated at the start, else on the end.
          **tagger_args: The arguments propagated to :meth:`FewshotClassifier.__init__`
      """
      super().__init__()
  
      if isinstance(embeddings, str):
          embeddings = TransformerDocumentEmbeddings(
              model=embeddings,
              fine_tune=True,
              layers="-1",
              layer_mean=False,
          )
  
      # prepare TARS dictionary
      tars_dictionary = Dictionary(add_unk=False)
      tars_dictionary.add_item(self.LABEL_NO_MATCH)
      tars_dictionary.add_item(self.LABEL_MATCH)
  
      # initialize a bare-bones sequence tagger
      self.tars_model = TextClassifier(
          embeddings=embeddings,
          label_dictionary=tars_dictionary,
          label_type=self.static_label_type,
          **tagger_args,
      )
  
      # transformer separator
      self.separator = str(self.tars_embeddings.tokenizer.sep_token)
      if self.tars_embeddings.tokenizer._bos_token:
          self.separator += str(
              self.tars_embeddings.tokenizer.bos_token
          )
  
      self.prefix = prefix
      self.num_negative_labels_to_sample = num_negative_labels_to_sample
  
      if task_name and label_dictionary and label_type:
          # Store task specific labels since TARS can handle multiple tasks
          self.add_and_switch_to_new_task(
              task_name, label_dictionary, label_type
          )
      else:
          log.info(
              "TARS initialized without a task. You need to call .add_and_switch_to_new_task() "
              "before training this model"
          )
  
      self.clean_up_labels = True
  
imports: import logging
  import typing
  from abc import ABC
  from collections import OrderedDict
  from pathlib import Path
  from typing import Any, Dict, List, Optional, Set, Tuple, Union
  import numpy
  import torch
  from sklearn.metrics.pairwise import cosine_similarity
  from sklearn.preprocessing import minmax_scale
  from tqdm import tqdm
  import flair
  from flair.data import Corpus, Dictionary, Sentence, Span
  from flair.datasets import DataLoader, FlairDatapointDataset
  from flair.embeddings import TokenEmbeddings, TransformerDocumentEmbeddings, TransformerWordEmbeddings
  from flair.file_utils import cached_path
  from flair.models.sequence_tagger_model import SequenceTagger
  from flair.models.text_classification_model import TextClassifier
  from flair.training_utils import store_embeddings
label_desc: Use image node_id 1 to create a new TARSClassifier object from inherited base classes: FewshotClassifier with example: obj = TARSClassifier(task_name, label_dictionary, label_type, embeddings, num_negative_labels_to_sample, prefix)