'''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   a__				(       UpperCAmelCase__			):
     lowerCamelCase  :					List[Any]							=["image_processor", "tokenizer"]
     lowerCamelCase  :					Union[str, Any]							="LayoutLMv2ImageProcessor"
     lowerCamelCase  :					List[Any]							=("LayoutXLMTokenizer", "LayoutXLMTokenizerFast")






     def __init__(			self		:		Optional[int]  ,    a		:		Tuple=None  ,    a		:		Union[str, Any]=None  ,    **a		:		Dict   ):





         """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.'''  ,    a  ,    )
             __lowerCamelCase          =  kwargs.pop('''feature_extractor'''   )

         __lowerCamelCase          =  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__(a  ,    a   )






     def __call__(			self		:		Optional[Any]  ,    a		:		str  ,    a		:		Union[TextInput, PreTokenizedInput, List[TextInput], List[PreTokenizedInput]] = None  ,    a		:		Optional[Union[PreTokenizedInput, List[PreTokenizedInput]]] = None  ,    a		:		Union[List[List[int]], List[List[List[int]]]] = None  ,    a		:		Optional[Union[List[int], List[List[int]]]] = None  ,    a		:		bool = True  ,    a		:		Union[bool, str, PaddingStrategy] = False  ,    a		:		Union[bool, str, TruncationStrategy] = None  ,    a		:		Optional[int] = None  ,    a		:		int = 0  ,    a		:		Optional[int] = None  ,    a		:		Optional[bool] = None  ,    a		:		Optional[bool] = None  ,    a		:		bool = False  ,    a		:		bool = False  ,    a		:		bool = False  ,    a		:		bool = False  ,    a		:		bool = True  ,    a		:		Optional[Union[str, TensorType]] = None  ,    **a		:		Dict  ,    ):





         """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
         __lowerCamelCase          =  self.image_processor(images=a  ,    return_tensors=a   )

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

         __lowerCamelCase          =  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=a  ,    add_special_tokens=a  ,    padding=a  ,    truncation=a  ,    max_length=a  ,    stride=a  ,    pad_to_multiple_of=a  ,    return_token_type_ids=a  ,    return_attention_mask=a  ,    return_overflowing_tokens=a  ,    return_special_tokens_mask=a  ,    return_offsets_mapping=a  ,    return_length=a  ,    verbose=a  ,    return_tensors=a  ,    **a  ,    )

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

         return encoded_inputs






     def        SCREAMING_SNAKE_CASE__       (			self		:		Union[str, Any]  ,    a		:		str  ,    a		:		List[Any]   ):





         """simple docstring"""



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

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

         return images_with_overflow






     def        SCREAMING_SNAKE_CASE__       (			self		:		Any  ,    *a		:		Dict  ,    **a		:		Dict   ):





         """simple docstring"""



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






     def        SCREAMING_SNAKE_CASE__       (			self		:		Tuple  ,    *a		:		List[Any]  ,    **a		:		Dict   ):





         """simple docstring"""



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






     @property
     def        SCREAMING_SNAKE_CASE__       (			self		:		Optional[int]   ):





         """simple docstring"""



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






     @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.'''  ,    a  ,    )
         return self.image_processor_class






     @property
     def        SCREAMING_SNAKE_CASE__       (			self		:		List[str]   ):





         """simple docstring"""



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

'''simple docstring'''




import functools
import operator

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


__UpperCAmelCase												=logging.get_logger(__name__)

__UpperCAmelCase												={
    "microsoft/unispeech-sat-base-100h-libri-ft": (
        "https://huggingface.co/microsoft/unispeech-sat-base-100h-libri-ft/resolve/main/config.json"
    ),
    # See all UniSpeechSat models at https://huggingface.co/models?filter=unispeech_sat
}




class    a__				(       UpperCAmelCase__			):
     lowerCamelCase  :					List[Any]							="unispeech-sat"






     def __init__(			self		:		Dict  ,    a		:		str=32  ,    a		:		Any=7_68  ,    a		:		Optional[Any]=12  ,    a		:		Optional[int]=12  ,    a		:		int=30_72  ,    a		:		int="gelu"  ,    a		:		Dict=0.1  ,    a		:		Dict=0.1  ,    a		:		List[Any]=0.1  ,    a		:		Tuple=0.0  ,    a		:		Optional[Any]=0.0  ,    a		:		Tuple=0.1  ,    a		:		List[Any]=0.1  ,    a		:		str=0.02  ,    a		:		List[Any]=1e-5  ,    a		:		int="group"  ,    a		:		Union[str, Any]="gelu"  ,    a		:		Optional[int]=(5_12, 5_12, 5_12, 5_12, 5_12, 5_12, 5_12)  ,    a		:		List[Any]=(5, 2, 2, 2, 2, 2, 2)  ,    a		:		int=(10, 3, 3, 3, 3, 2, 2)  ,    a		:		Optional[Any]=False  ,    a		:		Any=1_28  ,    a		:		Tuple=16  ,    a		:		str=False  ,    a		:		Optional[Any]=True  ,    a		:		Dict=0.05  ,    a		:		List[Any]=10  ,    a		:		Any=2  ,    a		:		Optional[Any]=0.0  ,    a		:		Optional[Any]=10  ,    a		:		Any=0  ,    a		:		Any=3_20  ,    a		:		str=2  ,    a		:		List[str]=0.1  ,    a		:		List[str]=1_00  ,    a		:		List[str]=2_56  ,    a		:		str=2_56  ,    a		:		Dict=0.1  ,    a		:		Optional[Any]="mean"  ,    a		:		str=False  ,    a		:		Tuple=False  ,    a		:		Optional[Any]=2_56  ,    a		:		int=(5_12, 5_12, 5_12, 5_12, 15_00)  ,    a		:		int=(5, 3, 3, 1, 1)  ,    a		:		Any=(1, 2, 3, 1, 1)  ,    a		:		Union[str, Any]=5_12  ,    a		:		Optional[int]=0  ,    a		:		Optional[int]=1  ,    a		:		Optional[int]=2  ,    a		:		int=5_04  ,    **a		:		Dict  ,    ):





         """simple docstring"""



         super().__init__(**a  ,    pad_token_id=a  ,    bos_token_id=a  ,    eos_token_id=a   )
         __lowerCamelCase          =  hidden_size
         __lowerCamelCase          =  feat_extract_norm
         __lowerCamelCase          =  feat_extract_activation
         __lowerCamelCase          =  list(a   )
         __lowerCamelCase          =  list(a   )
         __lowerCamelCase          =  list(a   )
         __lowerCamelCase          =  conv_bias
         __lowerCamelCase          =  num_conv_pos_embeddings
         __lowerCamelCase          =  num_conv_pos_embedding_groups
         __lowerCamelCase          =  len(self.conv_dim   )
         __lowerCamelCase          =  num_hidden_layers
         __lowerCamelCase          =  intermediate_size
         __lowerCamelCase          =  hidden_act
         __lowerCamelCase          =  num_attention_heads
         __lowerCamelCase          =  hidden_dropout
         __lowerCamelCase          =  attention_dropout
         __lowerCamelCase          =  activation_dropout
         __lowerCamelCase          =  feat_proj_dropout
         __lowerCamelCase          =  final_dropout
         __lowerCamelCase          =  layerdrop
         __lowerCamelCase          =  layer_norm_eps
         __lowerCamelCase          =  initializer_range
         __lowerCamelCase          =  vocab_size
         __lowerCamelCase          =  num_clusters
         __lowerCamelCase          =  do_stable_layer_norm
         __lowerCamelCase          =  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
         __lowerCamelCase          =  apply_spec_augment
         __lowerCamelCase          =  mask_time_prob
         __lowerCamelCase          =  mask_time_length
         __lowerCamelCase          =  mask_time_min_masks
         __lowerCamelCase          =  mask_feature_prob
         __lowerCamelCase          =  mask_feature_length
         __lowerCamelCase          =  mask_feature_min_masks

         # parameters for pretraining with codevector quantized representations
         __lowerCamelCase          =  num_codevectors_per_group
         __lowerCamelCase          =  num_codevector_groups
         __lowerCamelCase          =  contrastive_logits_temperature
         __lowerCamelCase          =  feat_quantizer_dropout
         __lowerCamelCase          =  num_negatives
         __lowerCamelCase          =  codevector_dim
         __lowerCamelCase          =  proj_codevector_dim
         __lowerCamelCase          =  diversity_loss_weight

         # ctc loss
         __lowerCamelCase          =  ctc_loss_reduction
         __lowerCamelCase          =  ctc_zero_infinity

         # SequenceClassification-specific parameter. Feel free to ignore for other classes.
         __lowerCamelCase          =  classifier_proj_size

         # XVector-specific parameters. Feel free to ignore for other classes.
         __lowerCamelCase          =  list(a   )
         __lowerCamelCase          =  list(a   )
         __lowerCamelCase          =  list(a   )
         __lowerCamelCase          =  xvector_output_dim






     @property
     def        SCREAMING_SNAKE_CASE__       (			self		:		Any   ):





         """simple docstring"""



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