


'''simple docstring'''







from collections import OrderedDict
from typing import Mapping

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


A__:   Tuple    =	logging.get_logger(__name__)

A__:   str    =	{
    '''flaubert/flaubert_small_cased''': '''https://huggingface.co/flaubert/flaubert_small_cased/resolve/main/config.json''',
    '''flaubert/flaubert_base_uncased''': '''https://huggingface.co/flaubert/flaubert_base_uncased/resolve/main/config.json''',
    '''flaubert/flaubert_base_cased''': '''https://huggingface.co/flaubert/flaubert_base_cased/resolve/main/config.json''',
    '''flaubert/flaubert_large_cased''': '''https://huggingface.co/flaubert/flaubert_large_cased/resolve/main/config.json''',
}







class A__	(						UpperCAmelCase__				):
      __UpperCamelCase	:  List[str]     	=							"flaubert"
      __UpperCamelCase	:  Optional[int]     	=							{
          "hidden_size": "emb_dim",
          "num_attention_heads": "n_heads",
          "num_hidden_layers": "n_layers",
          "n_words": "vocab_size",  # For backward compatibility
      }






      def __init__(			self      :int					,						SCREAMING_SNAKE_CASE      :Union[str, Any]=False					,						SCREAMING_SNAKE_CASE      :List[Any]=0.0					,						SCREAMING_SNAKE_CASE      :Optional[int]=3_0_1_4_5					,						SCREAMING_SNAKE_CASE      :Optional[Any]=2_0_4_8					,						SCREAMING_SNAKE_CASE      :int=1_2					,						SCREAMING_SNAKE_CASE      :Optional[int]=1_6					,						SCREAMING_SNAKE_CASE      :List[Any]=0.1					,						SCREAMING_SNAKE_CASE      :Any=0.1					,						SCREAMING_SNAKE_CASE      :List[str]=True					,						SCREAMING_SNAKE_CASE      :Union[str, Any]=False					,						SCREAMING_SNAKE_CASE      :List[Any]=False					,						SCREAMING_SNAKE_CASE      :List[Any]=False					,						SCREAMING_SNAKE_CASE      :int=1					,						SCREAMING_SNAKE_CASE      :List[str]=True					,						SCREAMING_SNAKE_CASE      :Any=5_1_2					,						SCREAMING_SNAKE_CASE      :Dict=2_0_4_8**-0.5					,						SCREAMING_SNAKE_CASE      :Dict=1e-12					,						SCREAMING_SNAKE_CASE      :Union[str, Any]=0.02					,						SCREAMING_SNAKE_CASE      :str=0					,						SCREAMING_SNAKE_CASE      :List[str]=1					,						SCREAMING_SNAKE_CASE      :str=2					,						SCREAMING_SNAKE_CASE      :int=3					,						SCREAMING_SNAKE_CASE      :Optional[Any]=5					,						SCREAMING_SNAKE_CASE      :Union[str, Any]=True					,						SCREAMING_SNAKE_CASE      :Tuple="first"					,						SCREAMING_SNAKE_CASE      :int=True					,						SCREAMING_SNAKE_CASE      :Optional[int]=None					,						SCREAMING_SNAKE_CASE      :Dict=True					,						SCREAMING_SNAKE_CASE      :Optional[Any]=0.1					,						SCREAMING_SNAKE_CASE      :Dict=5					,						SCREAMING_SNAKE_CASE      :List[str]=5					,						SCREAMING_SNAKE_CASE      :Optional[int]=0					,						SCREAMING_SNAKE_CASE      :str=0					,						SCREAMING_SNAKE_CASE      :List[Any]=2					,						SCREAMING_SNAKE_CASE      :Union[str, Any]=0					,						**SCREAMING_SNAKE_CASE      :List[str]					,						)	-> List[str]:




             '''simple docstring'''
             _a   :			Optional[int]					 =pre_norm
             _a   :			Union[str, Any]					 =layerdrop
             _a   :			str					 =vocab_size
             _a   :			List[str]					 =emb_dim
             _a   :			List[str]					 =n_layers
             _a   :			List[Any]					 =n_heads
             _a   :			str					 =dropout
             _a   :			Optional[Any]					 =attention_dropout
             _a   :			List[Any]					 =gelu_activation
             _a   :			str					 =sinusoidal_embeddings
             _a   :			List[str]					 =causal
             _a   :			Optional[int]					 =asm
             _a   :			Dict					 =n_langs
             _a   :			Union[str, Any]					 =use_lang_emb
             _a   :			Dict					 =layer_norm_eps
             _a   :			Optional[Any]					 =bos_index
             _a   :			int					 =eos_index
             _a   :			Dict					 =pad_index
             _a   :			Tuple					 =unk_index
             _a   :			Union[str, Any]					 =mask_index
             _a   :			List[str]					 =is_encoder
             _a   :			Tuple					 =max_position_embeddings
             _a   :			Tuple					 =embed_init_std
             _a   :			List[str]					 =init_std
             _a   :			List[str]					 =summary_type
             _a   :			Any					 =summary_use_proj
             _a   :			Dict					 =summary_activation
             _a   :			Dict					 =summary_proj_to_labels
             _a   :			str					 =summary_first_dropout
             _a   :			Optional[int]					 =start_n_top
             _a   :			Optional[int]					 =end_n_top
             _a   :			int					 =mask_token_id
             _a   :			Dict					 =lang_id

             if "n_words" in kwargs:
                    _a   :			Optional[int]					 =kwargs["""n_words"""]

             super().__init__(pad_token_id=SCREAMING_SNAKE_CASE					,						bos_token_id=SCREAMING_SNAKE_CASE					,						**SCREAMING_SNAKE_CASE     )







class A__	(						UpperCAmelCase__				):






      @property
      def __UpperCAmelCase	(			self      :Any     )	-> Mapping[str, Mapping[int, str]]:




             '''simple docstring'''
             if self.task == "multiple-choice":
                    _a   :			List[str]					 ={0: """batch""", 1: """choice""", 2: """sequence"""}
             else:
                    _a   :			Optional[int]					 ={0: """batch""", 1: """sequence"""}
             return OrderedDict(
                 [
                     ("""input_ids""", dynamic_axis),
                     ("""attention_mask""", dynamic_axis),
                 ]     )






'''simple docstring'''







from typing import Dict, Optional, Tuple

import torch


def      SCREAMING_SNAKE_CASE_ (  _UpperCAmelCase     :     torch.Tensor  )  ->      torch.Tensor:
       _a   :			Tuple					 =boundaries[1] - boundaries[0]
       _a   :			Dict					 =boundaries + step / 2
       _a   :			List[Any]					 =torch.cat([bin_centers, (bin_centers[-1] + step).unsqueeze(-1  )]   ,dim=0  )
       return bin_centers


def      SCREAMING_SNAKE_CASE_ (  _UpperCAmelCase     :     torch.Tensor   ,_UpperCAmelCase     :     torch.Tensor   ,)  ->      Tuple[torch.Tensor, torch.Tensor]:
       _a   :			Any					 =_calculate_bin_centers(_UpperCAmelCase  )
       return (
           torch.sum(aligned_distance_error_probs * bin_centers   ,dim=-1  ),
           bin_centers[-1],
       )


def      SCREAMING_SNAKE_CASE_ (  _UpperCAmelCase     :     torch.Tensor   ,_UpperCAmelCase     :     int = 31   ,_UpperCAmelCase     :     int = 64   ,**_UpperCAmelCase     :     Dict   ,)  ->      Dict[str, torch.Tensor]:
       _a   :			Dict					 =torch.linspace(0   ,_UpperCAmelCase   ,steps=(no_bins - 1)   ,device=logits.device  )

       _a   :			int					 =torch.nn.functional.softmax(_UpperCAmelCase   ,dim=-1  )
       _a ,   _a   :			List[Any]					 =_calculate_expected_aligned_error(
           alignment_confidence_breaks=_UpperCAmelCase   ,aligned_distance_error_probs=_UpperCAmelCase   ,)

       return {
           "aligned_confidence_probs": aligned_confidence_probs,
           "predicted_aligned_error": predicted_aligned_error,
           "max_predicted_aligned_error": max_predicted_aligned_error,
       }


def      SCREAMING_SNAKE_CASE_ (  _UpperCAmelCase     :     torch.Tensor   ,_UpperCAmelCase     :     Optional[torch.Tensor] = None   ,_UpperCAmelCase     :     int = 31   ,_UpperCAmelCase     :     int = 64   ,_UpperCAmelCase     :     float = 1e-8   ,**_UpperCAmelCase     :     Optional[Any]   ,)  ->      torch.Tensor:
       if residue_weights is None:
              _a   :			Dict					 =logits.new_ones(logits.shape[-2]  )

       _a   :			str					 =torch.linspace(0   ,_UpperCAmelCase   ,steps=(no_bins - 1)   ,device=logits.device  )

       _a   :			Optional[int]					 =_calculate_bin_centers(_UpperCAmelCase  )
       torch.sum(_UpperCAmelCase  )
       _a   :			List[str]					 =logits.shape[-2]
       _a   :			List[Any]					 =max(_UpperCAmelCase   ,19  )

       _a   :			Union[str, Any]					 =1.2_4 * (clipped_n - 15) ** (1.0 / 3) - 1.8

       _a   :			Tuple					 =torch.nn.functional.softmax(_UpperCAmelCase   ,dim=-1  )

       _a   :			Dict					 =1.0 / (1 + (bin_centers**2) / (da**2))
       _a   :			int					 =torch.sum(probs * tm_per_bin   ,dim=-1  )

       _a   :			List[Any]					 =residue_weights / (eps + residue_weights.sum())
       _a   :			List[str]					 =torch.sum(predicted_tm_term * normed_residue_mask   ,dim=-1  )

       _a   :			int					 =per_alignment * residue_weights

       _a   :			List[Any]					 =(weighted == torch.max(_UpperCAmelCase  )).nonzero()[0]
       return per_alignment[tuple(_UpperCAmelCase  )]


