




from typing import Dict, List, Optional, Union

import numpy as np

from ...image_processing_utils import BaseImageProcessor, BatchFeature, get_size_dict
from ...image_transforms import center_crop, normalize, rescale, resize, to_channel_dimension_format
from ...image_utils import (
    IMAGENET_DEFAULT_MEAN,
    IMAGENET_DEFAULT_STD,
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    get_image_size,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, is_vision_available, logging


if is_vision_available():
      import PIL


__magic_name__     :     Any  							=					logging.get_logger(__name__)





class 						SCREAMING_SNAKE_CASE__		(SCREAMING_SNAKE_CASE__ ):
     lowercase_   :			Dict   =   ["pixel_values"]
     def __init__(	self  :		List[str]					,	__lowerCamelCase  :		Optional[Any] = True					,	__lowerCamelCase  :		List[Any] = None					,	__lowerCamelCase  :		List[Any] = True					,	__lowerCamelCase  :		Dict = None					,	__lowerCamelCase  :		Optional[Any] = PILImageResampling.BICUBIC					,	__lowerCamelCase  :		Any = True					,	__lowerCamelCase  :		Optional[Any] = 1 / 2_55					,	__lowerCamelCase  :		str = True					,	__lowerCamelCase  :		str = None					,	__lowerCamelCase  :		Optional[Any] = None					,	**__lowerCamelCase  :		str					,	):



       """simple docstring"""
       super().__init__(**__lowerCamelCase	)
       lowerCAmelCase__								=			crop_size if crop_size is not None else {'''height''': 2_56, '''width''': 2_56}
       lowerCAmelCase__								=			get_size_dict(__lowerCamelCase					,	param_name='''crop_size'''	)
       lowerCAmelCase__								=			size if size is not None else {'''height''': 2_24, '''width''': 2_24}
       lowerCAmelCase__								=			get_size_dict(__lowerCamelCase	)

       lowerCAmelCase__								=			do_center_crop
       lowerCAmelCase__								=			crop_size
       lowerCAmelCase__								=			do_resize
       lowerCAmelCase__								=			size
       lowerCAmelCase__								=			resample
       lowerCAmelCase__								=			do_rescale
       lowerCAmelCase__								=			rescale_factor
       lowerCAmelCase__								=			do_normalize
       lowerCAmelCase__								=			image_mean if image_mean is not None else IMAGENET_DEFAULT_MEAN
       lowerCAmelCase__								=			image_std if image_std is not None else IMAGENET_DEFAULT_STD
     def 					A__			(	self  :		List[Any]					,	__lowerCamelCase  :		Optional[Any]					,	__lowerCamelCase  :		str					,	__lowerCamelCase  :		List[Any] = None					,	__lowerCamelCase  :		Optional[Any] = None					,	**__lowerCamelCase  :		Optional[Any]					,	):



       """simple docstring"""
       lowerCAmelCase__								=			self.size if size is None else size
       lowerCAmelCase__								=			get_size_dict(__lowerCamelCase	)
       lowerCAmelCase__								=			get_size_dict(__lowerCamelCase					,	param_name='''crop_size'''	)

       lowerCAmelCase__							,			lowerCAmelCase__								=			get_image_size(__lowerCamelCase	)
       lowerCAmelCase__								=			min(__lowerCamelCase					,	__lowerCamelCase	)
       lowerCAmelCase__								=			(size['''height'''] / crop_size['''height''']) * min_dim
       lowerCAmelCase__								=			(size['''width'''] / crop_size['''width''']) * min_dim
       return center_crop(__lowerCamelCase					,	size=(cropped_height, cropped_width)					,	data_format=__lowerCamelCase					,	**__lowerCamelCase	)
     def 					A__			(	self  :		Union[str, Any]					,	__lowerCamelCase  :		Union[str, Any]					,	__lowerCamelCase  :		Tuple					,	__lowerCamelCase  :		Optional[int] = PIL.Image.BICUBIC					,	__lowerCamelCase  :		Tuple = None					,	**__lowerCamelCase  :		str					,	):



       """simple docstring"""
       lowerCAmelCase__								=			get_size_dict(__lowerCamelCase	)
       if "height" not in size or "width" not in size:
         raise ValueError(F"""The size dictionary must contain the keys \'height\' and \'width\'. Got {size.keys()}"""	)
       return resize(
           __lowerCamelCase					,	size=(size['''height'''], size['''width'''])					,	resample=__lowerCamelCase					,	data_format=__lowerCamelCase					,	**__lowerCamelCase	)
     def 					A__			(	self  :		List[str]					,	__lowerCamelCase  :		Any					,	__lowerCamelCase  :		Any					,	__lowerCamelCase  :		Optional[Any] = None					,	**__lowerCamelCase  :		List[Any]					,	):



       """simple docstring"""
       return rescale(__lowerCamelCase					,	scale=__lowerCamelCase					,	data_format=__lowerCamelCase					,	**__lowerCamelCase	)
     def 					A__			(	self  :		Union[str, Any]					,	__lowerCamelCase  :		Tuple					,	__lowerCamelCase  :		List[Any]					,	__lowerCamelCase  :		str					,	__lowerCamelCase  :		Any = None					,	**__lowerCamelCase  :		Dict					,	):



       """simple docstring"""
       return normalize(__lowerCamelCase					,	mean=__lowerCamelCase					,	std=__lowerCamelCase					,	data_format=__lowerCamelCase					,	**__lowerCamelCase	)



     def 					A__			(	self  :		Dict					,	__lowerCamelCase  :		Dict					,	__lowerCamelCase  :		Dict = None					,	__lowerCamelCase  :		Union[str, Any] = None					,	__lowerCamelCase  :		int = None					,	__lowerCamelCase  :		Union[str, Any] = None					,	__lowerCamelCase  :		Optional[Any] = None					,	__lowerCamelCase  :		int = None					,	__lowerCamelCase  :		Any = None					,	__lowerCamelCase  :		List[str] = None					,	__lowerCamelCase  :		Tuple = None					,	__lowerCamelCase  :		List[Any] = None					,	__lowerCamelCase  :		Optional[int] = None					,	__lowerCamelCase  :		int = ChannelDimension.FIRST					,	**__lowerCamelCase  :		Dict					,	):



       """simple docstring"""
       lowerCAmelCase__								=			do_center_crop if do_center_crop is not None else self.do_center_crop
       lowerCAmelCase__								=			crop_size if crop_size is not None else self.crop_size
       lowerCAmelCase__								=			get_size_dict(__lowerCamelCase					,	param_name='''crop_size'''	)
       lowerCAmelCase__								=			do_resize if do_resize is not None else self.do_resize
       lowerCAmelCase__								=			size if size is not None else self.size
       lowerCAmelCase__								=			get_size_dict(__lowerCamelCase	)
       lowerCAmelCase__								=			resample if resample is not None else self.resample
       lowerCAmelCase__								=			do_rescale if do_rescale is not None else self.do_rescale
       lowerCAmelCase__								=			rescale_factor if rescale_factor is not None else self.rescale_factor
       lowerCAmelCase__								=			do_normalize if do_normalize is not None else self.do_normalize
       lowerCAmelCase__								=			image_mean if image_mean is not None else self.image_mean
       lowerCAmelCase__								=			image_std if image_std is not None else self.image_std

       lowerCAmelCase__								=			make_list_of_images(__lowerCamelCase	)

       if not valid_images(__lowerCamelCase	):
         raise ValueError(
             '''Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, '''
             '''torch.Tensor, tf.Tensor or jax.ndarray.'''	)

       if do_center_crop and crop_size is None:
         raise ValueError('''If `do_center_crop` is set to `True`, `crop_size` must be provided.'''	)

       if do_resize and size is None:
         raise ValueError('''Size must be specified if do_resize is True.'''	)

       if do_rescale and rescale_factor is None:
         raise ValueError('''Rescale factor must be specified if do_rescale is True.'''	)

       if do_normalize and (image_mean is None or image_std is None):
         raise ValueError('''Image mean and image standard deviation must be specified if do_normalize is True.'''	)

       # All transformations expect numpy arrays.
       lowerCAmelCase__								=			[to_numpy_array(__lowerCamelCase	) for image in images]

       if do_center_crop:
         lowerCAmelCase__								=			[self.center_crop(__lowerCamelCase					,	__lowerCamelCase					,	size=__lowerCamelCase	) for image in images]

       if do_resize:
         lowerCAmelCase__								=			[self.resize(image=__lowerCamelCase					,	size=__lowerCamelCase					,	resample=__lowerCamelCase	) for image in images]

       if do_rescale:
         lowerCAmelCase__								=			[self.rescale(image=__lowerCamelCase					,	scale=__lowerCamelCase	) for image in images]

       if do_normalize:
         lowerCAmelCase__								=			[self.normalize(image=__lowerCamelCase					,	mean=__lowerCamelCase					,	std=__lowerCamelCase	) for image in images]

       lowerCAmelCase__								=			[to_channel_dimension_format(__lowerCamelCase					,	__lowerCamelCase	) for image in images]

       lowerCAmelCase__								=			{'''pixel_values''': images}
       return BatchFeature(data=__lowerCamelCase					,	tensor_type=__lowerCamelCase	)







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,
}

