docstr: A CrossEncoder takes exactly two sentences / texts as input and either predicts
  a score or label for this sentence pair. It can for example predict the similarity of the sentence pair
  on a scale of 0 ... 1.
  
  It does not yield a sentence embedding and does not work for individually sentences.
  
  :param model_name: A model name from Hugging Face Hub that can be loaded with AutoModel, or a path to a local
      model. We provide several pre-trained CrossEncoder models that can be used for common tasks.
  :param num_labels: Number of labels of the classifier. If 1, the CrossEncoder is a regression model that
      outputs a continuous score 0...1. If > 1, it output several scores that can be soft-maxed to get
      probability scores for the different classes.
  :param max_length: Max length for input sequences. Longer sequences will be truncated. If None, max
      length of the model will be used
  :param device: Device that should be used for the model. If None, it will use CUDA if available.
  :param tokenizer_args: Arguments passed to AutoTokenizer
  :param automodel_args: Arguments passed to AutoModelForSequenceClassification
  :param default_activation_function: Callable (like nn.Sigmoid) about the default activation function that
      should be used on-top of model.predict(). If None. nn.Sigmoid() will be used if num_labels=1,
      else nn.Identity()
  :param classifier_dropout: The dropout ratio for the classification head.
docstr_tok: ["A","CrossEncoder","takes","exactly","two","sentences","\/","texts","as","input","and","either","predicts","a","score","or","label","for","this","sentence","pair",".","It","can","for","example","predict","the","similarity","of","the","sentence","pair","on","a","scale","of","0","...","1",".","It","does","not","yield","a","sentence","embedding","and","does","not","work","for","individually","sentences",".",":","param","model_name",":","A","model","name","from","Hugging","Face","Hub","that","can","be","loaded","with","AutoModel",",","or","a","path","to","a","local","model",".","We","provide","several","pre-trained","CrossEncoder","models","that","can","be","used","for","common","tasks",".",":","param","num_labels",":","Number","of","labels","of","the","classifier",".","If","1",",","the","CrossEncoder","is","a","regression","model","that","outputs","a","continuous","score","0","...","1",".","If",">","1",",","it","output","several","scores","that","can","be","soft-maxed","to","get","probability","scores","for","the","different","classes",".",":","param","max_length",":","Max","length","for","input","sequences",".","Longer","sequences","will","be","truncated",".","If","None",",","max","length","of","the","model","will","be","used",":","param","device",":","Device","that","should","be","used","for","the","model",".","If","None",",","it","will","use","CUDA","if","available",".",":","param","tokenizer_args",":","Arguments","passed","to","AutoTokenizer",":","param","automodel_args",":","Arguments","passed","to","AutoModelForSequenceClassification",":","param","default_activation_function",":","Callable","(","like","nn.Sigmoid",")","about","the","default","activation","function","that","should","be","used","on-top","of","model.predict","(",")",".","If","None",".","nn.Sigmoid","(",")","will","be","used","if","num_labels=1",",","else","nn.Identity","(",")",":","param","classifier_dropout",":","The","dropout","ratio","for","the","classification","head","."]
code: def __init__(
      self,
      model_name: str,
      num_labels: int = None,
      max_length: int = None,
      device: str = None,
      tokenizer_args: Dict = {},
      automodel_args: Dict = {},
      default_activation_function=None,
      classifier_dropout: float = None,
  ):
      """
      A CrossEncoder takes exactly two sentences / texts as input and either predicts
      a score or label for this sentence pair. It can for example predict the similarity of the sentence pair
      on a scale of 0 ... 1.
  
      It does not yield a sentence embedding and does not work for individually sentences.
  
      :param model_name: A model name from Hugging Face Hub that can be loaded with AutoModel, or a path to a local
          model. We provide several pre-trained CrossEncoder models that can be used for common tasks.
      :param num_labels: Number of labels of the classifier. If 1, the CrossEncoder is a regression model that
          outputs a continuous score 0...1. If > 1, it output several scores that can be soft-maxed to get
          probability scores for the different classes.
      :param max_length: Max length for input sequences. Longer sequences will be truncated. If None, max
          length of the model will be used
      :param device: Device that should be used for the model. If None, it will use CUDA if available.
      :param tokenizer_args: Arguments passed to AutoTokenizer
      :param automodel_args: Arguments passed to AutoModelForSequenceClassification
      :param default_activation_function: Callable (like nn.Sigmoid) about the default activation function that
          should be used on-top of model.predict(). If None. nn.Sigmoid() will be used if num_labels=1,
          else nn.Identity()
      :param classifier_dropout: The dropout ratio for the classification head.
      """
  
      self.config = AutoConfig.from_pretrained(model_name)
      classifier_trained = True
      if self.config.architectures is not None:
          classifier_trained = any(
              [
                  arch.endswith("ForSequenceClassification")
                  for arch in self.config.architectures
              ]
          )
  
      if classifier_dropout is not None:
          self.config.classifier_dropout = classifier_dropout
  
      if num_labels is None and not classifier_trained:
          num_labels = 1
  
      if num_labels is not None:
          self.config.num_labels = num_labels
  
      self.model = AutoModelForSequenceClassification.from_pretrained(
          model_name, config=self.config, **automodel_args
      )
      self.tokenizer = AutoTokenizer.from_pretrained(
          model_name, **tokenizer_args
      )
      self.max_length = max_length
  
      if device is None:
          device = "cuda" if torch.cuda.is_available() else "cpu"
          logger.info("Use pytorch device: {}".format(device))
  
      self._target_device = torch.device(device)
  
      if default_activation_function is not None:
          self.default_activation_function = default_activation_function
          try:
              self.config.sbert_ce_default_activation_function = (
                  util.fullname(self.default_activation_function)
              )
          except Exception as e:
              logger.warning(
                  "Was not able to update config about the default_activation_function: {}".format(
                      str(e)
                  )
              )
      elif (
          hasattr(self.config, "sbert_ce_default_activation_function")
          and self.config.sbert_ce_default_activation_function
          is not None
      ):
          self.default_activation_function = util.import_from_string(
              self.config.sbert_ce_default_activation_function
          )()
      else:
          self.default_activation_function = (
              nn.Sigmoid()
              if self.config.num_labels == 1
              else nn.Identity()
          )
  
imports: from transformers import AutoModelForSequenceClassification, AutoTokenizer, AutoConfig
  import numpy
  import logging
  import os
  from typing import Dict, Type, Callable, List
  import torch
  from torch import nn
  from torch.optim import Optimizer
  from torch.utils.data import DataLoader
  from tqdm.autonotebook import tqdm, trange
  from ..None import SentenceTransformer, util
  from ..evaluation import SentenceEvaluator
label_desc: Use image node_id 1 to create a new CrossEncoder object  with example: obj = CrossEncoder(model_name, num_labels, max_length, device, tokenizer_args, automodel_args, default_activation_function, classifier_dropout)