




'''simple docstring'''


import os

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


_snake_case      :      Tuple   							=		logging.get_logger(__name__)

class 			A    (		_a    ):







							def __init__(  self       :  str							,			lowerCAmelCase_       :  Optional[Any]							,			lowerCAmelCase_       :  List[str]=None					)			->							Any:


														"""simple docstring"""


														_a	     =				language
														_a	     =				train_language







							def    __lowerCAmelCase			(  self       :  str							,			lowerCAmelCase_       :  Optional[Any]					)			->							Optional[Any]:


														"""simple docstring"""


														_a	     =				self.language if self.train_language is None else self.train_language
														_a	     =				self._read_tsv(os.path.join(lowerCAmelCase_							,			F'XNLI-MT-1.0/multinli/multinli.train.{lg}.tsv'					)					)
														_a	     =				[]
														for i, line in enumerate(lowerCAmelCase_					):
																					if i == 0:
																												continue
																					_a	     =				F'train-{i}'
																					_a	     =				line[0]
																					_a	     =				line[1]
																					_a	     =				'''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    __lowerCAmelCase			(  self       :  str							,			lowerCAmelCase_       :  int					)			->							Tuple:


														"""simple docstring"""


														_a	     =				self._read_tsv(os.path.join(lowerCAmelCase_							,			'''XNLI-1.0/xnli.test.tsv'''					)					)
														_a	     =				[]
														for i, line in enumerate(lowerCAmelCase_					):
																					if i == 0:
																												continue
																					_a	     =				line[0]
																					if language != self.language:
																												continue
																					_a	     =				F'test-{i}'
																					_a	     =				line[6]
																					_a	     =				line[7]
																					_a	     =				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    __lowerCAmelCase			(  self       :  Optional[int]					)			->							List[Any]:


														"""simple docstring"""


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



_snake_case      :      Tuple   							=		{
    'xnli': XnliProcessor,
}

_snake_case      :      str   							=		{
    'xnli': 'classification',
}

_snake_case      :      Union[str, Any]   							=		{
    'xnli': 3,
}







'''simple docstring'''


import unittest
from pathlib import Path

from transformers import is_vision_available, load_tool
from transformers.testing_utils import get_tests_dir

from .test_tools_common import ToolTesterMixin


if is_vision_available():
				from PIL import Image

class 			A    (		unittest.TestCase     ,_a    ):







							def    __lowerCAmelCase			(  self       :  Optional[int]					)			->							Optional[int]:


														"""simple docstring"""


														_a	     =				load_tool('''image-question-answering'''					)
														self.tool.setup()
														_a	     =				load_tool('''image-question-answering'''							,			remote=lowerCAmelCase_					)







							def    __lowerCAmelCase			(  self       :  Tuple					)			->							Optional[int]:


														"""simple docstring"""


														_a	     =				Image.open(Path(get_tests_dir('''fixtures/tests_samples/COCO'''					)					) / '''000000039769.png'''					)
														_a	     =				self.tool(lowerCAmelCase_							,			'''How many cats are sleeping on the couch?'''					)
														self.assertEqual(lowerCAmelCase_							,			'''2'''					)







							def    __lowerCAmelCase			(  self       :  List[str]					)			->							Union[str, Any]:


														"""simple docstring"""


														_a	     =				Image.open(Path(get_tests_dir('''fixtures/tests_samples/COCO'''					)					) / '''000000039769.png'''					)
														_a	     =				self.remote_tool(lowerCAmelCase_							,			'''How many cats are sleeping on the couch?'''					)
														self.assertEqual(lowerCAmelCase_							,			'''2'''					)







							def    __lowerCAmelCase			(  self       :  Dict					)			->							Tuple:


														"""simple docstring"""


														_a	     =				Image.open(Path(get_tests_dir('''fixtures/tests_samples/COCO'''					)					) / '''000000039769.png'''					)
														_a	     =				self.tool(image=lowerCAmelCase_							,			question='''How many cats are sleeping on the couch?'''					)
														self.assertEqual(lowerCAmelCase_							,			'''2'''					)







							def    __lowerCAmelCase			(  self       :  Tuple					)			->							Dict:


														"""simple docstring"""


														_a	     =				Image.open(Path(get_tests_dir('''fixtures/tests_samples/COCO'''					)					) / '''000000039769.png'''					)
														_a	     =				self.remote_tool(image=lowerCAmelCase_							,			question='''How many cats are sleeping on the couch?'''					)
														self.assertEqual(lowerCAmelCase_							,			'''2'''					)

