

'''simple docstring'''


from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_flax_available,
    is_tensorflow_text_available,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


lowerCAmelCase__										= {
    "configuration_bert": ["BERT_PRETRAINED_CONFIG_ARCHIVE_MAP", "BertConfig", "BertOnnxConfig"],
    "tokenization_bert": ["BasicTokenizer", "BertTokenizer", "WordpieceTokenizer"],
}

try:
						if not is_tokenizers_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						lowerCAmelCase__										= ["BertTokenizerFast"]

try:
						if not is_torch_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						lowerCAmelCase__										= [
						    "BERT_PRETRAINED_MODEL_ARCHIVE_LIST",
						    "BertForMaskedLM",
						    "BertForMultipleChoice",
						    "BertForNextSentencePrediction",
						    "BertForPreTraining",
						    "BertForQuestionAnswering",
						    "BertForSequenceClassification",
						    "BertForTokenClassification",
						    "BertLayer",
						    "BertLMHeadModel",
						    "BertModel",
						    "BertPreTrainedModel",
						    "load_tf_weights_in_bert",
						]

try:
						if not is_tf_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						lowerCAmelCase__										= [
						    "TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST",
						    "TFBertEmbeddings",
						    "TFBertForMaskedLM",
						    "TFBertForMultipleChoice",
						    "TFBertForNextSentencePrediction",
						    "TFBertForPreTraining",
						    "TFBertForQuestionAnswering",
						    "TFBertForSequenceClassification",
						    "TFBertForTokenClassification",
						    "TFBertLMHeadModel",
						    "TFBertMainLayer",
						    "TFBertModel",
						    "TFBertPreTrainedModel",
						]
try:
						if not is_tensorflow_text_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						lowerCAmelCase__										= ["TFBertTokenizer"]

try:
						if not is_flax_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						lowerCAmelCase__										= [
						    "FlaxBertForCausalLM",
						    "FlaxBertForMaskedLM",
						    "FlaxBertForMultipleChoice",
						    "FlaxBertForNextSentencePrediction",
						    "FlaxBertForPreTraining",
						    "FlaxBertForQuestionAnswering",
						    "FlaxBertForSequenceClassification",
						    "FlaxBertForTokenClassification",
						    "FlaxBertModel",
						    "FlaxBertPreTrainedModel",
						]

if TYPE_CHECKING:
						from .configuration_bert import BERT_PRETRAINED_CONFIG_ARCHIVE_MAP, BertConfig, BertOnnxConfig
						from .tokenization_bert import BasicTokenizer, BertTokenizer, WordpieceTokenizer

						try:
												if not is_tokenizers_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .tokenization_bert_fast import BertTokenizerFast

						try:
												if not is_torch_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .modeling_bert import (
												    BERT_PRETRAINED_MODEL_ARCHIVE_LIST,
												    BertForMaskedLM,
												    BertForMultipleChoice,
												    BertForNextSentencePrediction,
												    BertForPreTraining,
												    BertForQuestionAnswering,
												    BertForSequenceClassification,
												    BertForTokenClassification,
												    BertLayer,
												    BertLMHeadModel,
												    BertModel,
												    BertPreTrainedModel,
												    load_tf_weights_in_bert,
												)

						try:
												if not is_tf_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .modeling_tf_bert import (
												    TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST,
												    TFBertEmbeddings,
												    TFBertForMaskedLM,
												    TFBertForMultipleChoice,
												    TFBertForNextSentencePrediction,
												    TFBertForPreTraining,
												    TFBertForQuestionAnswering,
												    TFBertForSequenceClassification,
												    TFBertForTokenClassification,
												    TFBertLMHeadModel,
												    TFBertMainLayer,
												    TFBertModel,
												    TFBertPreTrainedModel,
												)

						try:
												if not is_tensorflow_text_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .tokenization_bert_tf import TFBertTokenizer

						try:
												if not is_flax_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .modeling_flax_bert import (
												    FlaxBertForCausalLM,
												    FlaxBertForMaskedLM,
												    FlaxBertForMultipleChoice,
												    FlaxBertForNextSentencePrediction,
												    FlaxBertForPreTraining,
												    FlaxBertForQuestionAnswering,
												    FlaxBertForSequenceClassification,
												    FlaxBertForTokenClassification,
												    FlaxBertModel,
												    FlaxBertPreTrainedModel,
												)

else:
						import sys

						lowerCAmelCase__										= _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)









'''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 					lowercase						(  a_ ):
							_lowerCamelCase		:      List[str]=   "Wav2Vec2FeatureExtractor"
							_lowerCamelCase		:      Any=   "AutoTokenizer"


							def __init__(			self    ,			_snake_case    ,			_snake_case)							->				List[str]:
								super().__init__(_snake_case    ,			_snake_case)
								UpperCAmelCase_		:      int       	=					self.feature_extractor
								UpperCAmelCase_		:      str       	=					False


							@classmethod
							def 						_snake_case							(			cls    ,			_snake_case    ,			**_snake_case)							->				List[Any]:
								try:
									return super().from_pretrained(_snake_case    ,			**_snake_case)
								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: '    ,			_snake_case    ,			)

									UpperCAmelCase_		:      Any       	=					WavaVecaFeatureExtractor.from_pretrained(_snake_case    ,			**_snake_case)
									UpperCAmelCase_		:      List[str]       	=					WavaVecaCTCTokenizer.from_pretrained(_snake_case    ,			**_snake_case)

									return cls(feature_extractor=_snake_case    ,			tokenizer=_snake_case)


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

								if "raw_speech" in kwargs:
									warnings.warn('Using `raw_speech` as a keyword argument is deprecated. Use `audio` instead.')
									UpperCAmelCase_		:      List[str]       	=					kwargs.pop('raw_speech')
								else:
									UpperCAmelCase_		:      Dict       	=					kwargs.pop('audio'    ,			_snake_case)
								UpperCAmelCase_		:      str       	=					kwargs.pop('sampling_rate'    ,			_snake_case)
								UpperCAmelCase_		:      List[str]       	=					kwargs.pop('text'    ,			_snake_case)
								if len(_snake_case) > 0:
									UpperCAmelCase_		:      List[str]       	=					args[0]
									UpperCAmelCase_		:      Tuple       	=					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:
									UpperCAmelCase_		:      Union[str, Any]       	=					self.feature_extractor(_snake_case    ,			*_snake_case    ,			sampling_rate=_snake_case    ,			**_snake_case)
								if text is not None:
									UpperCAmelCase_		:      Optional[int]       	=					self.tokenizer(_snake_case    ,			**_snake_case)

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


							def 						_snake_case							(			self    ,			*_snake_case    ,			**_snake_case)							->				str:
								# For backward compatibility
								if self._in_target_context_manager:
									return self.current_processor.pad(*_snake_case    ,			**_snake_case)

								UpperCAmelCase_		:      Union[str, Any]       	=					kwargs.pop('input_features'    ,			_snake_case)
								UpperCAmelCase_		:      Dict       	=					kwargs.pop('labels'    ,			_snake_case)
								if len(_snake_case) > 0:
									UpperCAmelCase_		:      Optional[Any]       	=					args[0]
									UpperCAmelCase_		:      int       	=					args[1:]

								if input_features is not None:
									UpperCAmelCase_		:      Dict       	=					self.feature_extractor.pad(_snake_case    ,			*_snake_case    ,			**_snake_case)
								if labels is not None:
									UpperCAmelCase_		:      Union[str, Any]       	=					self.tokenizer.pad(_snake_case    ,			**_snake_case)

								if labels is None:
									return input_features
								elif input_features is None:
									return labels
								else:
									UpperCAmelCase_		:      Union[str, Any]       	=					labels['input_ids']
									return input_features


							def 						_snake_case							(			self    ,			*_snake_case    ,			**_snake_case)							->				Dict:
								return self.tokenizer.batch_decode(*_snake_case    ,			**_snake_case)


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





							@contextmanager
							def 						_snake_case							(			self)							->				Tuple:
								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.')
								UpperCAmelCase_		:      Optional[Any]       	=					True
								UpperCAmelCase_		:      Tuple       	=					self.tokenizer
								yield
								UpperCAmelCase_		:      Tuple       	=					self.feature_extractor
								UpperCAmelCase_		:      Tuple       	=					False






