
'''simple docstring'''






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


UpperCAmelCase_							: Dict =							logging.get_logger(__name__)

UpperCAmelCase_							: Any =							{
    'microsoft/trocr-base-handwritten': (
        'https://huggingface.co/microsoft/trocr-base-handwritten/resolve/main/config.json'
    ),
    # See all TrOCR models at https://huggingface.co/models?filter=trocr
}

class 			UpperCAmelCase__    (							A			):
    lowerCAmelCase_					     =		'trocr'
    lowerCAmelCase_					     =		['past_key_values']
    lowerCAmelCase_					     =		{
        'num_attention_heads': 'decoder_attention_heads',
        'hidden_size': 'd_model',
        'num_hidden_layers': 'decoder_layers',
    }



    def __init__(						self   :							List[Any],__A   :							int=5_0_2_6_5,__A   :							Union[str, Any]=1_0_2_4,__A   :							Any=1_2,__A   :							Any=1_6,__A   :							List[str]=4_0_9_6,__A   :							Tuple="gelu",__A   :							List[str]=5_1_2,__A   :							Tuple=0.1,__A   :							str=0.0,__A   :							Tuple=0.0,__A   :							List[Any]=2,__A   :							List[Any]=0.02,__A   :							Union[str, Any]=0.0,__A   :							Optional[int]=True,__A   :							List[Any]=False,__A   :							int=True,__A   :							Optional[int]=True,__A   :							List[str]=1,__A   :							Tuple=0,__A   :							Tuple=2,**__A   :							List[Any],):
          _lowerCamelCase					: Optional[Any]		    = vocab_size
          _lowerCamelCase					: str		    = d_model
          _lowerCamelCase					: Dict		    = decoder_layers
          _lowerCamelCase					: Dict		    = decoder_attention_heads
          _lowerCamelCase					: Union[str, Any]		    = decoder_ffn_dim
          _lowerCamelCase					: int		    = activation_function
          _lowerCamelCase					: Union[str, Any]		    = max_position_embeddings
          _lowerCamelCase					: Optional[int]		    = dropout
          _lowerCamelCase					: Any		    = attention_dropout
          _lowerCamelCase					: Tuple		    = activation_dropout
          _lowerCamelCase					: Dict		    = init_std
          _lowerCamelCase					: str		    = decoder_layerdrop
          _lowerCamelCase					: Optional[int]		    = use_cache
          _lowerCamelCase					: Any		    = scale_embedding
          _lowerCamelCase					: int		    = use_learned_position_embeddings
          _lowerCamelCase					: Optional[int]		    = layernorm_embedding

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



"""simple docstring"""


import warnings
from contextlib import contextmanager

from ...processing_utils import ProcessorMixin
class     _UpperCamelCase    (  lowerCAmelCase__						):
							'''simple docstring'''







							__UpperCAmelCase		:       List[str]							 ="""Speech2TextFeatureExtractor"""
							__UpperCAmelCase		:       Union[str, Any]							 ="""Speech2TextTokenizer"""

							def __init__(	self       ,  __a       ,  __a      ):
										super().__init__(__a       ,  __a      )
										__lowerCAmelCase							       =     self.feature_extractor
										__lowerCAmelCase							       =     False

							def __call__(	self       ,  *__a       ,  **__a      ):
										# For backward compatibility
										if self._in_target_context_manager:
													return self.current_processor(*__a       ,  **__a      )

										if "raw_speech" in kwargs:
													warnings.warn("Using `raw_speech` as a keyword argument is deprecated. Use `audio` instead."      )
													__lowerCAmelCase							       =     kwargs.pop("raw_speech"      )
										else:
													__lowerCAmelCase							       =     kwargs.pop("audio"       ,  __a      )
										__lowerCAmelCase							       =     kwargs.pop("sampling_rate"       ,  __a      )
										__lowerCAmelCase							       =     kwargs.pop("text"       ,  __a      )
										if len(__a      ) > 0:
													__lowerCAmelCase							       =     args[0]
													__lowerCAmelCase							       =     args[1:]

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

										if audio is not None:
													__lowerCAmelCase							       =     self.feature_extractor(__a       ,  *__a       ,  sampling_rate=__a       ,  **__a      )
										if text is not None:
													__lowerCAmelCase							       =     self.tokenizer(__a       ,  **__a      )

										if text is None:
													return inputs
										elif audio is None:
													return encodings
										else:
													__lowerCAmelCase							       =     encodings["input_ids"]
													return inputs

							def      snake_case							(	self       ,  *__a       ,  **__a      ):
										return self.tokenizer.batch_decode(*__a       ,  **__a      )

							def      snake_case							(	self       ,  *__a       ,  **__a      ):
										return self.tokenizer.decode(*__a       ,  **__a      )



							@contextmanager
							def      snake_case							(	self      ):
										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 audio inputs, or in a separate call."      )
										__lowerCAmelCase							       =     True
										__lowerCAmelCase							       =     self.tokenizer
										yield
										__lowerCAmelCase							       =     self.feature_extractor
										__lowerCAmelCase							       =     False




