



'''simple docstring'''







from typing import List, Optional, Union

import numpy as np

from ...feature_extraction_sequence_utils import SequenceFeatureExtractor
from ...feature_extraction_utils import BatchFeature
from ...utils import PaddingStrategy, TensorType, logging


_UpperCamelCase  						=			logging.get_logger(__name__)

class      lowerCamelCase__     (     _lowercase				):






	'''simple docstring'''

	A__		=	['''input_values''', '''attention_mask''']




	def __init__(  self		:  Dict   ,		__A		:  Optional[Any]=1   ,		__A		:  Any=1_6000   ,		__A		:  List[str]=0.0   ,		__A		:  List[str]=False   ,		__A		:  Optional[Any]=True   ,		**__A		:  List[str]   ,		)     ->			Optional[int]:




								'''simple docstring'''





								super().__init__(feature_size=__a   ,		sampling_rate=__a   ,		padding_value=__a   ,		**__a					)
								lowerCAmelCase__  =   return_attention_mask
								lowerCAmelCase__  =   do_normalize




	@staticmethod
	def      lowercase__							(  __A		:  List[str]   ,		__A		:  Union[str, Any]   ,		__A		:  int = 0.0					)     ->			List[np.ndarray]:




								'''simple docstring'''





								if attention_mask is not None:
															lowerCAmelCase__  =   np.array(__a   ,		np.intaa					)
															lowerCAmelCase__  =   []

															for vector, length in zip(__a   ,		attention_mask.sum(-1					)					):
																						lowerCAmelCase__  =   (vector - vector[:length].mean()) / np.sqrt(vector[:length].var() + 1E-7					)
																						if length < normed_slice.shape[0]:
																													lowerCAmelCase__  =   padding_value

																						normed_input_values.append(__a					)
								else:
															lowerCAmelCase__  =   [(x - x.mean()) / np.sqrt(x.var() + 1E-7					) for x in input_values]

								return normed_input_values




	def __call__(  self		:  Optional[int]   ,		__A		:  Any   ,		__A		:  str = False   ,		__A		:  int = None   ,		__A		:  str = False   ,		__A		:  List[str] = None   ,		__A		:  List[str] = None   ,		__A		:  str = None   ,		__A		:  List[str] = None   ,		**__A		:  Any   ,		)     ->			BatchFeature:




								'''simple docstring'''





								if sampling_rate is not None:
															if sampling_rate != self.sampling_rate:
																						raise ValueError(
																						    f'''The model corresponding to this feature extractor: {self} was trained using a sampling rate of'''
																						    f''' {self.sampling_rate}. Please make sure that the provided `raw_speech` input was sampled with'''
																						    f''' {self.sampling_rate} and not {sampling_rate}.'''					)
								else:
															logger.warning(
															    """It is strongly recommended to pass the ``sampling_rate`` argument to this function. """
															    """Failing to do so can result in silent errors that might be hard to debug."""					)

								lowerCAmelCase__  =   isinstance(__a   ,		np.ndarray					) and len(raw_speech.shape					) > 1
								if is_batched_numpy and len(raw_speech.shape					) > 2:
															raise ValueError(f'''Only mono-channel audio is supported for input to {self}'''					)
								lowerCAmelCase__  =   is_batched_numpy or (
								    isinstance(__a   ,		(list, tuple)					) and (isinstance(raw_speech[0]   ,		(np.ndarray, tuple, list)					))
								)

								# always return batch
								if not is_batched:
															lowerCAmelCase__  =   [raw_speech]

								# convert into correct format for padding
								lowerCAmelCase__  =   BatchFeature({"""input_values""": raw_speech}					)

								lowerCAmelCase__  =   self.pad(
								    __a   ,		padding=__a   ,		max_length=__a   ,		truncation=__a   ,		pad_to_multiple_of=__a   ,		return_attention_mask=__a   ,		)

								# convert input values to correct format
								lowerCAmelCase__  =   padded_inputs["""input_values"""]
								if not isinstance(input_values[0]   ,		np.ndarray					):
															lowerCAmelCase__  =   [np.asarray(__a   ,		dtype=np.floataa					) for array in input_values]
								elif (
								    not isinstance(__a   ,		np.ndarray					)
								    and isinstance(input_values[0]   ,		np.ndarray					)
								    and input_values[0].dtype is np.dtype(np.floataa					)
								):
															lowerCAmelCase__  =   [array.astype(np.floataa					) for array in input_values]
								elif isinstance(__a   ,		np.ndarray					) and input_values.dtype is np.dtype(np.floataa					):
															lowerCAmelCase__  =   input_values.astype(np.floataa					)

								# convert attention_mask to correct format
								lowerCAmelCase__  =   padded_inputs.get("""attention_mask"""					)
								if attention_mask is not None:
															lowerCAmelCase__  =   [np.asarray(__a   ,		dtype=np.intaa					) for array in attention_mask]

								# zero-mean and unit-variance normalization
								if self.do_normalize:
															lowerCAmelCase__  =   (
															    attention_mask
															    if self._get_padding_strategies(__a   ,		max_length=__a					) is not PaddingStrategy.DO_NOT_PAD
															    else None
															)
															lowerCAmelCase__  =   self.zero_mean_unit_var_norm(
															    padded_inputs["""input_values"""]   ,		attention_mask=__a   ,		padding_value=self.padding_value					)

								if return_tensors is not None:
															lowerCAmelCase__  =   padded_inputs.convert_to_tensors(__a					)

								return padded_inputs












"""simple docstring"""





from typing import TYPE_CHECKING

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


lowerCAmelCase__        =      {
    '''configuration_openai''': ['''OPENAI_GPT_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''OpenAIGPTConfig'''],
    '''tokenization_openai''': ['''OpenAIGPTTokenizer'''],
}

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

try:
						if not is_torch_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						lowerCAmelCase__        =      [
						    '''OPENAI_GPT_PRETRAINED_MODEL_ARCHIVE_LIST''',
						    '''OpenAIGPTDoubleHeadsModel''',
						    '''OpenAIGPTForSequenceClassification''',
						    '''OpenAIGPTLMHeadModel''',
						    '''OpenAIGPTModel''',
						    '''OpenAIGPTPreTrainedModel''',
						    '''load_tf_weights_in_openai_gpt''',
						]

try:
						if not is_tf_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						lowerCAmelCase__        =      [
						    '''TF_OPENAI_GPT_PRETRAINED_MODEL_ARCHIVE_LIST''',
						    '''TFOpenAIGPTDoubleHeadsModel''',
						    '''TFOpenAIGPTForSequenceClassification''',
						    '''TFOpenAIGPTLMHeadModel''',
						    '''TFOpenAIGPTMainLayer''',
						    '''TFOpenAIGPTModel''',
						    '''TFOpenAIGPTPreTrainedModel''',
						]


if TYPE_CHECKING:
						from .configuration_openai import OPENAI_GPT_PRETRAINED_CONFIG_ARCHIVE_MAP, OpenAIGPTConfig
						from .tokenization_openai import OpenAIGPTTokenizer

						try:
												if not is_tokenizers_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .tokenization_openai_fast import OpenAIGPTTokenizerFast

						try:
												if not is_torch_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .modeling_openai import (
												    OPENAI_GPT_PRETRAINED_MODEL_ARCHIVE_LIST,
												    OpenAIGPTDoubleHeadsModel,
												    OpenAIGPTForSequenceClassification,
												    OpenAIGPTLMHeadModel,
												    OpenAIGPTModel,
												    OpenAIGPTPreTrainedModel,
												    load_tf_weights_in_openai_gpt,
												)

						try:
												if not is_tf_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .modeling_tf_openai import (
												    TF_OPENAI_GPT_PRETRAINED_MODEL_ARCHIVE_LIST,
												    TFOpenAIGPTDoubleHeadsModel,
												    TFOpenAIGPTForSequenceClassification,
												    TFOpenAIGPTLMHeadModel,
												    TFOpenAIGPTMainLayer,
												    TFOpenAIGPTModel,
												    TFOpenAIGPTPreTrainedModel,
												)

else:
						import sys

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






