


'''simple docstring'''






import warnings
from contextlib import contextmanager

from ...processing_utils import ProcessorMixin
from .feature_extraction_wavaveca import WavaVecaFeatureExtractor
from .tokenization_wavaveca import WavaVecaCTCTokenizer




class 	a__       (							a__						):





							'''simple docstring'''






							lowercase__    :     Dict					=   "Wav2Vec2FeatureExtractor"
							lowercase__    :     Optional[Any]					=   "AutoTokenizer"







							def __init__(	self      ,					lowerCamelCase_      ,					lowerCamelCase_     ) ->							Any:
														super().__init__(lowerCamelCase_      ,					lowerCamelCase_     )
														lowerCAmelCase__      =			self.feature_extractor
														lowerCAmelCase__      =			False







							@classmethod
							def 						__SCREAMING_SNAKE_CASE							(	cls      ,					lowerCamelCase_      ,					**lowerCamelCase_     ) ->							List[Any]:
														try:
																					return super().from_pretrained(lowerCamelCase_      ,					**lowerCamelCase_     )
														except OSError:
																					warnings.warn(
																					    F"""Loading a tokenizer inside {cls.__name__} from a config that does not"""
																					    ''' include a `tokenizer_class` attribute is deprecated and will be '''
																					    '''removed in v5. Please add `\'tokenizer_class\': \'Wav2Vec2CTCTokenizer\'`'''
																					    ''' attribute to either your `config.json` or `tokenizer_config.json` '''
																					    '''file to suppress this warning: '''      ,					lowerCamelCase_      ,					)

																					lowerCAmelCase__      =			WavaVecaFeatureExtractor.from_pretrained(lowerCamelCase_      ,					**lowerCamelCase_     )
																					lowerCAmelCase__      =			WavaVecaCTCTokenizer.from_pretrained(lowerCamelCase_      ,					**lowerCamelCase_     )

																					return cls(feature_extractor=lowerCamelCase_      ,					tokenizer=lowerCamelCase_     )







							def __call__(	self      ,					*lowerCamelCase_      ,					**lowerCamelCase_     ) ->							Any:
														# For backward compatibility
														if self._in_target_context_manager:
																					return self.current_processor(*lowerCamelCase_      ,					**lowerCamelCase_     )

														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'''      ,					lowerCamelCase_     )
														lowerCAmelCase__      =			kwargs.pop('''sampling_rate'''      ,					lowerCamelCase_     )
														lowerCAmelCase__      =			kwargs.pop('''text'''      ,					lowerCamelCase_     )
														if len(lowerCamelCase_     ) > 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(lowerCamelCase_      ,					*lowerCamelCase_      ,					sampling_rate=lowerCamelCase_      ,					**lowerCamelCase_     )
														if text is not None:
																					lowerCAmelCase__      =			self.tokenizer(lowerCamelCase_      ,					**lowerCamelCase_     )

														if text is None:
																					return inputs
														elif audio is None:
																					return encodings
														else:
																					lowerCAmelCase__      =			encodings['''input_ids''']
																					return inputs







							def 						__SCREAMING_SNAKE_CASE							(	self      ,					*lowerCamelCase_      ,					**lowerCamelCase_     ) ->							Any:
														# For backward compatibility
														if self._in_target_context_manager:
																					return self.current_processor.pad(*lowerCamelCase_      ,					**lowerCamelCase_     )

														lowerCAmelCase__      =			kwargs.pop('''input_features'''      ,					lowerCamelCase_     )
														lowerCAmelCase__      =			kwargs.pop('''labels'''      ,					lowerCamelCase_     )
														if len(lowerCamelCase_     ) > 0:
																					lowerCAmelCase__      =			args[0]
																					lowerCAmelCase__      =			args[1:]

														if input_features is not None:
																					lowerCAmelCase__      =			self.feature_extractor.pad(lowerCamelCase_      ,					*lowerCamelCase_      ,					**lowerCamelCase_     )
														if labels is not None:
																					lowerCAmelCase__      =			self.tokenizer.pad(lowerCamelCase_      ,					**lowerCamelCase_     )

														if labels is None:
																					return input_features
														elif input_features is None:
																					return labels
														else:
																					lowerCAmelCase__      =			labels['''input_ids''']
																					return input_features







							def 						__SCREAMING_SNAKE_CASE							(	self      ,					*lowerCamelCase_      ,					**lowerCamelCase_     ) ->							Tuple:
														return self.tokenizer.batch_decode(*lowerCamelCase_      ,					**lowerCamelCase_     )







							def 						__SCREAMING_SNAKE_CASE							(	self      ,					*lowerCamelCase_      ,					**lowerCamelCase_     ) ->							Tuple:
														return self.tokenizer.decode(*lowerCamelCase_      ,					**lowerCamelCase_     )







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



'''simple docstring'''






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


__UpperCAmelCase					       =							logging.get_logger(__name__)

__UpperCAmelCase					       =							{'''ctrl''': '''https://huggingface.co/ctrl/resolve/main/config.json'''}




class 	a__       (							a__						):





							'''simple docstring'''






							lowercase__    :     Dict					=   "ctrl"
							lowercase__    :     str					=   ["past_key_values"]
							lowercase__    :     Optional[int]					=   {
							    "max_position_embeddings": "n_positions",
							    "hidden_size": "n_embd",
							    "num_attention_heads": "n_head",
							    "num_hidden_layers": "n_layer",
							}







							def __init__(	self      ,					lowerCamelCase_=24_65_34      ,					lowerCamelCase_=2_56      ,					lowerCamelCase_=12_80      ,					lowerCamelCase_=81_92      ,					lowerCamelCase_=48      ,					lowerCamelCase_=16      ,					lowerCamelCase_=0.1      ,					lowerCamelCase_=0.1      ,					lowerCamelCase_=1e-6      ,					lowerCamelCase_=0.02      ,					lowerCamelCase_=True      ,					**lowerCamelCase_      ,					) ->							Union[str, Any]:
														lowerCAmelCase__      =			vocab_size
														lowerCAmelCase__      =			n_positions
														lowerCAmelCase__      =			n_embd
														lowerCAmelCase__      =			n_layer
														lowerCAmelCase__      =			n_head
														lowerCAmelCase__      =			dff
														lowerCAmelCase__      =			resid_pdrop
														lowerCAmelCase__      =			embd_pdrop
														lowerCAmelCase__      =			layer_norm_epsilon
														lowerCAmelCase__      =			initializer_range

														lowerCAmelCase__      =			use_cache

														super().__init__(**lowerCamelCase_     )