



"""simple docstring"""






import json
import os
from functools import lru_cache
from typing import List, Optional, Tuple

import regex as re

from ...tokenization_utils import AddedToken, PreTrainedTokenizer
from ...utils import logging


snake_case   					=				logging.get_logger(__name__)


snake_case   					=				{'''vocab_file''': '''vocab.json''', '''merges_file''': '''merges.txt'''}

# See all BART models at https://huggingface.co/models?filter=bart
snake_case   					=				{
    '''vocab_file''': {
        '''facebook/bart-base''': '''https://huggingface.co/facebook/bart-base/resolve/main/vocab.json''',
        '''facebook/bart-large''': '''https://huggingface.co/facebook/bart-large/resolve/main/vocab.json''',
        '''facebook/bart-large-mnli''': '''https://huggingface.co/facebook/bart-large-mnli/resolve/main/vocab.json''',
        '''facebook/bart-large-cnn''': '''https://huggingface.co/facebook/bart-large-cnn/resolve/main/vocab.json''',
        '''facebook/bart-large-xsum''': '''https://huggingface.co/facebook/bart-large-xsum/resolve/main/vocab.json''',
        '''yjernite/bart_eli5''': '''https://huggingface.co/yjernite/bart_eli5/resolve/main/vocab.json''',
    },
    '''merges_file''': {
        '''facebook/bart-base''': '''https://huggingface.co/facebook/bart-base/resolve/main/merges.txt''',
        '''facebook/bart-large''': '''https://huggingface.co/facebook/bart-large/resolve/main/merges.txt''',
        '''facebook/bart-large-mnli''': '''https://huggingface.co/facebook/bart-large-mnli/resolve/main/merges.txt''',
        '''facebook/bart-large-cnn''': '''https://huggingface.co/facebook/bart-large-cnn/resolve/main/merges.txt''',
        '''facebook/bart-large-xsum''': '''https://huggingface.co/facebook/bart-large-xsum/resolve/main/merges.txt''',
        '''yjernite/bart_eli5''': '''https://huggingface.co/yjernite/bart_eli5/resolve/main/merges.txt''',
    },
}

snake_case   					=				{
    '''facebook/bart-base''': 1_0_2_4,
    '''facebook/bart-large''': 1_0_2_4,
    '''facebook/bart-large-mnli''': 1_0_2_4,
    '''facebook/bart-large-cnn''': 1_0_2_4,
    '''facebook/bart-large-xsum''': 1_0_2_4,
    '''yjernite/bart_eli5''': 1_0_2_4,
}




@lru_cache()
def 			snake_case		(		)						->				List[Any]:
  _snake_case   	=      (
      list(range(ord('''!'''	)  ,						ord('''~'''	) + 1	)	) + list(range(ord('''¡'''	)  ,						ord('''¬'''	) + 1	)	) + list(range(ord('''®'''	)  ,						ord('''ÿ'''	) + 1	)	)
  )
  _snake_case   	=      bs[:]
  _snake_case   	=      0
  for b in range(2**8	):
    if b not in bs:
      bs.append(lowerCAmelCase_	)
      cs.append(2**8 + n	)
      n += 1
  _snake_case   	=      [chr(lowerCAmelCase_	) for n in cs]
  return dict(zip(lowerCAmelCase_  ,						lowerCAmelCase_	)	)




def 			snake_case		(		lowerCAmelCase_	)						->				int:
  _snake_case   	=      set()
  _snake_case   	=      word[0]
  for char in word[1:]:
    pairs.add((prev_char, char)	)
    _snake_case   	=      char
  return pairs







class     UpperCAmelCase    (	__SCREAMING_SNAKE_CASE  ):
   A__		:	Optional[Any]           =  VOCAB_FILES_NAMES
   A__		:	Any           =  PRETRAINED_VOCAB_FILES_MAP
   A__		:	Optional[int]           =  PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
   A__		:	str           =  ['''input_ids''', '''attention_mask''']



   def __init__(       self    :	List[Any]							,       __lowerCamelCase    :	Optional[int]							,       __lowerCamelCase    :	Dict							,       __lowerCamelCase    :	Optional[Any]="replace"							,       __lowerCamelCase    :	Optional[Any]="<s>"							,       __lowerCamelCase    :	Union[str, Any]="</s>"							,       __lowerCamelCase    :	List[Any]="</s>"							,       __lowerCamelCase    :	List[str]="<s>"							,       __lowerCamelCase    :	Any="<unk>"							,       __lowerCamelCase    :	Any="<pad>"							,       __lowerCamelCase    :	Any="<mask>"							,       __lowerCamelCase    :	Any=False							,       **__lowerCamelCase    :	Dict							,       ):



     """simple docstring"""
     _snake_case   	=      AddedToken(__lowerCamelCase							,       lstrip=__lowerCamelCase							,       rstrip=__lowerCamelCase				) if isinstance(__lowerCamelCase							,       __lowerCamelCase				) else bos_token
     _snake_case   	=      AddedToken(__lowerCamelCase							,       lstrip=__lowerCamelCase							,       rstrip=__lowerCamelCase				) if isinstance(__lowerCamelCase							,       __lowerCamelCase				) else eos_token
     _snake_case   	=      AddedToken(__lowerCamelCase							,       lstrip=__lowerCamelCase							,       rstrip=__lowerCamelCase				) if isinstance(__lowerCamelCase							,       __lowerCamelCase				) else sep_token
     _snake_case   	=      AddedToken(__lowerCamelCase							,       lstrip=__lowerCamelCase							,       rstrip=__lowerCamelCase				) if isinstance(__lowerCamelCase							,       __lowerCamelCase				) else cls_token
     _snake_case   	=      AddedToken(__lowerCamelCase							,       lstrip=__lowerCamelCase							,       rstrip=__lowerCamelCase				) if isinstance(__lowerCamelCase							,       __lowerCamelCase				) else unk_token
     _snake_case   	=      AddedToken(__lowerCamelCase							,       lstrip=__lowerCamelCase							,       rstrip=__lowerCamelCase				) if isinstance(__lowerCamelCase							,       __lowerCamelCase				) else pad_token

     # Mask token behave like a normal word, i.e. include the space before it
     _snake_case   	=      AddedToken(__lowerCamelCase							,       lstrip=__lowerCamelCase							,       rstrip=__lowerCamelCase				) if isinstance(__lowerCamelCase							,       __lowerCamelCase				) else mask_token

     super().__init__(
         errors=__lowerCamelCase							,       bos_token=__lowerCamelCase							,       eos_token=__lowerCamelCase							,       unk_token=__lowerCamelCase							,       sep_token=__lowerCamelCase							,       cls_token=__lowerCamelCase							,       pad_token=__lowerCamelCase							,       mask_token=__lowerCamelCase							,       add_prefix_space=__lowerCamelCase							,       **__lowerCamelCase							,       )

     with open(__lowerCamelCase							,       encoding='''utf-8'''				) as vocab_handle:
       _snake_case   	=      json.load(__lowerCamelCase				)
     _snake_case   	=      {v: k for k, v in self.encoder.items()}
     _snake_case   	=      errors  # how to handle errors in decoding
     _snake_case   	=      bytes_to_unicode()
     _snake_case   	=      {v: k for k, v in self.byte_encoder.items()}
     with open(__lowerCamelCase							,       encoding='''utf-8'''				) as merges_handle:
       _snake_case   	=      merges_handle.read().split('''\n'''				)[1:-1]
     _snake_case   	=      [tuple(merge.split()				) for merge in bpe_merges]
     _snake_case   	=      dict(zip(__lowerCamelCase							,       range(len(__lowerCamelCase				)				)				)				)
     _snake_case   	=      {}
     _snake_case   	=      add_prefix_space

     # Should have added re.IGNORECASE so BPE merges can happen for capitalized versions of contractions
     _snake_case   	=      re.compile(R'''\'s|\'t|\'re|\'ve|\'m|\'ll|\'d| ?\p{L}+| ?\p{N}+| ?[^\s\p{L}\p{N}]+|\s+(?!\S)|\s+'''				)



   @property
   def    __UpperCAmelCase    (       self    :	str				):



     """simple docstring"""
     return len(self.encoder				)



   def    __UpperCAmelCase    (       self    :	str				):



     """simple docstring"""
     return dict(self.encoder							,       **self.added_tokens_encoder				)



   def    __UpperCAmelCase    (       self    :	Union[str, Any]							,       __lowerCamelCase    :	Any				):



     """simple docstring"""
     if token in self.cache:
       return self.cache[token]
     _snake_case   	=      tuple(__lowerCamelCase				)
     _snake_case   	=      get_pairs(__lowerCamelCase				)

     if not pairs:
       return token

     while True:
       _snake_case   	=      min(__lowerCamelCase							,       key=lambda __lowerCamelCase				: self.bpe_ranks.get(__lowerCamelCase							,       float('''inf'''				)				)				)
       if bigram not in self.bpe_ranks:
         break
       _snake_case	,     _snake_case   	=      bigram
       _snake_case   	=      []
       _snake_case   	=      0
       while i < len(__lowerCamelCase				):
         try:
           _snake_case   	=      word.index(__lowerCamelCase							,       __lowerCamelCase				)
         except ValueError:
           new_word.extend(word[i:]				)
           break
         else:
           new_word.extend(word[i:j]				)
           _snake_case   	=      j

         if word[i] == first and i < len(__lowerCamelCase				) - 1 and word[i + 1] == second:
           new_word.append(first + second				)
           i += 2
         else:
           new_word.append(word[i]				)
           i += 1
       _snake_case   	=      tuple(__lowerCamelCase				)
       _snake_case   	=      new_word
       if len(__lowerCamelCase				) == 1:
         break
       else:
         _snake_case   	=      get_pairs(__lowerCamelCase				)
     _snake_case   	=      ''' '''.join(__lowerCamelCase				)
     _snake_case   	=      word
     return word



   def    __UpperCAmelCase    (       self    :	str							,       __lowerCamelCase    :	List[Any]				):



     """simple docstring"""
     _snake_case   	=      []
     for token in re.findall(self.pat							,       __lowerCamelCase				):
       _snake_case   	=      ''''''.join(
           self.byte_encoder[b] for b in token.encode('''utf-8'''				)				)  # Maps all our bytes to unicode strings, avoiding control tokens of the BPE (spaces in our case)
       bpe_tokens.extend(bpe_token for bpe_token in self.bpe(__lowerCamelCase				).split(''' '''				)				)
     return bpe_tokens



   def    __UpperCAmelCase    (       self    :	List[str]							,       __lowerCamelCase    :	List[str]				):



     """simple docstring"""
     return self.encoder.get(__lowerCamelCase							,       self.encoder.get(self.unk_token				)				)



   def    __UpperCAmelCase    (       self    :	List[str]							,       __lowerCamelCase    :	Optional[Any]				):



     """simple docstring"""
     return self.decoder.get(__lowerCamelCase				)



   def    __UpperCAmelCase    (       self    :	Optional[int]							,       __lowerCamelCase    :	Any				):



     """simple docstring"""
     _snake_case   	=      ''''''.join(__lowerCamelCase				)
     _snake_case   	=      bytearray([self.byte_decoder[c] for c in text]				).decode('''utf-8'''							,       errors=self.errors				)
     return text



   def    __UpperCAmelCase    (       self    :	int							,       __lowerCamelCase    :	str							,       __lowerCamelCase    :	Optional[str] = None				):



     """simple docstring"""
     if not os.path.isdir(__lowerCamelCase				):
       logger.error(f"""Vocabulary path ({save_directory}) should be a directory"""				)
       return
     _snake_case   	=      os.path.join(
         __lowerCamelCase							,       (filename_prefix + '''-''' if filename_prefix else '''''') + VOCAB_FILES_NAMES['''vocab_file''']				)
     _snake_case   	=      os.path.join(
         __lowerCamelCase							,       (filename_prefix + '''-''' if filename_prefix else '''''') + VOCAB_FILES_NAMES['''merges_file''']				)

     with open(__lowerCamelCase							,       '''w'''							,       encoding='''utf-8'''				) as f:
       f.write(json.dumps(self.encoder							,       indent=2							,       sort_keys=__lowerCamelCase							,       ensure_ascii=__lowerCamelCase				) + '''\n'''				)

     _snake_case   	=      0
     with open(__lowerCamelCase							,       '''w'''							,       encoding='''utf-8'''				) as writer:
       writer.write('''#version: 0.2\n'''				)
       for bpe_tokens, token_index in sorted(self.bpe_ranks.items()							,       key=lambda __lowerCamelCase				: kv[1]				):
         if index != token_index:
           logger.warning(
               f"""Saving vocabulary to {merge_file}: BPE merge indices are not consecutive."""
               ''' Please check that the tokenizer is not corrupted!'''				)
           _snake_case   	=      token_index
         writer.write(''' '''.join(__lowerCamelCase				) + '''\n'''				)
         index += 1

     return vocab_file, merge_file



   def    __UpperCAmelCase    (       self    :	Tuple							,       __lowerCamelCase    :	List[int]							,       __lowerCamelCase    :	Optional[List[int]] = None				):



     """simple docstring"""
     if token_ids_a is None:
       return [self.cls_token_id] + token_ids_a + [self.sep_token_id]
     _snake_case   	=      [self.cls_token_id]
     _snake_case   	=      [self.sep_token_id]
     return cls + token_ids_a + sep + sep + token_ids_a + sep



   def    __UpperCAmelCase    (       self    :	Any							,       __lowerCamelCase    :	List[int]							,       __lowerCamelCase    :	Optional[List[int]] = None							,       __lowerCamelCase    :	bool = False				):



     """simple docstring"""
     if already_has_special_tokens:
       return super().get_special_tokens_mask(
           token_ids_a=__lowerCamelCase							,       token_ids_a=__lowerCamelCase							,       already_has_special_tokens=__lowerCamelCase				)

     if token_ids_a is None:
       return [1] + ([0] * len(__lowerCamelCase				)) + [1]
     return [1] + ([0] * len(__lowerCamelCase				)) + [1, 1] + ([0] * len(__lowerCamelCase				)) + [1]



   def    __UpperCAmelCase    (       self    :	Optional[Any]							,       __lowerCamelCase    :	List[int]							,       __lowerCamelCase    :	Optional[List[int]] = None				):



     """simple docstring"""
     _snake_case   	=      [self.sep_token_id]
     _snake_case   	=      [self.cls_token_id]

     if token_ids_a is None:
       return len(cls + token_ids_a + sep				) * [0]
     return len(cls + token_ids_a + sep + sep + token_ids_a + sep				) * [0]





   def    __UpperCAmelCase    (       self    :	Tuple							,       __lowerCamelCase    :	Optional[int]							,       __lowerCamelCase    :	List[str]=False							,       **__lowerCamelCase    :	Optional[Any]				):



     """simple docstring"""
     _snake_case   	=      kwargs.pop('''add_prefix_space'''							,       self.add_prefix_space				)
     if (is_split_into_words or add_prefix_space) and (len(__lowerCamelCase				) > 0 and not text[0].isspace()):
       _snake_case   	=      ''' ''' + text
     return (text, kwargs)









'''simple docstring'''


import logging

import torch
from torch import nn
from torch.nn import CrossEntropyLoss, MSELoss

from transformers.file_utils import add_start_docstrings, add_start_docstrings_to_model_forward
from transformers.models.bert.modeling_bert import (
    BERT_INPUTS_DOCSTRING,
    BERT_START_DOCSTRING,
    BertEncoder,
    BertModel,
    BertPreTrainedModel,
)


_UpperCamelCase 							=  logging.getLogger(__name__)







class 							__magic_name__	(       lowerCAmelCase ):

     """simple docstring"""






     def lowerCAmelCase__  (   self			,     lowerCamelCase			,     lowerCamelCase			,     lowerCamelCase=None			,     lowerCamelCase=None		):


          '''simple docstring'''





          __A	:       List[Any]      =							self.layer[current_layer](lowerCamelCase			,     lowerCamelCase			,     head_mask[current_layer]		)

          __A	:       Tuple      =							layer_outputs[0]

          return hidden_states







@add_start_docstrings(
    'The bare Bert Model transformer with PABEE outputting raw hidden-states without any specific head on top.'    ,		lowerCAmelCase    ,		)
class 							__magic_name__	(       lowerCAmelCase ):

     """simple docstring"""






     def __init__(   self			,     lowerCamelCase		):


          '''simple docstring'''





          super().__init__(lowerCamelCase		)

          __A	:       Any      =							BertEncoderWithPabee(lowerCamelCase		)

          self.init_weights()
          __A	:       Optional[Any]      =							0
          __A	:       Union[str, Any]      =							0
          __A	:       Dict      =							0

          __A	:       List[Any]      =							0


     def lowerCAmelCase__  (   self			,     lowerCamelCase		):


          '''simple docstring'''





          __A	:       Any      =							threshold


     def lowerCAmelCase__  (   self			,     lowerCamelCase		):


          '''simple docstring'''





          __A	:       List[Any]      =							patience


     def lowerCAmelCase__  (   self		):


          '''simple docstring'''





          __A	:       List[str]      =							0
          __A	:       int      =							0


     def lowerCAmelCase__  (   self		):


          '''simple docstring'''





          __A	:       Optional[Any]      =							self.inference_layers_num / self.inference_instances_num
          __A	:       int      =							(
              f"*** Patience = {self.patience} Avg. Inference Layers = {avg_inf_layers:.2f} Speed Up ="
              f" {1 - avg_inf_layers / self.config.num_hidden_layers:.2f} ***"
          )
          print(lowerCamelCase		)


     @add_start_docstrings_to_model_forward(lowerCamelCase		)
     def lowerCAmelCase__  (   self			,     lowerCamelCase=None			,     lowerCamelCase=None			,     lowerCamelCase=None			,     lowerCamelCase=None			,     lowerCamelCase=None			,     lowerCamelCase=None			,     lowerCamelCase=None			,     lowerCamelCase=None			,     lowerCamelCase=None			,     lowerCamelCase=None			,     lowerCamelCase=False			,     ):


          '''simple docstring'''





          if input_ids is not None and inputs_embeds is not None:
               raise ValueError("You cannot specify both input_ids and inputs_embeds at the same time"		)
          elif input_ids is not None:
               __A	:       Optional[int]      =							input_ids.size()
          elif inputs_embeds is not None:
               __A	:       Any      =							inputs_embeds.size()[:-1]
          else:
               raise ValueError("You have to specify either input_ids or inputs_embeds"		)

          __A	:       List[str]      =							input_ids.device if input_ids is not None else inputs_embeds.device

          if attention_mask is None:
               __A	:       Any      =							torch.ones(lowerCamelCase			,     device=lowerCamelCase		)
          if token_type_ids is None:
               __A	:       List[Any]      =							torch.zeros(lowerCamelCase			,     dtype=torch.long			,     device=lowerCamelCase		)

          # We can provide a self-attention mask of dimensions [batch_size, from_seq_length, to_seq_length]
          # ourselves in which case we just need to make it broadcastable to all heads.
          __A	:       torch.Tensor      =							self.get_extended_attention_mask(lowerCamelCase			,     lowerCamelCase			,     lowerCamelCase		)

          # If a 2D ou 3D attention mask is provided for the cross-attention
          # we need to make broadcastable to [batch_size, num_heads, seq_length, seq_length]
          if self.config.is_decoder and encoder_hidden_states is not None:
               __A  ,__A  ,__A	:       Tuple      =							encoder_hidden_states.size()
               __A	:       Any      =							(encoder_batch_size, encoder_sequence_length)
               if encoder_attention_mask is None:
                    __A	:       List[str]      =							torch.ones(lowerCamelCase			,     device=lowerCamelCase		)
               __A	:       Dict      =							self.invert_attention_mask(lowerCamelCase		)
          else:
               __A	:       Union[str, Any]      =							None

          # Prepare head mask if needed
          # 1.0 in head_mask indicate we keep the head
          # attention_probs has shape bsz x n_heads x N x N
          # input head_mask has shape [num_heads] or [num_hidden_layers x num_heads]
          # and head_mask is converted to shape [num_hidden_layers x batch x num_heads x seq_length x seq_length]
          __A	:       Any      =							self.get_head_mask(lowerCamelCase			,     self.config.num_hidden_layers		)

          __A	:       Tuple      =							self.embeddings(
              input_ids=lowerCamelCase			,     position_ids=lowerCamelCase			,     token_type_ids=lowerCamelCase			,     inputs_embeds=lowerCamelCase		)
          __A	:       str      =							embedding_output

          if self.training:
               __A	:       Dict      =							[]
               for i in range(self.config.num_hidden_layers		):
                    __A	:       str      =							self.encoder.adaptive_forward(
                        lowerCamelCase			,     current_layer=lowerCamelCase			,     attention_mask=lowerCamelCase			,     head_mask=lowerCamelCase		)

                    __A	:       Optional[Any]      =							self.pooler(lowerCamelCase		)
                    __A	:       Optional[Any]      =							output_layers[i](output_dropout(lowerCamelCase		)		)
                    res.append(lowerCamelCase		)
          elif self.patience == 0:  # Use all layers for inference
               __A	:       int      =							self.encoder(
                   lowerCamelCase			,     attention_mask=lowerCamelCase			,     head_mask=lowerCamelCase			,     encoder_hidden_states=lowerCamelCase			,     encoder_attention_mask=lowerCamelCase			,     )
               __A	:       Optional[Any]      =							self.pooler(encoder_outputs[0]		)
               __A	:       List[str]      =							[output_layers[self.config.num_hidden_layers - 1](lowerCamelCase		)]
          else:
               __A	:       int      =							0
               __A	:       List[str]      =							None
               __A	:       Optional[int]      =							0
               for i in range(self.config.num_hidden_layers		):
                    calculated_layer_num += 1
                    __A	:       List[str]      =							self.encoder.adaptive_forward(
                        lowerCamelCase			,     current_layer=lowerCamelCase			,     attention_mask=lowerCamelCase			,     head_mask=lowerCamelCase		)

                    __A	:       List[str]      =							self.pooler(lowerCamelCase		)
                    __A	:       str      =							output_layers[i](lowerCamelCase		)
                    if regression:
                         __A	:       int      =							logits.detach()
                         if patient_result is not None:
                              __A	:       Union[str, Any]      =							patient_result.detach()
                         if (patient_result is not None) and torch.abs(patient_result - labels		) < self.regression_threshold:
                              patient_counter += 1
                         else:
                              __A	:       Any      =							0
                    else:
                         __A	:       str      =							logits.detach().argmax(dim=1		)
                         if patient_result is not None:
                              __A	:       List[str]      =							patient_result.detach().argmax(dim=1		)
                         if (patient_result is not None) and torch.all(labels.eq(lowerCamelCase		)		):
                              patient_counter += 1
                         else:
                              __A	:       Union[str, Any]      =							0

                    __A	:       int      =							logits
                    if patient_counter == self.patience:
                         break
               __A	:       List[str]      =							[patient_result]
               self.inference_layers_num += calculated_layer_num
               self.inference_instances_num += 1

          return res







@add_start_docstrings(
    'Bert Model transformer with PABEE and a sequence classification/regression head on top (a linear layer on top of\n    the pooled output) e.g. for GLUE tasks. '    ,		lowerCAmelCase    ,		)
class 							__magic_name__	(       lowerCAmelCase ):

     """simple docstring"""






     def __init__(   self			,     lowerCamelCase		):


          '''simple docstring'''





          super().__init__(lowerCamelCase		)
          __A	:       Union[str, Any]      =							config.num_labels

          __A	:       Union[str, Any]      =							BertModelWithPabee(lowerCamelCase		)
          __A	:       Union[str, Any]      =							nn.Dropout(config.hidden_dropout_prob		)
          __A	:       int      =							nn.ModuleList(
              [nn.Linear(config.hidden_size			,     self.config.num_labels		) for _ in range(config.num_hidden_layers		)]		)

          self.init_weights()


     @add_start_docstrings_to_model_forward(lowerCamelCase		)
     def lowerCAmelCase__  (   self			,     lowerCamelCase=None			,     lowerCamelCase=None			,     lowerCamelCase=None			,     lowerCamelCase=None			,     lowerCamelCase=None			,     lowerCamelCase=None			,     lowerCamelCase=None			,     ):


          '''simple docstring'''





          __A	:       Optional[Any]      =							self.bert(
              input_ids=lowerCamelCase			,     attention_mask=lowerCamelCase			,     token_type_ids=lowerCamelCase			,     position_ids=lowerCamelCase			,     head_mask=lowerCamelCase			,     inputs_embeds=lowerCamelCase			,     output_dropout=self.dropout			,     output_layers=self.classifiers			,     regression=self.num_labels == 1			,     )

          __A	:       Any      =							(logits[-1],)

          if labels is not None:
               __A	:       Optional[Any]      =							None
               __A	:       int      =							0
               for ix, logits_item in enumerate(lowerCamelCase		):
                    if self.num_labels == 1:
                         #  We are doing regression
                         __A	:       Union[str, Any]      =							MSELoss()
                         __A	:       str      =							loss_fct(logits_item.view(-1		)			,     labels.view(-1		)		)
                    else:
                         __A	:       Optional[int]      =							CrossEntropyLoss()
                         __A	:       Optional[int]      =							loss_fct(logits_item.view(-1			,     self.num_labels		)			,     labels.view(-1		)		)
                    if total_loss is None:
                         __A	:       str      =							loss
                    else:
                         total_loss += loss * (ix + 1)
                    total_weights += ix + 1
               __A	:       Tuple      =							(total_loss / total_weights,) + outputs

          return outputs

