
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			(   UpperCamelCase_			):





     """simple docstring"""







     SCREAMING_SNAKE_CASE_		 =	['''image_processor''', '''tokenizer''']
     SCREAMING_SNAKE_CASE_		 =	'''LayoutLMv3ImageProcessor'''
     SCREAMING_SNAKE_CASE_		 =	('''LayoutLMv3Tokenizer''', '''LayoutLMv3TokenizerFast''')






     def __init__(				self    ,    __SCREAMING_SNAKE_CASE=None    ,    __SCREAMING_SNAKE_CASE=None    ,    **__SCREAMING_SNAKE_CASE	)	-> int:




           """simple docstring"""







           UpperCamelCase__     : int											=					None
           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    ,    )
                 UpperCamelCase__     : str											=					kwargs.pop('''feature_extractor'''	)

           UpperCamelCase__     : Optional[int]											=					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    ,    __SCREAMING_SNAKE_CASE    ,    __SCREAMING_SNAKE_CASE = None    ,    __SCREAMING_SNAKE_CASE = None    ,    __SCREAMING_SNAKE_CASE = None    ,    __SCREAMING_SNAKE_CASE = None    ,    __SCREAMING_SNAKE_CASE = True    ,    __SCREAMING_SNAKE_CASE = False    ,    __SCREAMING_SNAKE_CASE = None    ,    __SCREAMING_SNAKE_CASE = None    ,    __SCREAMING_SNAKE_CASE = 0    ,    __SCREAMING_SNAKE_CASE = None    ,    __SCREAMING_SNAKE_CASE = None    ,    __SCREAMING_SNAKE_CASE = None    ,    __SCREAMING_SNAKE_CASE = False    ,    __SCREAMING_SNAKE_CASE = False    ,    __SCREAMING_SNAKE_CASE = False    ,    __SCREAMING_SNAKE_CASE = False    ,    __SCREAMING_SNAKE_CASE = True    ,    __SCREAMING_SNAKE_CASE = None    ,    **__SCREAMING_SNAKE_CASE    ,    )	-> 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.'''	)

           # first, apply the image processor
           UpperCamelCase__     : int											=					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	):
                       UpperCamelCase__     : Any											=					[text]  # add batch dimension (as the image processor always adds a batch dimension)
                 UpperCamelCase__     : Tuple											=					features['''words''']

           UpperCamelCase__     : int											=					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
           UpperCamelCase__     : str											=					features.pop('''pixel_values'''	)
           if return_overflowing_tokens is True:
                 UpperCamelCase__     : Optional[Any]											=					self.get_overflowing_images(__SCREAMING_SNAKE_CASE    ,    encoded_inputs['''overflow_to_sample_mapping''']	)
           UpperCamelCase__     : Any											=					images

           return encoded_inputs






     def  __SCREAMING_SNAKE_CASE      (				self    ,    __SCREAMING_SNAKE_CASE    ,    __SCREAMING_SNAKE_CASE	)	-> int:




           """simple docstring"""







           UpperCamelCase__     : int											=					[]
           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  __SCREAMING_SNAKE_CASE      (				self    ,    *__SCREAMING_SNAKE_CASE    ,    **__SCREAMING_SNAKE_CASE	)	-> str:




           """simple docstring"""







           return self.tokenizer.batch_decode(*__SCREAMING_SNAKE_CASE    ,    **__SCREAMING_SNAKE_CASE	)






     def  __SCREAMING_SNAKE_CASE      (				self    ,    *__SCREAMING_SNAKE_CASE    ,    **__SCREAMING_SNAKE_CASE	)	-> int:




           """simple docstring"""







           return self.tokenizer.decode(*__SCREAMING_SNAKE_CASE    ,    **__SCREAMING_SNAKE_CASE	)






     @property
     def  __SCREAMING_SNAKE_CASE      (				self	)	-> Dict:




           """simple docstring"""







           return ["input_ids", "bbox", "attention_mask", "pixel_values"]






     @property
     def  __SCREAMING_SNAKE_CASE      (				self	)	-> List[str]:




           """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  __SCREAMING_SNAKE_CASE      (				self	)	-> List[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




import functools
import operator

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


lowerCamelCase  =logging.get_logger(__name__)

lowerCamelCase  ={
    "facebook/wav2vec2-base-960h": "https://huggingface.co/facebook/wav2vec2-base-960h/resolve/main/config.json",
    # See all Wav2Vec2 models at https://huggingface.co/models?filter=wav2vec2
}




class 					_lowerCamelCase			(   UpperCamelCase_			):





     """simple docstring"""







     SCREAMING_SNAKE_CASE_		 =	'''wav2vec2'''






     def __init__(				self    ,    __SCREAMING_SNAKE_CASE=3_2    ,    __SCREAMING_SNAKE_CASE=7_6_8    ,    __SCREAMING_SNAKE_CASE=1_2    ,    __SCREAMING_SNAKE_CASE=1_2    ,    __SCREAMING_SNAKE_CASE=3_0_7_2    ,    __SCREAMING_SNAKE_CASE="gelu"    ,    __SCREAMING_SNAKE_CASE=0.1    ,    __SCREAMING_SNAKE_CASE=0.1    ,    __SCREAMING_SNAKE_CASE=0.1    ,    __SCREAMING_SNAKE_CASE=0.0    ,    __SCREAMING_SNAKE_CASE=0.0    ,    __SCREAMING_SNAKE_CASE=0.1    ,    __SCREAMING_SNAKE_CASE=0.1    ,    __SCREAMING_SNAKE_CASE=0.02    ,    __SCREAMING_SNAKE_CASE=1e-5    ,    __SCREAMING_SNAKE_CASE="group"    ,    __SCREAMING_SNAKE_CASE="gelu"    ,    __SCREAMING_SNAKE_CASE=(5_1_2, 5_1_2, 5_1_2, 5_1_2, 5_1_2, 5_1_2, 5_1_2)    ,    __SCREAMING_SNAKE_CASE=(5, 2, 2, 2, 2, 2, 2)    ,    __SCREAMING_SNAKE_CASE=(1_0, 3, 3, 3, 3, 2, 2)    ,    __SCREAMING_SNAKE_CASE=False    ,    __SCREAMING_SNAKE_CASE=1_2_8    ,    __SCREAMING_SNAKE_CASE=1_6    ,    __SCREAMING_SNAKE_CASE=False    ,    __SCREAMING_SNAKE_CASE=True    ,    __SCREAMING_SNAKE_CASE=0.05    ,    __SCREAMING_SNAKE_CASE=1_0    ,    __SCREAMING_SNAKE_CASE=2    ,    __SCREAMING_SNAKE_CASE=0.0    ,    __SCREAMING_SNAKE_CASE=1_0    ,    __SCREAMING_SNAKE_CASE=0    ,    __SCREAMING_SNAKE_CASE=3_2_0    ,    __SCREAMING_SNAKE_CASE=2    ,    __SCREAMING_SNAKE_CASE=0.1    ,    __SCREAMING_SNAKE_CASE=1_0_0    ,    __SCREAMING_SNAKE_CASE=2_5_6    ,    __SCREAMING_SNAKE_CASE=2_5_6    ,    __SCREAMING_SNAKE_CASE=0.1    ,    __SCREAMING_SNAKE_CASE="sum"    ,    __SCREAMING_SNAKE_CASE=False    ,    __SCREAMING_SNAKE_CASE=False    ,    __SCREAMING_SNAKE_CASE=2_5_6    ,    __SCREAMING_SNAKE_CASE=(5_1_2, 5_1_2, 5_1_2, 5_1_2, 1_5_0_0)    ,    __SCREAMING_SNAKE_CASE=(5, 3, 3, 1, 1)    ,    __SCREAMING_SNAKE_CASE=(1, 2, 3, 1, 1)    ,    __SCREAMING_SNAKE_CASE=5_1_2    ,    __SCREAMING_SNAKE_CASE=0    ,    __SCREAMING_SNAKE_CASE=1    ,    __SCREAMING_SNAKE_CASE=2    ,    __SCREAMING_SNAKE_CASE=False    ,    __SCREAMING_SNAKE_CASE=3    ,    __SCREAMING_SNAKE_CASE=2    ,    __SCREAMING_SNAKE_CASE=3    ,    __SCREAMING_SNAKE_CASE=None    ,    __SCREAMING_SNAKE_CASE=None    ,    **__SCREAMING_SNAKE_CASE    ,    )	-> str:




           """simple docstring"""







           super().__init__(**__SCREAMING_SNAKE_CASE    ,    pad_token_id=__SCREAMING_SNAKE_CASE    ,    bos_token_id=__SCREAMING_SNAKE_CASE    ,    eos_token_id=__SCREAMING_SNAKE_CASE	)
           UpperCamelCase__     : str											=					hidden_size
           UpperCamelCase__     : List[Any]											=					feat_extract_norm
           UpperCamelCase__     : Union[str, Any]											=					feat_extract_activation
           UpperCamelCase__     : Union[str, Any]											=					list(__SCREAMING_SNAKE_CASE	)
           UpperCamelCase__     : Dict											=					list(__SCREAMING_SNAKE_CASE	)
           UpperCamelCase__     : Dict											=					list(__SCREAMING_SNAKE_CASE	)
           UpperCamelCase__     : Tuple											=					conv_bias
           UpperCamelCase__     : Optional[Any]											=					num_conv_pos_embeddings
           UpperCamelCase__     : Tuple											=					num_conv_pos_embedding_groups
           UpperCamelCase__     : Tuple											=					len(self.conv_dim	)
           UpperCamelCase__     : Optional[Any]											=					num_hidden_layers
           UpperCamelCase__     : Union[str, Any]											=					intermediate_size
           UpperCamelCase__     : Union[str, Any]											=					hidden_act
           UpperCamelCase__     : List[Any]											=					num_attention_heads
           UpperCamelCase__     : Optional[int]											=					hidden_dropout
           UpperCamelCase__     : Tuple											=					attention_dropout
           UpperCamelCase__     : List[Any]											=					activation_dropout
           UpperCamelCase__     : Optional[int]											=					feat_proj_dropout
           UpperCamelCase__     : int											=					final_dropout
           UpperCamelCase__     : str											=					layerdrop
           UpperCamelCase__     : Dict											=					layer_norm_eps
           UpperCamelCase__     : str											=					initializer_range
           UpperCamelCase__     : List[Any]											=					vocab_size
           UpperCamelCase__     : Dict											=					do_stable_layer_norm
           UpperCamelCase__     : Dict											=					use_weighted_layer_sum

           if (
               (len(self.conv_stride	) != self.num_feat_extract_layers)
               or (len(self.conv_kernel	) != self.num_feat_extract_layers)
               or (len(self.conv_dim	) != self.num_feat_extract_layers)
           ):
                 raise ValueError(
                     '''Configuration for convolutional layers is incorrect. It is required that `len(config.conv_dim)` =='''
                     ''' `len(config.conv_stride)` == `len(config.conv_kernel)`, but is `len(config.conv_dim) ='''
                     F''' {len(self.conv_dim	)}`, `len(config.conv_stride) = {len(self.conv_stride	)}`,'''
                     F''' `len(config.conv_kernel) = {len(self.conv_kernel	)}`.'''	)

           # fine-tuning config parameters for SpecAugment: https://arxiv.org/abs/1904.08779
           UpperCamelCase__     : Tuple											=					apply_spec_augment
           UpperCamelCase__     : str											=					mask_time_prob
           UpperCamelCase__     : Tuple											=					mask_time_length
           UpperCamelCase__     : Optional[Any]											=					mask_time_min_masks
           UpperCamelCase__     : str											=					mask_feature_prob
           UpperCamelCase__     : List[str]											=					mask_feature_length
           UpperCamelCase__     : Optional[Any]											=					mask_feature_min_masks

           # parameters for pretraining with codevector quantized representations
           UpperCamelCase__     : Dict											=					num_codevectors_per_group
           UpperCamelCase__     : Optional[int]											=					num_codevector_groups
           UpperCamelCase__     : Dict											=					contrastive_logits_temperature
           UpperCamelCase__     : List[Any]											=					feat_quantizer_dropout
           UpperCamelCase__     : List[Any]											=					num_negatives
           UpperCamelCase__     : Tuple											=					codevector_dim
           UpperCamelCase__     : List[str]											=					proj_codevector_dim
           UpperCamelCase__     : Tuple											=					diversity_loss_weight

           # ctc loss
           UpperCamelCase__     : List[str]											=					ctc_loss_reduction
           UpperCamelCase__     : Optional[Any]											=					ctc_zero_infinity

           # adapter
           UpperCamelCase__     : List[Any]											=					add_adapter
           UpperCamelCase__     : Any											=					adapter_kernel_size
           UpperCamelCase__     : Tuple											=					adapter_stride
           UpperCamelCase__     : Tuple											=					num_adapter_layers
           UpperCamelCase__     : Optional[Any]											=					output_hidden_size or hidden_size
           UpperCamelCase__     : Union[str, Any]											=					adapter_attn_dim

           # SequenceClassification-specific parameter. Feel free to ignore for other classes.
           UpperCamelCase__     : List[str]											=					classifier_proj_size

           # XVector-specific parameters. Feel free to ignore for other classes.
           UpperCamelCase__     : Union[str, Any]											=					list(__SCREAMING_SNAKE_CASE	)
           UpperCamelCase__     : List[str]											=					list(__SCREAMING_SNAKE_CASE	)
           UpperCamelCase__     : Optional[Any]											=					list(__SCREAMING_SNAKE_CASE	)
           UpperCamelCase__     : int											=					xvector_output_dim






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




           """simple docstring"""







           return functools.reduce(operator.mul    ,    self.conv_stride    ,    1	)


