




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


__magic_name__     :     int  							=					logging.get_logger(__name__)





class 						SCREAMING_SNAKE_CASE__		(_a ):
     lowercase_   :			Tuple   =   ["input_values", "attention_mask"]
     def __init__(	self  :		str					,	__lowerCamelCase  :		Optional[int]=1					,	__lowerCamelCase  :		int=1_60_00					,	__lowerCamelCase  :		Any=0.0					,	__lowerCamelCase  :		List[Any]=False					,	__lowerCamelCase  :		List[str]=True					,	**__lowerCamelCase  :		Dict					,	):



       """simple docstring"""
       super().__init__(feature_size=__lowerCamelCase					,	sampling_rate=__lowerCamelCase					,	padding_value=__lowerCamelCase					,	**__lowerCamelCase	)
       lowerCAmelCase__								=			return_attention_mask
       lowerCAmelCase__								=			do_normalize
     @staticmethod
     def 					A__			(	__lowerCamelCase  :		List[np.ndarray]					,	__lowerCamelCase  :		List[np.ndarray]					,	__lowerCamelCase  :		float = 0.0	):



       """simple docstring"""
       if attention_mask is not None:
         lowerCAmelCase__								=			np.array(__lowerCamelCase					,	np.intaa	)
         lowerCAmelCase__								=			[]

         for vector, length in zip(__lowerCamelCase					,	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(__lowerCamelCase	)
       else:
         lowerCAmelCase__								=			[(x - x.mean()) / np.sqrt(x.var() + 1e-7	) for x in input_values]

       return normed_input_values



     def __call__(	self  :		Dict					,	__lowerCamelCase  :		Union[np.ndarray, List[float], List[np.ndarray], List[List[float]]]					,	__lowerCamelCase  :		Union[bool, str, PaddingStrategy] = False					,	__lowerCamelCase  :		Optional[int] = None					,	__lowerCamelCase  :		bool = False					,	__lowerCamelCase  :		Optional[int] = None					,	__lowerCamelCase  :		Optional[bool] = None					,	__lowerCamelCase  :		Optional[Union[str, TensorType]] = None					,	__lowerCamelCase  :		Optional[int] = None					,	**__lowerCamelCase  :		Optional[int]					,	):



       """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(__lowerCamelCase					,	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(__lowerCamelCase					,	(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(
           __lowerCamelCase					,	padding=__lowerCamelCase					,	max_length=__lowerCamelCase					,	truncation=__lowerCamelCase					,	pad_to_multiple_of=__lowerCamelCase					,	return_attention_mask=__lowerCamelCase					,	)

       # convert input values to correct format
       lowerCAmelCase__								=			padded_inputs['''input_values''']
       if not isinstance(input_values[0]					,	np.ndarray	):
         lowerCAmelCase__								=			[np.asarray(__lowerCamelCase					,	dtype=np.floataa	) for array in input_values]
       elif (
           not isinstance(__lowerCamelCase					,	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(__lowerCamelCase					,	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(__lowerCamelCase					,	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(__lowerCamelCase					,	max_length=__lowerCamelCase	) is not PaddingStrategy.DO_NOT_PAD
             else None
         )
         lowerCAmelCase__								=			self.zero_mean_unit_var_norm(
             padded_inputs['''input_values''']					,	attention_mask=__lowerCamelCase					,	padding_value=self.padding_value	)

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

       return padded_inputs







import os

from ...utils import logging
from .utils import DataProcessor, InputExample


__magic_name__     :     str  							=					logging.get_logger(__name__)





class 						SCREAMING_SNAKE_CASE__		(_a ):
     def __init__(	self  :		Any					,	__lowerCamelCase  :		Any					,	__lowerCamelCase  :		Optional[int]=None	):



       """simple docstring"""
       lowerCAmelCase__								=			language
       lowerCAmelCase__								=			train_language
     def 					A__			(	self  :		str					,	__lowerCamelCase  :		List[str]	):



       """simple docstring"""
       lowerCAmelCase__								=			self.language if self.train_language is None else self.train_language
       lowerCAmelCase__								=			self._read_tsv(os.path.join(__lowerCamelCase					,	F"""XNLI-MT-1.0/multinli/multinli.train.{lg}.tsv"""	)	)
       lowerCAmelCase__								=			[]
       for i, line in enumerate(__lowerCamelCase	):
         if i == 0:
           continue
         lowerCAmelCase__								=			F"""train-{i}"""
         lowerCAmelCase__								=			line[0]
         lowerCAmelCase__								=			line[1]
         lowerCAmelCase__								=			'''contradiction''' if line[2] == '''contradictory''' else line[2]
         if not isinstance(__lowerCamelCase					,	__lowerCamelCase	):
           raise ValueError(F"""Training input {text_a} is not a string"""	)
         if not isinstance(__lowerCamelCase					,	__lowerCamelCase	):
           raise ValueError(F"""Training input {text_b} is not a string"""	)
         if not isinstance(__lowerCamelCase					,	__lowerCamelCase	):
           raise ValueError(F"""Training label {label} is not a string"""	)
         examples.append(InputExample(guid=__lowerCamelCase					,	text_a=__lowerCamelCase					,	text_b=__lowerCamelCase					,	label=__lowerCamelCase	)	)
       return examples
     def 					A__			(	self  :		Dict					,	__lowerCamelCase  :		Union[str, Any]	):



       """simple docstring"""
       lowerCAmelCase__								=			self._read_tsv(os.path.join(__lowerCamelCase					,	'''XNLI-1.0/xnli.test.tsv'''	)	)
       lowerCAmelCase__								=			[]
       for i, line in enumerate(__lowerCamelCase	):
         if i == 0:
           continue
         lowerCAmelCase__								=			line[0]
         if language != self.language:
           continue
         lowerCAmelCase__								=			F"""test-{i}"""
         lowerCAmelCase__								=			line[6]
         lowerCAmelCase__								=			line[7]
         lowerCAmelCase__								=			line[1]
         if not isinstance(__lowerCamelCase					,	__lowerCamelCase	):
           raise ValueError(F"""Training input {text_a} is not a string"""	)
         if not isinstance(__lowerCamelCase					,	__lowerCamelCase	):
           raise ValueError(F"""Training input {text_b} is not a string"""	)
         if not isinstance(__lowerCamelCase					,	__lowerCamelCase	):
           raise ValueError(F"""Training label {label} is not a string"""	)
         examples.append(InputExample(guid=__lowerCamelCase					,	text_a=__lowerCamelCase					,	text_b=__lowerCamelCase					,	label=__lowerCamelCase	)	)
       return examples



     def 					A__			(	self  :		List[str]	):



       """simple docstring"""
       return ["contradiction", "entailment", "neutral"]



__magic_name__     :     Tuple  							=					{
    """xnli""": XnliProcessor,
}

__magic_name__     :     List[Any]  							=					{
    """xnli""": """classification""",
}

__magic_name__     :     str  							=					{
    """xnli""": 3,
}

