


'''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__				( __UpperCAmelCase      ):







				"""simple docstring"""



				__UpperCamelCase    :		List[str]	=	"Wav2Vec2FeatureExtractor"
				__UpperCamelCase    :		List[Any]	=	"AutoTokenizer"




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




				@classmethod
				def 					_snake_case  (cls       ,			__lowercase       ,			**__lowercase		):
										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       ,			*__lowercase       ,			**__lowercase		):
										# 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 					_snake_case  (self       ,			*__lowercase       ,			**__lowercase		):
										# 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 					_snake_case  (self       ,			*__lowercase       ,			**__lowercase		):
										return self.tokenizer.batch_decode(*_lowerCamelCase       ,			**_lowerCamelCase		)




				def 					_snake_case  (self       ,			*__lowercase       ,			**__lowercase		):
										return self.tokenizer.decode(*_lowerCamelCase       ,			**_lowerCamelCase		)




				@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







'''simple docstring'''

import numpy as np

from transformers import Pipeline

def 							__magic_name__(						lowerCamelCase):
						__lowerCAmelCase							       =				np.max(lowerCamelCase,				axis=-1,				keepdims=lowerCamelCase)
						__lowerCAmelCase							       =				np.exp(outputs - maxes)
						return shifted_exp / shifted_exp.sum(axis=-1,				keepdims=lowerCamelCase)




class       a__				( __A      ):







				"""simple docstring"""



				def 					_snake_case  (self       ,			**__lowercase		):
										__lowerCAmelCase							       =				{}
										if "second_text" in kwargs:
																__lowerCAmelCase							       =				kwargs['''second_text''']
										return preprocess_kwargs, {}, {}




				def 					_snake_case  (self       ,			__lowercase       ,			__lowercase=None		):
										return self.tokenizer(__lowercase       ,			text_pair=__lowercase       ,			return_tensors=self.framework		)




				def 					_snake_case  (self       ,			__lowercase		):
										return self.model(**__lowercase		)




				def 					_snake_case  (self       ,			__lowercase		):
										__lowerCAmelCase							       =				model_outputs.logits[0].numpy()
										__lowerCAmelCase							       =				softmax(__lowercase		)

										__lowerCAmelCase							       =				np.argmax(__lowercase		)
										__lowerCAmelCase							       =				self.model.config.idalabel[best_class]
										__lowerCAmelCase							       =				probabilities[best_class].item()
										__lowerCAmelCase							       =				logits.tolist()
										return {"label": label, "score": score, "logits": logits}

