


from ...configuration_utils import PretrainedConfig
from ...utils import logging


a_ :int  							=			logging.get_logger(__name__)

a_ :Tuple  							=			{
    'facebook/s2t-small-librispeech-asr': (
        'https://huggingface.co/facebook/s2t-small-librispeech-asr/resolve/main/config.json'
    ),
    # See all Speech2Text models at https://huggingface.co/models?filter=speech_to_text
}

class 							lowercase  (						_UpperCAmelCase			):
     lowerCamelCase			:			Union[str, Any]      = '''speech_to_text'''
     lowerCamelCase			:			str      = ['''past_key_values''']
     lowerCamelCase			:			Optional[Any]      = {'''num_attention_heads''': '''encoder_attention_heads''', '''hidden_size''': '''d_model'''}







     def __init__(						self :						Any   ,   _lowercase :						List[Any]=1_00_00   ,   _lowercase :						Union[str, Any]=12   ,   _lowercase :						int=20_48   ,   _lowercase :						Tuple=4   ,   _lowercase :						Any=6   ,   _lowercase :						int=20_48   ,   _lowercase :						str=4   ,   _lowercase :						Optional[Any]=0.0   ,   _lowercase :						List[str]=0.0   ,   _lowercase :						Dict=True   ,   _lowercase :						List[str]=True   ,   _lowercase :						List[str]="relu"   ,   _lowercase :						List[str]=2_56   ,   _lowercase :						str=0.1   ,   _lowercase :						Tuple=0.0   ,   _lowercase :						List[Any]=0.0   ,   _lowercase :						int=0.02   ,   _lowercase :						int=2   ,   _lowercase :						Any=True   ,   _lowercase :						List[str]=1   ,   _lowercase :						List[str]=0   ,   _lowercase :						Tuple=2   ,   _lowercase :						Dict=60_00   ,   _lowercase :						str=10_24   ,   _lowercase :						int=2   ,   _lowercase :						Any=(5, 5)   ,   _lowercase :						Tuple=10_24   ,   _lowercase :						Optional[Any]=80   ,   _lowercase :						Tuple=1   ,   **_lowercase :						Optional[int]   ,   ):
           SCREAMING_SNAKE_CASE__       :  Optional[int]						     =		vocab_size
           SCREAMING_SNAKE_CASE__       :  int						     =		d_model
           SCREAMING_SNAKE_CASE__       :  Optional[Any]						     =		encoder_ffn_dim
           SCREAMING_SNAKE_CASE__       :  Tuple						     =		encoder_layers
           SCREAMING_SNAKE_CASE__       :  Union[str, Any]						     =		encoder_attention_heads
           SCREAMING_SNAKE_CASE__       :  str						     =		decoder_ffn_dim
           SCREAMING_SNAKE_CASE__       :  Any						     =		decoder_layers
           SCREAMING_SNAKE_CASE__       :  Optional[int]						     =		decoder_attention_heads
           SCREAMING_SNAKE_CASE__       :  Any						     =		dropout
           SCREAMING_SNAKE_CASE__       :  List[str]						     =		attention_dropout
           SCREAMING_SNAKE_CASE__       :  List[str]						     =		activation_dropout
           SCREAMING_SNAKE_CASE__       :  int						     =		activation_function
           SCREAMING_SNAKE_CASE__       :  List[str]						     =		init_std
           SCREAMING_SNAKE_CASE__       :  Optional[Any]						     =		encoder_layerdrop
           SCREAMING_SNAKE_CASE__       :  Tuple						     =		decoder_layerdrop
           SCREAMING_SNAKE_CASE__       :  int						     =		use_cache
           SCREAMING_SNAKE_CASE__       :  Any						     =		encoder_layers
           SCREAMING_SNAKE_CASE__       :  str						     =		scale_embedding  # scale factor will be sqrt(d_model) if True
           SCREAMING_SNAKE_CASE__       :  Dict						     =		max_source_positions
           SCREAMING_SNAKE_CASE__       :  Tuple						     =		max_target_positions
           SCREAMING_SNAKE_CASE__       :  List[Any]						     =		num_conv_layers
           SCREAMING_SNAKE_CASE__       :  str						     =		list(_lowercase      )
           SCREAMING_SNAKE_CASE__       :  List[str]						     =		conv_channels
           SCREAMING_SNAKE_CASE__       :  List[Any]						     =		input_feat_per_channel
           SCREAMING_SNAKE_CASE__       :  List[str]						     =		input_channels

           if len(self.conv_kernel_sizes      ) != self.num_conv_layers:
                 raise ValueError(
                     '''Configuration for convolutional module is incorrect. '''
                     '''It is required that `len(config.conv_kernel_sizes)` == `config.num_conv_layers` '''
                     f"""but is `len(config.conv_kernel_sizes) = {len(self.conv_kernel_sizes      )}`, """
                     f"""`config.num_conv_layers = {self.num_conv_layers}`."""      )

           super().__init__(
               pad_token_id=_lowercase   ,   bos_token_id=_lowercase   ,   eos_token_id=_lowercase   ,   is_encoder_decoder=_lowercase   ,   decoder_start_token_id=_lowercase   ,   **_lowercase   ,   )









'''simple docstring'''



import warnings
from typing import List, Optional, Union

from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding, PaddingStrategy, PreTokenizedInput, TextInput, TruncationStrategy
from ...utils import TensorType







class 		lowerCAmelCase__  ( a   ):



 """simple docstring"""



 lowerCAmelCase__       = ["image_processor", "tokenizer"]
 lowerCAmelCase__       = "LayoutLMv2ImageProcessor"
 lowerCAmelCase__       = ("LayoutXLMTokenizer", "LayoutXLMTokenizerFast")
 def __init__(						self   :			Any   ,				__SCREAMING_SNAKE_CASE   :			Optional[Any]=None   ,				__SCREAMING_SNAKE_CASE   :			List[Any]=None   ,				**__SCREAMING_SNAKE_CASE   :			str     )    ->					List[str]:


      """simple docstring"""




      if "feature_extractor" in kwargs:
           warnings.warn(
               """The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor`"""
               """ instead."""   ,				__SCREAMING_SNAKE_CASE   ,				)
           __SCREAMING_SNAKE_CASE      = kwargs.pop("""feature_extractor"""     )

      __SCREAMING_SNAKE_CASE      = image_processor if image_processor is not None else feature_extractor
      if image_processor is None:
           raise ValueError("""You need to specify an `image_processor`."""     )
      if tokenizer is None:
           raise ValueError("""You need to specify a `tokenizer`."""     )

      super().__init__(__SCREAMING_SNAKE_CASE   ,				__SCREAMING_SNAKE_CASE     )
 def __call__(						self   :			str   ,				__SCREAMING_SNAKE_CASE   :			Optional[int]   ,				__SCREAMING_SNAKE_CASE   :			Union[TextInput, PreTokenizedInput, List[TextInput], List[PreTokenizedInput]] = None   ,				__SCREAMING_SNAKE_CASE   :			Optional[Union[PreTokenizedInput, List[PreTokenizedInput]]] = None   ,				__SCREAMING_SNAKE_CASE   :			Union[List[List[int]], List[List[List[int]]]] = None   ,				__SCREAMING_SNAKE_CASE   :			Optional[Union[List[int], List[List[int]]]] = None   ,				__SCREAMING_SNAKE_CASE   :			bool = True   ,				__SCREAMING_SNAKE_CASE   :			Union[bool, str, PaddingStrategy] = False   ,				__SCREAMING_SNAKE_CASE   :			Union[bool, str, TruncationStrategy] = None   ,				__SCREAMING_SNAKE_CASE   :			Optional[int] = None   ,				__SCREAMING_SNAKE_CASE   :			int = 0   ,				__SCREAMING_SNAKE_CASE   :			Optional[int] = None   ,				__SCREAMING_SNAKE_CASE   :			Optional[bool] = None   ,				__SCREAMING_SNAKE_CASE   :			Optional[bool] = None   ,				__SCREAMING_SNAKE_CASE   :			bool = False   ,				__SCREAMING_SNAKE_CASE   :			bool = False   ,				__SCREAMING_SNAKE_CASE   :			bool = False   ,				__SCREAMING_SNAKE_CASE   :			bool = False   ,				__SCREAMING_SNAKE_CASE   :			bool = True   ,				__SCREAMING_SNAKE_CASE   :			Optional[Union[str, TensorType]] = None   ,				**__SCREAMING_SNAKE_CASE   :			Any   ,				)    ->					BatchEncoding:


      """simple docstring"""




      if self.image_processor.apply_ocr and (boxes is not None):
           raise ValueError(
               """You cannot provide bounding boxes """
               """if you initialized the image processor with apply_ocr set to True."""     )

      if self.image_processor.apply_ocr and (word_labels is not None):
           raise ValueError(
               """You cannot provide word labels if you initialized the image processor with apply_ocr set to True."""     )

      if return_overflowing_tokens is True and return_offsets_mapping is False:
           raise ValueError("""You cannot return overflowing tokens without returning the offsets mapping."""     )

      # first, apply the image processor
      __SCREAMING_SNAKE_CASE      = self.image_processor(images=__SCREAMING_SNAKE_CASE   ,				return_tensors=__SCREAMING_SNAKE_CASE     )

      # second, apply the tokenizer
      if text is not None and self.image_processor.apply_ocr and text_pair is None:
           if isinstance(__SCREAMING_SNAKE_CASE   ,				__SCREAMING_SNAKE_CASE     ):
                __SCREAMING_SNAKE_CASE      = [text]  # add batch dimension (as the image processor always adds a batch dimension)
           __SCREAMING_SNAKE_CASE      = features["""words"""]

      __SCREAMING_SNAKE_CASE      = self.tokenizer(
          text=text if text is not None else features["""words"""]   ,				text_pair=text_pair if text_pair is not None else None   ,				boxes=boxes if boxes is not None else features["""boxes"""]   ,				word_labels=__SCREAMING_SNAKE_CASE   ,				add_special_tokens=__SCREAMING_SNAKE_CASE   ,				padding=__SCREAMING_SNAKE_CASE   ,				truncation=__SCREAMING_SNAKE_CASE   ,				max_length=__SCREAMING_SNAKE_CASE   ,				stride=__SCREAMING_SNAKE_CASE   ,				pad_to_multiple_of=__SCREAMING_SNAKE_CASE   ,				return_token_type_ids=__SCREAMING_SNAKE_CASE   ,				return_attention_mask=__SCREAMING_SNAKE_CASE   ,				return_overflowing_tokens=__SCREAMING_SNAKE_CASE   ,				return_special_tokens_mask=__SCREAMING_SNAKE_CASE   ,				return_offsets_mapping=__SCREAMING_SNAKE_CASE   ,				return_length=__SCREAMING_SNAKE_CASE   ,				verbose=__SCREAMING_SNAKE_CASE   ,				return_tensors=__SCREAMING_SNAKE_CASE   ,				**__SCREAMING_SNAKE_CASE   ,				)

      # add pixel values
      __SCREAMING_SNAKE_CASE      = features.pop("""pixel_values"""     )
      if return_overflowing_tokens is True:
           __SCREAMING_SNAKE_CASE      = self.get_overflowing_images(__SCREAMING_SNAKE_CASE   ,				encoded_inputs["""overflow_to_sample_mapping"""]     )
      __SCREAMING_SNAKE_CASE      = images

      return encoded_inputs
 def  UpperCAmelCase__						(						self   :			List[str]   ,				__SCREAMING_SNAKE_CASE   :			Tuple   ,				__SCREAMING_SNAKE_CASE   :			Dict     )    ->					int:


      """simple docstring"""




      __SCREAMING_SNAKE_CASE      = []
      for sample_idx in overflow_to_sample_mapping:
           images_with_overflow.append(images[sample_idx]     )

      if len(__SCREAMING_SNAKE_CASE     ) != len(__SCREAMING_SNAKE_CASE     ):
           raise ValueError(
               """Expected length of images to be the same as the length of `overflow_to_sample_mapping`, but got"""
               f' {len(__SCREAMING_SNAKE_CASE     )} and {len(__SCREAMING_SNAKE_CASE     )}'     )

      return images_with_overflow
 def  UpperCAmelCase__						(						self   :			Optional[Any]   ,				*__SCREAMING_SNAKE_CASE   :			str   ,				**__SCREAMING_SNAKE_CASE   :			List[str]     )    ->					List[str]:


      """simple docstring"""




      return self.tokenizer.batch_decode(*__SCREAMING_SNAKE_CASE   ,				**__SCREAMING_SNAKE_CASE     )
 def  UpperCAmelCase__						(						self   :			Union[str, Any]   ,				*__SCREAMING_SNAKE_CASE   :			Dict   ,				**__SCREAMING_SNAKE_CASE   :			Any     )    ->					Union[str, Any]:


      """simple docstring"""




      return self.tokenizer.decode(*__SCREAMING_SNAKE_CASE   ,				**__SCREAMING_SNAKE_CASE     )
 @property
 def  UpperCAmelCase__						(						self   :			int     )    ->					Optional[int]:


      """simple docstring"""




      return ["input_ids", "bbox", "attention_mask", "image"]
 @property
 def  UpperCAmelCase__						(						self   :			Any     )    ->					List[Any]:


      """simple docstring"""




      warnings.warn(
          """`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead."""   ,				__SCREAMING_SNAKE_CASE   ,				)
      return self.image_processor_class


 @property
 def  UpperCAmelCase__						(						self   :			Optional[int]     )    ->					Any:


      """simple docstring"""




      warnings.warn(
          """`feature_extractor` is deprecated and will be removed in v5. Use `image_processor` instead."""   ,				__SCREAMING_SNAKE_CASE   ,				)
      return self.image_processor






