





import re
import warnings
from contextlib import contextmanager

from ...processing_utils import ProcessorMixin







class    __snake_case	(							__lowerCamelCase      ):





       '''simple docstring'''







       lowerCAmelCase__						=					["""image_processor""", """tokenizer"""]
       lowerCAmelCase__						=					"""AutoImageProcessor"""
       lowerCAmelCase__						=					"""AutoTokenizer"""




       def __init__(  self			:   List[str]							,    A			:   Dict=None							,    A			:   Optional[int]=None							,    **A			:   Union[str, Any]		):
         __snake_case:						Optional[Any]			  =						None
         if "feature_extractor" in kwargs:
           warnings.warn(
               """The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor`"""
               """ instead."""							,    __a							,    )
           __snake_case:						Tuple			  =						kwargs.pop("""feature_extractor"""		)

         __snake_case:						Union[str, Any]			  =						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		)
         __snake_case:						Dict			  =						self.image_processor
         __snake_case:						Optional[Any]			  =						False




       def __call__(  self			:   Optional[Any]							,    *A			:   List[str]							,    **A			:   Tuple		):
         # For backward compatibility
         if self._in_target_context_manager:
           return self.current_processor(*__a							,    **__a		)

         __snake_case:						Tuple			  =						kwargs.pop("""images"""							,    __a		)
         __snake_case:						Any			  =						kwargs.pop("""text"""							,    __a		)
         if len(__a		) > 0:
           __snake_case:						Any			  =						args[0]
           __snake_case:						Any			  =						args[1:]

         if images is None and text is None:
           raise ValueError("""You need to specify either an `images` or `text` input to process."""		)

         if images is not None:
           __snake_case:						List[str]			  =						self.image_processor(__a							,    *__a							,    **__a		)
         if text is not None:
           __snake_case:						int			  =						self.tokenizer(__a							,    **__a		)

         if text is None:
           return inputs
         elif images is None:
           return encodings
         else:
           __snake_case:						Optional[Any]			  =						encodings["""input_ids"""]
           return inputs




       def 							UpperCAmelCase__			(  self			:   Union[str, Any]							,    *A			:   Optional[int]							,    **A			:   int		):
         return self.tokenizer.batch_decode(*__a							,    **__a		)




       def 							UpperCAmelCase__			(  self			:   List[str]							,    *A			:   Any							,    **A			:   Optional[int]		):
         return self.tokenizer.decode(*__a							,    **__a		)




       @contextmanager
       def 							UpperCAmelCase__			(  self			:   List[str]		):
         warnings.warn(
             """`as_target_processor` is deprecated and will be removed in v5 of Transformers. You can process your """
             """labels by using the argument `text` of the regular `__call__` method (either in the same call as """
             """your images inputs, or in a separate call."""		)
         __snake_case:						int			  =						True
         __snake_case:						Dict			  =						self.tokenizer
         yield
         __snake_case:						Dict			  =						self.image_processor
         __snake_case:						Dict			  =						False




       def 							UpperCAmelCase__			(  self			:   Optional[Any]							,    A			:   int							,    A			:   Optional[Any]=False							,    A			:   Optional[int]=None		):
         if added_vocab is None:
           __snake_case:						Tuple			  =						self.tokenizer.get_added_vocab()

         __snake_case:						Tuple			  =						{}

         while tokens:
           __snake_case:						Tuple			  =						re.search(r"""<s_(.*?)>"""							,    __a							,    re.IGNORECASE		)
           if start_token is None:
             break
           __snake_case:						str			  =						start_token.group(1		)
           __snake_case:						Any			  =						re.search(rf'''</s_{key}>'''							,    __a							,    re.IGNORECASE		)
           __snake_case:						Optional[Any]			  =						start_token.group()
           if end_token is None:
             __snake_case:						str			  =						tokens.replace(__a							,    """"""		)
           else:
             __snake_case:						int			  =						end_token.group()
             __snake_case:						Union[str, Any]			  =						re.escape(__a		)
             __snake_case:						Optional[Any]			  =						re.escape(__a		)
             __snake_case:						List[str]			  =						re.search(f'''{start_token_escaped}(.*?){end_token_escaped}'''							,    __a							,    re.IGNORECASE		)
             if content is not None:
               __snake_case:						str			  =						content.group(1		).strip()
               if r"<s_" in content and r"</s_" in content:  # non-leaf node
                 __snake_case:						Optional[int]			  =						self.tokenajson(__a							,    is_inner_value=__a							,    added_vocab=__a		)
                 if value:
                   if len(__a		) == 1:
                     __snake_case:						List[Any]			  =						value[0]
                   __snake_case:						Dict			  =						value
               else:  # leaf nodes
                 __snake_case:						str			  =						[]
                 for leaf in content.split(r"""<sep/>"""		):
                   __snake_case:						Tuple			  =						leaf.strip()
                   if leaf in added_vocab and leaf[0] == "<" and leaf[-2:] == "/>":
                     __snake_case:						Tuple			  =						leaf[1:-2]  # for categorical special tokens
                   output[key].append(__a		)
                 if len(output[key]		) == 1:
                   __snake_case:						Any			  =						output[key][0]

             __snake_case:						Optional[int]			  =						tokens[tokens.find(__a		) + len(__a		) :].strip()
             if tokens[:6] == r"<sep/>":  # non-leaf nodes
               return [output] + self.tokenajson(tokens[6:]							,    is_inner_value=__a							,    added_vocab=__a		)

         if len(__a		):
           return [output] if is_inner_value else output
         else:
           return [] if is_inner_value else {"text_sequence": tokens}




       @property
       def 							UpperCAmelCase__			(  self			:   Tuple		):
         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 							UpperCAmelCase__			(  self			:   str		):
         warnings.warn(
             """`feature_extractor` is deprecated and will be removed in v5. Use `image_processor` instead."""							,    __a							,    )
         return self.image_processor













import functools
import operator

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


__UpperCAmelCase	:       Optional[Any]    	=							logging.get_logger(__name__)

__UpperCAmelCase	:       Union[str, Any]    	=							{
    "asapp/sew-d-tiny-100k": "https://huggingface.co/asapp/sew-d-tiny-100k/resolve/main/config.json",
    # See all SEW-D models at https://huggingface.co/models?filter=sew-d
}







class    __snake_case	(							__lowerCamelCase      ):





       '''simple docstring'''







       lowerCAmelCase__						=					"""sew-d"""




       def __init__(  self			:   Dict							,    A			:   Any=32							,    A			:   Dict=768							,    A			:   Optional[Any]=12							,    A			:   Union[str, Any]=12							,    A			:   Union[str, Any]=3_072							,    A			:   Optional[Any]=2							,    A			:   Union[str, Any]=512							,    A			:   List[Any]=256							,    A			:   Dict=True							,    A			:   Union[str, Any]=True							,    A			:   Optional[int]=("p2c", "c2p")							,    A			:   str="layer_norm"							,    A			:   Dict="gelu_python"							,    A			:   Tuple=0.1							,    A			:   Any=0.1							,    A			:   Tuple=0.1							,    A			:   Optional[int]=0.0							,    A			:   Any=0.1							,    A			:   Any=0.02							,    A			:   Dict=1E-7							,    A			:   str=1E-5							,    A			:   int="group"							,    A			:   int="gelu"							,    A			:   str=(64, 128, 128, 128, 128, 256, 256, 256, 256, 512, 512, 512, 512)							,    A			:   Union[str, Any]=(5, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1)							,    A			:   List[Any]=(10, 3, 1, 3, 1, 3, 1, 3, 1, 2, 1, 2, 1)							,    A			:   Optional[int]=False							,    A			:   int=128							,    A			:   int=16							,    A			:   Optional[Any]=True							,    A			:   List[Any]=0.05							,    A			:   Any=10							,    A			:   Dict=2							,    A			:   List[Any]=0.0							,    A			:   Union[str, Any]=10							,    A			:   int=0							,    A			:   List[Any]="mean"							,    A			:   Union[str, Any]=False							,    A			:   Any=False							,    A			:   Optional[int]=256							,    A			:   List[Any]=0							,    A			:   Any=1							,    A			:   List[Any]=2							,    **A			:   List[Any]							,    ):
         super().__init__(**A							,    pad_token_id=A							,    bos_token_id=A							,    eos_token_id=A		)
         __snake_case:						Optional[int]			  =						hidden_size
         __snake_case:						str			  =						feat_extract_norm
         __snake_case:						int			  =						feat_extract_activation
         __snake_case:						str			  =						list(A		)
         __snake_case:						Any			  =						list(A		)
         __snake_case:						str			  =						list(A		)
         __snake_case:						Union[str, Any]			  =						conv_bias
         __snake_case:						int			  =						num_conv_pos_embeddings
         __snake_case:						str			  =						num_conv_pos_embedding_groups
         __snake_case:						List[Any]			  =						len(self.conv_dim		)
         __snake_case:						List[str]			  =						num_hidden_layers
         __snake_case:						Union[str, Any]			  =						intermediate_size
         __snake_case:						Dict			  =						squeeze_factor
         __snake_case:						List[Any]			  =						max_position_embeddings
         __snake_case:						List[Any]			  =						position_buckets
         __snake_case:						List[str]			  =						share_att_key
         __snake_case:						int			  =						relative_attention
         __snake_case:						Union[str, Any]			  =						norm_rel_ebd
         __snake_case:						List[str]			  =						list(A		)
         __snake_case:						Tuple			  =						hidden_act
         __snake_case:						List[Any]			  =						num_attention_heads
         __snake_case:						str			  =						hidden_dropout
         __snake_case:						int			  =						attention_dropout
         __snake_case:						Dict			  =						activation_dropout
         __snake_case:						Any			  =						feat_proj_dropout
         __snake_case:						int			  =						final_dropout
         __snake_case:						List[Any]			  =						layer_norm_eps
         __snake_case:						List[str]			  =						feature_layer_norm_eps
         __snake_case:						List[Any]			  =						initializer_range
         __snake_case:						List[Any]			  =						vocab_size

         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)`,"""
               f'''but is `len(config.conv_dim) = {len(self.conv_dim		)}`, `len(config.conv_stride)'''
               f'''= {len(self.conv_stride		)}`, `len(config.conv_kernel) = {len(self.conv_kernel		)}`.'''		)

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

         # ctc loss
         __snake_case:						Any			  =						ctc_loss_reduction
         __snake_case:						str			  =						ctc_zero_infinity

         # sequence classification
         __snake_case:						Optional[Any]			  =						use_weighted_layer_sum
         __snake_case:						List[Any]			  =						classifier_proj_size






       @property
       def 							UpperCAmelCase__			(  self			:   int		):
         return functools.reduce(operator.mul							,    self.conv_stride							,    1		)






