
import datasets


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

__a          =			'\\nXNLI is a subset of a few thousand examples from MNLI which has been translated\ninto a 14 different languages (some low-ish resource). As with MNLI, the goal is\nto predict textual entailment (does sentence A imply/contradict/neither sentence\nB) and is a classification task (given two sentences, predict one of three\nlabels).\n'

__a          =			'\nComputes XNLI score which is just simple accuracy.\nArgs:\n    predictions: Predicted labels.\n    references: Ground truth labels.\nReturns:\n    \'accuracy\': accuracy\nExamples:\n\n    >>> predictions = [0, 1]\n    >>> references = [0, 1]\n    >>> xnli_metric = datasets.load_metric(\"xnli\")\n    >>> results = xnli_metric.compute(predictions=predictions, references=references)\n    >>> print(results)\n    {\'accuracy\': 1.0}\n'







def lowerCamelCase__       (      _lowercase			,						_lowercase				):

     '''simple docstring'''


     return (preds == labels).mean()



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






    """simple docstring"""





    def 							a__				(				self  )			->		Union[str, Any]:
         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 							a__				(				self       ,_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE  )			->		List[Any]:
         return {"accuracy": simple_accuracy(snake_case__       ,snake_case__  )}





import shutil
import tempfile
import unittest

import numpy as np
import pytest

from transformers.testing_utils import require_vision
from transformers.utils import is_vision_available


if is_vision_available():
     from PIL import Image

     from transformers import AutoProcessor, BlipaProcessor, BlipImageProcessor, GPTaTokenizer, PreTrainedTokenizerFast

@require_vision
class   __a(					unittest.TestCase       ):






    """simple docstring"""





    def 							a__				(				self  )			->		Optional[int]:
         UpperCAmelCase_      :							Optional[int]       =      tempfile.mkdtemp()

         UpperCAmelCase_      :							str       =      BlipImageProcessor()
         UpperCAmelCase_      :							Dict       =      GPTaTokenizer.from_pretrained('''hf-internal-testing/tiny-random-GPT2Model'''  )

         UpperCAmelCase_      :							Optional[Any]       =      BlipaProcessor(_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE  )

         processor.save_pretrained(self.tmpdirname  )





    def 							a__				(				self       ,**_SCREAMING_SNAKE_CASE  )			->		Optional[int]:
         return AutoProcessor.from_pretrained(self.tmpdirname       ,**_SCREAMING_SNAKE_CASE  ).tokenizer





    def 							a__				(				self       ,**_SCREAMING_SNAKE_CASE  )			->		Dict:
         return AutoProcessor.from_pretrained(self.tmpdirname       ,**_SCREAMING_SNAKE_CASE  ).image_processor





    def 							a__				(				self  )			->		List[Any]:
         shutil.rmtree(self.tmpdirname  )





    def 							a__				(				self  )			->		Tuple:
         UpperCAmelCase_      :							Tuple       =      [np.random.randint(255       ,size=(3, 30, 400)       ,dtype=np.uinta  )]

         UpperCAmelCase_      :							Optional[Any]       =      [Image.fromarray(np.moveaxis(_SCREAMING_SNAKE_CASE       ,0       ,-1  )  ) for x in image_inputs]

         return image_inputs





    def 							a__				(				self  )			->		List[str]:
         UpperCAmelCase_      :							Dict       =      BlipaProcessor(tokenizer=self.get_tokenizer()       ,image_processor=self.get_image_processor()  )
         processor.save_pretrained(self.tmpdirname  )

         UpperCAmelCase_      :							str       =      self.get_tokenizer(bos_token='''(BOS)'''       ,eos_token='''(EOS)'''  )
         UpperCAmelCase_      :							int       =      self.get_image_processor(do_normalize=_SCREAMING_SNAKE_CASE       ,padding_value=1.0  )

         UpperCAmelCase_      :							Union[str, Any]       =      BlipaProcessor.from_pretrained(
             self.tmpdirname       ,bos_token='''(BOS)'''       ,eos_token='''(EOS)'''       ,do_normalize=_SCREAMING_SNAKE_CASE       ,padding_value=1.0  )

         self.assertEqual(processor.tokenizer.get_vocab()       ,tokenizer_add_kwargs.get_vocab()  )
         self.assertIsInstance(processor.tokenizer       ,_SCREAMING_SNAKE_CASE  )

         self.assertEqual(processor.image_processor.to_json_string()       ,image_processor_add_kwargs.to_json_string()  )
         self.assertIsInstance(processor.image_processor       ,_SCREAMING_SNAKE_CASE  )





    def 							a__				(				self  )			->		Any:
         UpperCAmelCase_      :							Dict       =      self.get_image_processor()
         UpperCAmelCase_      :							Any       =      self.get_tokenizer()

         UpperCAmelCase_      :							str       =      BlipaProcessor(tokenizer=_SCREAMING_SNAKE_CASE       ,image_processor=_SCREAMING_SNAKE_CASE  )

         UpperCAmelCase_      :							Union[str, Any]       =      self.prepare_image_inputs()

         UpperCAmelCase_      :							Optional[Any]       =      image_processor(_SCREAMING_SNAKE_CASE       ,return_tensors='''np'''  )
         UpperCAmelCase_      :							int       =      processor(images=_SCREAMING_SNAKE_CASE       ,return_tensors='''np'''  )

         for key in input_feat_extract.keys():
              self.assertAlmostEqual(input_feat_extract[key].sum()       ,input_processor[key].sum()       ,delta=1e-2  )





    def 							a__				(				self  )			->		int:
         UpperCAmelCase_      :							str       =      self.get_image_processor()
         UpperCAmelCase_      :							List[Any]       =      self.get_tokenizer()

         UpperCAmelCase_      :							Any       =      BlipaProcessor(tokenizer=_SCREAMING_SNAKE_CASE       ,image_processor=_SCREAMING_SNAKE_CASE  )

         UpperCAmelCase_      :							Tuple       =      '''lower newer'''

         UpperCAmelCase_      :							Optional[int]       =      processor(text=_SCREAMING_SNAKE_CASE  )

         UpperCAmelCase_      :							int       =      tokenizer(_SCREAMING_SNAKE_CASE       ,return_token_type_ids=_SCREAMING_SNAKE_CASE  )

         for key in encoded_tok.keys():
              self.assertListEqual(encoded_tok[key]       ,encoded_processor[key]  )





    def 							a__				(				self  )			->		Optional[int]:
         UpperCAmelCase_      :							str       =      self.get_image_processor()
         UpperCAmelCase_      :							List[Any]       =      self.get_tokenizer()

         UpperCAmelCase_      :							Tuple       =      BlipaProcessor(tokenizer=_SCREAMING_SNAKE_CASE       ,image_processor=_SCREAMING_SNAKE_CASE  )

         UpperCAmelCase_      :							int       =      '''lower newer'''
         UpperCAmelCase_      :							int       =      self.prepare_image_inputs()

         UpperCAmelCase_      :							List[str]       =      processor(text=_SCREAMING_SNAKE_CASE       ,images=_SCREAMING_SNAKE_CASE  )

         self.assertListEqual(list(inputs.keys()  )       ,['''pixel_values''', '''input_ids''', '''attention_mask''']  )

         # test if it raises when no input is passed
         with pytest.raises(_SCREAMING_SNAKE_CASE  ):
              processor()





    def 							a__				(				self  )			->		Optional[int]:
         UpperCAmelCase_      :							Tuple       =      self.get_image_processor()
         UpperCAmelCase_      :							Dict       =      self.get_tokenizer()

         UpperCAmelCase_      :							List[str]       =      BlipaProcessor(tokenizer=_SCREAMING_SNAKE_CASE       ,image_processor=_SCREAMING_SNAKE_CASE  )

         UpperCAmelCase_      :							Optional[Any]       =      [[1, 4, 5, 8, 1, 0, 8], [3, 4, 3, 1, 1, 8, 9]]

         UpperCAmelCase_      :							List[str]       =      processor.batch_decode(_SCREAMING_SNAKE_CASE  )
         UpperCAmelCase_      :							Union[str, Any]       =      tokenizer.batch_decode(_SCREAMING_SNAKE_CASE  )

         self.assertListEqual(_SCREAMING_SNAKE_CASE       ,_SCREAMING_SNAKE_CASE  )





    def 							a__				(				self  )			->		str:
         UpperCAmelCase_      :							Union[str, Any]       =      self.get_image_processor()
         UpperCAmelCase_      :							int       =      self.get_tokenizer()

         UpperCAmelCase_      :							Any       =      BlipaProcessor(tokenizer=_SCREAMING_SNAKE_CASE       ,image_processor=_SCREAMING_SNAKE_CASE  )

         UpperCAmelCase_      :							Dict       =      '''lower newer'''
         UpperCAmelCase_      :							Union[str, Any]       =      self.prepare_image_inputs()

         UpperCAmelCase_      :							Any       =      processor(text=_SCREAMING_SNAKE_CASE       ,images=_SCREAMING_SNAKE_CASE  )

         # For now the processor supports only ['pixel_values', 'input_ids', 'attention_mask']
         self.assertListEqual(list(inputs.keys()  )       ,['''pixel_values''', '''input_ids''', '''attention_mask''']  )