


import warnings
from contextlib import contextmanager

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







class 						_snake_case    ( _snake_case				):
 SCREAMING_SNAKE_CASE__ =			'Wav2Vec2FeatureExtractor'
 SCREAMING_SNAKE_CASE__ =			'AutoTokenizer'




 def __init__(						self   ,    _lowerCamelCase   ,    _lowerCamelCase       ):
       super().__init__(_lowerCamelCase   ,    _lowerCamelCase       )
       a		:Any									=			self.feature_extractor
       a		:int									=			False




 @classmethod
 def 			SCREAMING_SNAKE_CASE__							(						cls   ,    _lowerCamelCase   ,    **_lowerCamelCase       ):
       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   ,    )

             a		:Tuple									=			WavaVecaFeatureExtractor.from_pretrained(_lowerCamelCase   ,    **_lowerCamelCase       )
             a		:List[str]									=			WavaVecaCTCTokenizer.from_pretrained(_lowerCamelCase   ,    **_lowerCamelCase       )

             return cls(feature_extractor=_lowerCamelCase   ,    tokenizer=_lowerCamelCase       )




 def __call__(						self   ,    *_lowerCamelCase   ,    **_lowerCamelCase       ):
       # 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.'''       )
             a		:Optional[Any]									=			kwargs.pop('''raw_speech'''       )
       else:
             a		:Optional[int]									=			kwargs.pop('''audio'''   ,    _lowerCamelCase       )
       a		:int									=			kwargs.pop('''sampling_rate'''   ,    _lowerCamelCase       )
       a		:Dict									=			kwargs.pop('''text'''   ,    _lowerCamelCase       )
       if len(_lowerCamelCase       ) > 0:
             a		:Optional[int]									=			args[0]
             a		:int									=			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:
             a		:Union[str, Any]									=			self.feature_extractor(_lowerCamelCase   ,    *_lowerCamelCase   ,    sampling_rate=_lowerCamelCase   ,    **_lowerCamelCase       )
       if text is not None:
             a		:List[Any]									=			self.tokenizer(_lowerCamelCase   ,    **_lowerCamelCase       )

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




 def 			SCREAMING_SNAKE_CASE__							(						self   ,    *_lowerCamelCase   ,    **_lowerCamelCase       ):
       # For backward compatibility
       if self._in_target_context_manager:
             return self.current_processor.pad(*_lowerCamelCase   ,    **_lowerCamelCase       )

       a		:List[str]									=			kwargs.pop('''input_features'''   ,    _lowerCamelCase       )
       a		:List[Any]									=			kwargs.pop('''labels'''   ,    _lowerCamelCase       )
       if len(_lowerCamelCase       ) > 0:
             a		:List[Any]									=			args[0]
             a		:int									=			args[1:]

       if input_features is not None:
             a		:Optional[Any]									=			self.feature_extractor.pad(_lowerCamelCase   ,    *_lowerCamelCase   ,    **_lowerCamelCase       )
       if labels is not None:
             a		:List[Any]									=			self.tokenizer.pad(_lowerCamelCase   ,    **_lowerCamelCase       )

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




 def 			SCREAMING_SNAKE_CASE__							(						self   ,    *_lowerCamelCase   ,    **_lowerCamelCase       ):
       return self.tokenizer.batch_decode(*_lowerCamelCase   ,    **_lowerCamelCase       )




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




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









import datasets


snake_case							:       int										=	'''\
@InProceedings{conneau2018xnli,
  author = "Conneau, Alexis
                 and Rinott, Ruty
                 and Lample, Guillaume
                 and Williams, Adina
                 and Bowman, Samuel R.
                 and Schwenk, Holger
                 and Stoyanov, Veselin",
  title = "XNLI: Evaluating Cross-lingual Sentence Representations",
  booktitle = "Proceedings of the 2018 Conference on Empirical Methods
               in Natural Language Processing",
  year = "2018",
  publisher = "Association for Computational Linguistics",
  location = "Brussels, Belgium",
}
'''

snake_case							:       Tuple										=	'''\
XNLI is a subset of a few thousand examples from MNLI which has been translated
into a 14 different languages (some low-ish resource). As with MNLI, the goal is
to predict textual entailment (does sentence A imply/contradict/neither sentence
B) and is a classification task (given two sentences, predict one of three
labels).
'''

snake_case							:       Union[str, Any]										=	'''
Computes XNLI score which is just simple accuracy.
Args:
    predictions: Predicted labels.
    references: Ground truth labels.
Returns:
    \'accuracy\': accuracy
Examples:

    >>> predictions = [0, 1]
    >>> references = [0, 1]
    >>> xnli_metric = datasets.load_metric("xnli")
    >>> results = xnli_metric.compute(predictions=predictions, references=references)
    >>> print(results)
    {\'accuracy\': 1.0}
'''
def 							__lowerCamelCase		(					UpperCAmelCase_		:						List[Any]					,    UpperCAmelCase_		:						List[str]		):




      """simple docstring"""





      return (preds == labels).mean()







@datasets.utils.file_utils.add_start_docstrings(_DESCRIPTION		,       _KWARGS_DESCRIPTION				)
class 						_snake_case    ( datasets.Metric				):




 def 			SCREAMING_SNAKE_CASE__							(						self       ):
       return datasets.MetricInfo(
           description=_DESCRIPTION   ,    citation=_CITATION   ,    inputs_description=_KWARGS_DESCRIPTION   ,    features=datasets.Features(
               {
                   '''predictions''': datasets.Value('''int64''' if self.config_name != '''sts-b''' else '''float32'''       ),
                   '''references''': datasets.Value('''int64''' if self.config_name != '''sts-b''' else '''float32'''       ),
               }       )   ,    codebase_urls=[]   ,    reference_urls=[]   ,    format='''numpy'''   ,    )




 def 			SCREAMING_SNAKE_CASE__							(						self   ,    _lowerCamelCase   ,    _lowerCamelCase       ):
       return {"accuracy": simple_accuracy(_lowerCamelCase   ,    _lowerCamelCase       )}





