



import inspect
import unittest

from transformers import ViTConfig
from transformers.testing_utils import (
    require_accelerate,
    require_torch,
    require_torch_gpu,
    require_vision,
    slow,
    torch_device,
)
from transformers.utils import cached_property, is_torch_available, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
	import torch
	from torch import nn

	from transformers import ViTForImageClassification, ViTForMaskedImageModeling, ViTModel
	from transformers.models.vit.modeling_vit import VIT_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
	from PIL import Image

	from transformers import ViTImageProcessor







class 				_a				:

			def __init__(self,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_=13,   SCREAMING_SNAKE_CASE_=30,   SCREAMING_SNAKE_CASE_=2,   SCREAMING_SNAKE_CASE_=3,   SCREAMING_SNAKE_CASE_=True,   SCREAMING_SNAKE_CASE_=True,   SCREAMING_SNAKE_CASE_=32,   SCREAMING_SNAKE_CASE_=5,   SCREAMING_SNAKE_CASE_=4,   SCREAMING_SNAKE_CASE_=37,   SCREAMING_SNAKE_CASE_="gelu",   SCREAMING_SNAKE_CASE_=0.1,   SCREAMING_SNAKE_CASE_=0.1,   SCREAMING_SNAKE_CASE_=10,   SCREAMING_SNAKE_CASE_=0.0_2,   SCREAMING_SNAKE_CASE_=None,   SCREAMING_SNAKE_CASE_=2,   )       ->   Tuple:
						UpperCAmelCase_:		Optional[int]							      =     parent
						UpperCAmelCase_:		Optional[Any]							      =     batch_size
						UpperCAmelCase_:		Optional[Any]							      =     image_size
						UpperCAmelCase_:		Optional[int]							      =     patch_size
						UpperCAmelCase_:		Optional[Any]							      =     num_channels
						UpperCAmelCase_:		str							      =     is_training
						UpperCAmelCase_:		Union[str, Any]							      =     use_labels
						UpperCAmelCase_:		List[str]							      =     hidden_size
						UpperCAmelCase_:		Dict							      =     num_hidden_layers
						UpperCAmelCase_:		List[Any]							      =     num_attention_heads
						UpperCAmelCase_:		Optional[int]							      =     intermediate_size
						UpperCAmelCase_:		List[Any]							      =     hidden_act
						UpperCAmelCase_:		str							      =     hidden_dropout_prob
						UpperCAmelCase_:		Tuple							      =     attention_probs_dropout_prob
						UpperCAmelCase_:		Any							      =     type_sequence_label_size
						UpperCAmelCase_:		str							      =     initializer_range
						UpperCAmelCase_:		Tuple							      =     scope
						UpperCAmelCase_:		Optional[int]							      =     encoder_stride

						# in ViT, the seq length equals the number of patches + 1 (we add 1 for the [CLS] token)
						UpperCAmelCase_:		Tuple							      =     (image_size // patch_size) ** 2
						UpperCAmelCase_:		Optional[int]							      =     num_patches + 1

			def      __snake_case       (self					)       ->   int:
						UpperCAmelCase_:		Tuple							      =     floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]					)

						UpperCAmelCase_:		List[Any]							      =     None
						if self.use_labels:
									UpperCAmelCase_:		List[Any]							      =     ids_tensor([self.batch_size],   self.type_sequence_label_size					)

						UpperCAmelCase_:		str							      =     self.get_config()

						return config, pixel_values, labels

			def      __snake_case       (self					)       ->   str:
						return ViTConfig(
						    image_size=self.image_size,   patch_size=self.patch_size,   num_channels=self.num_channels,   hidden_size=self.hidden_size,   num_hidden_layers=self.num_hidden_layers,   num_attention_heads=self.num_attention_heads,   intermediate_size=self.intermediate_size,   hidden_act=self.hidden_act,   hidden_dropout_prob=self.hidden_dropout_prob,   attention_probs_dropout_prob=self.attention_probs_dropout_prob,   is_decoder=SCREAMING_SNAKE_CASE_,   initializer_range=self.initializer_range,   encoder_stride=self.encoder_stride,   )

			def      __snake_case       (self,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_					)       ->   Dict:
						UpperCAmelCase_:		Optional[Any]							      =     ViTModel(config=SCREAMING_SNAKE_CASE_					)
						model.to(SCREAMING_SNAKE_CASE_					)
						model.eval()
						UpperCAmelCase_:		Optional[Any]							      =     model(SCREAMING_SNAKE_CASE_					)
						self.parent.assertEqual(result.last_hidden_state.shape,   (self.batch_size, self.seq_length, self.hidden_size)					)

			def      __snake_case       (self,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_					)       ->   Tuple:
						UpperCAmelCase_:		int							      =     ViTForMaskedImageModeling(config=SCREAMING_SNAKE_CASE_					)
						model.to(SCREAMING_SNAKE_CASE_					)
						model.eval()
						UpperCAmelCase_:		str							      =     model(SCREAMING_SNAKE_CASE_					)
						self.parent.assertEqual(
						    result.reconstruction.shape,   (self.batch_size, self.num_channels, self.image_size, self.image_size)					)

						# test greyscale images
						UpperCAmelCase_:		Union[str, Any]							      =     1
						UpperCAmelCase_:		str							      =     ViTForMaskedImageModeling(SCREAMING_SNAKE_CASE_					)
						model.to(SCREAMING_SNAKE_CASE_					)
						model.eval()

						UpperCAmelCase_:		Optional[int]							      =     floats_tensor([self.batch_size, 1, self.image_size, self.image_size]					)
						UpperCAmelCase_:		str							      =     model(SCREAMING_SNAKE_CASE_					)
						self.parent.assertEqual(result.reconstruction.shape,   (self.batch_size, 1, self.image_size, self.image_size)					)

			def      __snake_case       (self,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_					)       ->   Union[str, Any]:
						UpperCAmelCase_:		str							      =     self.type_sequence_label_size
						UpperCAmelCase_:		List[Any]							      =     ViTForImageClassification(SCREAMING_SNAKE_CASE_					)
						model.to(SCREAMING_SNAKE_CASE_					)
						model.eval()
						UpperCAmelCase_:		Dict							      =     model(SCREAMING_SNAKE_CASE_,   labels=SCREAMING_SNAKE_CASE_					)
						self.parent.assertEqual(result.logits.shape,   (self.batch_size, self.type_sequence_label_size)					)

						# test greyscale images
						UpperCAmelCase_:		Union[str, Any]							      =     1
						UpperCAmelCase_:		str							      =     ViTForImageClassification(SCREAMING_SNAKE_CASE_					)
						model.to(SCREAMING_SNAKE_CASE_					)
						model.eval()

						UpperCAmelCase_:		Dict							      =     floats_tensor([self.batch_size, 1, self.image_size, self.image_size]					)
						UpperCAmelCase_:		str							      =     model(SCREAMING_SNAKE_CASE_					)
						self.parent.assertEqual(result.logits.shape,   (self.batch_size, self.type_sequence_label_size)					)

			def      __snake_case       (self					)       ->   List[str]:
						UpperCAmelCase_:		Any							      =     self.prepare_config_and_inputs()
						(
						    (
						    UpperCAmelCase_
						)      ,							(
						    UpperCAmelCase_
						)      ,							(
						    UpperCAmelCase_
						)      ,							
						):		List[Any]							      =     config_and_inputs
						UpperCAmelCase_:		Union[str, Any]							      =     {"""pixel_values""": pixel_values}
						return config, inputs_dict







@require_torch
class 				_a				(   _lowerCAmelCase ,		_lowerCAmelCase ,		unittest.TestCase					):
			A      		=	(
			    (
			        ViTModel,
			        ViTForImageClassification,
			        ViTForMaskedImageModeling,
			    )
			    if is_torch_available()
			    else ()
			)
			A      		=	(
			    {'''feature-extraction''': ViTModel, '''image-classification''': ViTForImageClassification}
			    if is_torch_available()
			    else {}
			)
			A      		=	True

			A      		=	False
			A      		=	False
			A      		=	False

			def      __snake_case       (self					)       ->   List[str]:
						UpperCAmelCase_:		Any							      =     ViTModelTester(self					)
						UpperCAmelCase_:		List[str]							      =     ConfigTester(self,   config_class=SCREAMING_SNAKE_CASE_,   has_text_modality=SCREAMING_SNAKE_CASE_,   hidden_size=37					)

			def      __snake_case       (self					)       ->   int:
						self.config_tester.run_common_tests()

			@unittest.skip(reason="""ViT does not use inputs_embeds"""					)
			def      __snake_case       (self					)       ->   int:
						pass

			def      __snake_case       (self					)       ->   List[str]:
						UpperCAmelCase_      ,							UpperCAmelCase_:		Optional[int]							      =     self.model_tester.prepare_config_and_inputs_for_common()

						for model_class in self.all_model_classes:
									UpperCAmelCase_:		str							      =     model_class(SCREAMING_SNAKE_CASE_					)
									self.assertIsInstance(model.get_input_embeddings(),   (nn.Module)					)
									UpperCAmelCase_:		int							      =     model.get_output_embeddings()
									self.assertTrue(x is None or isinstance(SCREAMING_SNAKE_CASE_,   nn.Linear					)					)

			def      __snake_case       (self					)       ->   Dict:
						UpperCAmelCase_      ,							UpperCAmelCase_:		List[str]							      =     self.model_tester.prepare_config_and_inputs_for_common()

						for model_class in self.all_model_classes:
									UpperCAmelCase_:		Union[str, Any]							      =     model_class(SCREAMING_SNAKE_CASE_					)
									UpperCAmelCase_:		Dict							      =     inspect.signature(model.forward					)
									# signature.parameters is an OrderedDict => so arg_names order is deterministic
									UpperCAmelCase_:		Tuple							      =     [*signature.parameters.keys()]

									UpperCAmelCase_:		Tuple							      =     ["""pixel_values"""]
									self.assertListEqual(arg_names[:1],   SCREAMING_SNAKE_CASE_					)

			def      __snake_case       (self					)       ->   List[Any]:
						UpperCAmelCase_:		str							      =     self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_model(*SCREAMING_SNAKE_CASE_					)

			def      __snake_case       (self					)       ->   Tuple:
						UpperCAmelCase_:		Tuple							      =     self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_masked_image_modeling(*SCREAMING_SNAKE_CASE_					)

			def      __snake_case       (self					)       ->   int:
						UpperCAmelCase_:		Optional[Any]							      =     self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_image_classification(*SCREAMING_SNAKE_CASE_					)

			@slow
			def      __snake_case       (self					)       ->   Optional[int]:
						for model_name in VIT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
									UpperCAmelCase_:		Union[str, Any]							      =     ViTModel.from_pretrained(SCREAMING_SNAKE_CASE_					)
									self.assertIsNotNone(SCREAMING_SNAKE_CASE_					)







def  lowerCAmelCase_	():





			"""simple docstring"""


			UpperCAmelCase_:		str							      =     Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png"""  )
			return image







@require_torch
@require_vision
class 				_a				(   unittest.TestCase					):

			@cached_property
			def      __snake_case       (self					)       ->   Union[str, Any]:
						return ViTImageProcessor.from_pretrained("""google/vit-base-patch16-224"""					) if is_vision_available() else None

			@slow
			def      __snake_case       (self					)       ->   Optional[Any]:
						UpperCAmelCase_:		Union[str, Any]							      =     ViTForImageClassification.from_pretrained("""google/vit-base-patch16-224"""					).to(SCREAMING_SNAKE_CASE_					)

						UpperCAmelCase_:		int							      =     self.default_image_processor
						UpperCAmelCase_:		Optional[int]							      =     prepare_img()
						UpperCAmelCase_:		List[Any]							      =     image_processor(images=SCREAMING_SNAKE_CASE_,   return_tensors="""pt"""					).to(SCREAMING_SNAKE_CASE_					)

						# forward pass
						with torch.no_grad():
									UpperCAmelCase_:		Optional[int]							      =     model(**SCREAMING_SNAKE_CASE_					)

						# verify the logits
						UpperCAmelCase_:		Optional[Any]							      =     torch.Size((1, 1000)					)
						self.assertEqual(outputs.logits.shape,   SCREAMING_SNAKE_CASE_					)

						UpperCAmelCase_:		Tuple							      =     torch.tensor([-0.2_7_4_4, 0.8_2_1_5, -0.0_8_3_6]					).to(SCREAMING_SNAKE_CASE_					)

						self.assertTrue(torch.allclose(outputs.logits[0, :3],   SCREAMING_SNAKE_CASE_,   atol=1E-4					)					)

			@slow
			def      __snake_case       (self					)       ->   Any:
						# ViT models have an `interpolate_pos_encoding` argument in their forward method,
						# allowing to interpolate the pre-trained position embeddings in order to use
						# the model on higher resolutions. The DINO model by Facebook AI leverages this
						# to visualize self-attention on higher resolution images.
						UpperCAmelCase_:		Union[str, Any]							      =     ViTModel.from_pretrained("""facebook/dino-vits8"""					).to(SCREAMING_SNAKE_CASE_					)

						UpperCAmelCase_:		int							      =     ViTImageProcessor.from_pretrained("""facebook/dino-vits8""",   size=480					)
						UpperCAmelCase_:		int							      =     prepare_img()
						UpperCAmelCase_:		List[Any]							      =     image_processor(images=SCREAMING_SNAKE_CASE_,   return_tensors="""pt"""					)
						UpperCAmelCase_:		List[Any]							      =     inputs.pixel_values.to(SCREAMING_SNAKE_CASE_					)

						# forward pass
						with torch.no_grad():
									UpperCAmelCase_:		int							      =     model(SCREAMING_SNAKE_CASE_,   interpolate_pos_encoding=SCREAMING_SNAKE_CASE_					)

						# verify the logits
						UpperCAmelCase_:		Any							      =     torch.Size((1, 3601, 384)					)
						self.assertEqual(outputs.last_hidden_state.shape,   SCREAMING_SNAKE_CASE_					)

						UpperCAmelCase_:		Optional[int]							      =     torch.tensor(
						    [[4.2_3_4_0, 4.3_9_0_6, -6.6_6_9_2], [4.5_4_6_3, 1.8_9_2_8, -6.7_2_5_7], [4.4_4_2_9, 0.8_4_9_6, -5.8_5_8_5]]					).to(SCREAMING_SNAKE_CASE_					)

						self.assertTrue(torch.allclose(outputs.last_hidden_state[0, :3, :3],   SCREAMING_SNAKE_CASE_,   atol=1E-4					)					)

			@slow
			@require_accelerate
			@require_torch_gpu
			def      __snake_case       (self					)       ->   Dict:
						UpperCAmelCase_:		str							      =     ViTModel.from_pretrained("""facebook/dino-vits8""",   torch_dtype=torch.floataa,   device_map="""auto"""					)
						UpperCAmelCase_:		str							      =     self.default_image_processor

						UpperCAmelCase_:		Any							      =     prepare_img()
						UpperCAmelCase_:		List[str]							      =     image_processor(images=SCREAMING_SNAKE_CASE_,   return_tensors="""pt"""					)
						UpperCAmelCase_:		Optional[int]							      =     inputs.pixel_values.to(SCREAMING_SNAKE_CASE_					)

						# forward pass to make sure inference works in fp16
						with torch.no_grad():
									UpperCAmelCase_:		List[Any]							      =     model(SCREAMING_SNAKE_CASE_					)











import logging
import os
from dataclasses import dataclass
from typing import List, Optional, Union

import tqdm
from filelock import FileLock

from transformers import (
    BartTokenizer,
    BartTokenizerFast,
    DataProcessor,
    PreTrainedTokenizer,
    RobertaTokenizer,
    RobertaTokenizerFast,
    XLMRobertaTokenizer,
    is_tf_available,
    is_torch_available,
)


a      :  Optional[Any]			     =			logging.getLogger(__name__)







@dataclass(frozen=_lowerCAmelCase					)
class 				_a				:
			A      		=	42
			A      		=	42
			A      		=	None
			A      		=	None
			A      		=	None







@dataclass(frozen=_lowerCAmelCase					)
class 				_a				:
			A      		=	42
			A      		=	None
			A      		=	None
			A      		=	None
			A      		=	None


if is_torch_available():
	import torch
	from torch.utils.data import Dataset







	class 				_a				(   _lowerCAmelCase					):
				A      		=	42

				def __init__(self,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_ = None,   SCREAMING_SNAKE_CASE_=False,   SCREAMING_SNAKE_CASE_ = False,   )       ->   Union[str, Any]:
							UpperCAmelCase_:		Optional[Any]							      =     hans_processors[task]()

							UpperCAmelCase_:		Dict							      =     os.path.join(
							    SCREAMING_SNAKE_CASE_,   """cached_{}_{}_{}_{}""".format(
							        """dev""" if evaluate else """train""",   tokenizer.__class__.__name__,   str(SCREAMING_SNAKE_CASE_					),   SCREAMING_SNAKE_CASE_,   ),   )
							UpperCAmelCase_:		Dict							      =     processor.get_labels()
							if tokenizer.__class__ in (
							    RobertaTokenizer,
							    RobertaTokenizerFast,
							    XLMRobertaTokenizer,
							    BartTokenizer,
							    BartTokenizerFast,
							):
										# HACK(label indices are swapped in RoBERTa pretrained model)
										UpperCAmelCase_      ,							UpperCAmelCase_:		Tuple							      =     label_list[2], label_list[1]
							UpperCAmelCase_:		str							      =     label_list

							# Make sure only the first process in distributed training processes the dataset,
							# and the others will use the cache.
							UpperCAmelCase_:		int							      =     cached_features_file + """.lock"""
							with FileLock(SCREAMING_SNAKE_CASE_					):
										if os.path.exists(SCREAMING_SNAKE_CASE_					) and not overwrite_cache:
													logger.info(f'Loading features from cached file {cached_features_file}'					)
													UpperCAmelCase_:		Dict							      =     torch.load(SCREAMING_SNAKE_CASE_					)
										else:
													logger.info(f'Creating features from dataset file at {data_dir}'					)

													UpperCAmelCase_:		Union[str, Any]							      =     (
													    processor.get_dev_examples(SCREAMING_SNAKE_CASE_					) if evaluate else processor.get_train_examples(SCREAMING_SNAKE_CASE_					)
													)

													logger.info("""Training examples: %s""",   len(SCREAMING_SNAKE_CASE_					)					)
													UpperCAmelCase_:		List[Any]							      =     hans_convert_examples_to_features(SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_					)
													logger.info("""Saving features into cached file %s""",   SCREAMING_SNAKE_CASE_					)
													torch.save(self.features,   SCREAMING_SNAKE_CASE_					)

				def __len__(self					)       ->   Optional[int]:
							return len(self.features					)

				def __getitem__(self,   SCREAMING_SNAKE_CASE_					)       ->   InputFeatures:
							return self.features[i]

				def      __snake_case       (self					)       ->   List[str]:
							return self.label_list


if is_tf_available():
	import tensorflow as tf







	class 				_a				:
				A      		=	42

				def __init__(self,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_ = 128,   SCREAMING_SNAKE_CASE_=False,   SCREAMING_SNAKE_CASE_ = False,   )       ->   Optional[int]:
							UpperCAmelCase_:		Union[str, Any]							      =     hans_processors[task]()
							UpperCAmelCase_:		List[Any]							      =     processor.get_labels()
							if tokenizer.__class__ in (
							    RobertaTokenizer,
							    RobertaTokenizerFast,
							    XLMRobertaTokenizer,
							    BartTokenizer,
							    BartTokenizerFast,
							):
										# HACK(label indices are swapped in RoBERTa pretrained model)
										UpperCAmelCase_      ,							UpperCAmelCase_:		List[str]							      =     label_list[2], label_list[1]
							UpperCAmelCase_:		Dict							      =     label_list

							UpperCAmelCase_:		List[str]							      =     processor.get_dev_examples(SCREAMING_SNAKE_CASE_					) if evaluate else processor.get_train_examples(SCREAMING_SNAKE_CASE_					)
							UpperCAmelCase_:		Any							      =     hans_convert_examples_to_features(SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_					)

							def gen():
										for ex_index, ex in tqdm.tqdm(enumerate(self.features					),   desc="""convert examples to features"""					):
													if ex_index % 10000 == 0:
																logger.info("""Writing example %d of %d""" % (ex_index, len(SCREAMING_SNAKE_CASE_					))					)

													yield (
													    {
													        "example_id": 0,
													        "input_ids": ex.input_ids,
													        "attention_mask": ex.attention_mask,
													        "token_type_ids": ex.token_type_ids,
													    },
													    ex.label,
													)

							UpperCAmelCase_:		List[str]							      =     tf.data.Dataset.from_generator(
							    SCREAMING_SNAKE_CASE_,   (
							        {
							            """example_id""": tf.intaa,
							            """input_ids""": tf.intaa,
							            """attention_mask""": tf.intaa,
							            """token_type_ids""": tf.intaa,
							        },
							        tf.intaa,
							    ),   (
							        {
							            """example_id""": tf.TensorShape([]					),
							            """input_ids""": tf.TensorShape([None, None]					),
							            """attention_mask""": tf.TensorShape([None, None]					),
							            """token_type_ids""": tf.TensorShape([None, None]					),
							        },
							        tf.TensorShape([]					),
							    ),   )

				def      __snake_case       (self					)       ->   Optional[Any]:
							return self.dataset

				def __len__(self					)       ->   Optional[int]:
							return len(self.features					)

				def __getitem__(self,   SCREAMING_SNAKE_CASE_					)       ->   InputFeatures:
							return self.features[i]

				def      __snake_case       (self					)       ->   Union[str, Any]:
							return self.label_list







class 				_a				(   _lowerCAmelCase					):

			def      __snake_case       (self,   SCREAMING_SNAKE_CASE_					)       ->   Dict:
						return self._create_examples(self._read_tsv(os.path.join(SCREAMING_SNAKE_CASE_,   """heuristics_train_set.txt"""					)					),   """train"""					)

			def      __snake_case       (self,   SCREAMING_SNAKE_CASE_					)       ->   Dict:
						return self._create_examples(self._read_tsv(os.path.join(SCREAMING_SNAKE_CASE_,   """heuristics_evaluation_set.txt"""					)					),   """dev"""					)

			def      __snake_case       (self					)       ->   Optional[int]:
						return ["contradiction", "entailment", "neutral"]

			def      __snake_case       (self,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_					)       ->   List[Any]:
						UpperCAmelCase_:		Optional[Any]							      =     []
						for i, line in enumerate(SCREAMING_SNAKE_CASE_					):
									if i == 0:
												continue
									UpperCAmelCase_:		Tuple							      =     """%s-%s""" % (set_type, line[0])
									UpperCAmelCase_:		int							      =     line[5]
									UpperCAmelCase_:		int							      =     line[6]
									UpperCAmelCase_:		List[str]							      =     line[7][2:] if line[7].startswith("""ex"""					) else line[7]
									UpperCAmelCase_:		Any							      =     line[0]
									examples.append(InputExample(guid=SCREAMING_SNAKE_CASE_,   text_a=SCREAMING_SNAKE_CASE_,   text_b=SCREAMING_SNAKE_CASE_,   label=SCREAMING_SNAKE_CASE_,   pairID=SCREAMING_SNAKE_CASE_					)					)
						return examples







def  lowerCAmelCase_	(lowerCAmelCase__:		List[InputExample]		,						lowerCAmelCase__:		List[str]		,						lowerCAmelCase__:		int		,						lowerCAmelCase__:		PreTrainedTokenizer		,						):





			"""simple docstring"""


			UpperCAmelCase_:		List[str]							      =     {label: i for i, label in enumerate(lowerCAmelCase__  )}

			UpperCAmelCase_:		Optional[int]							      =     []
			for ex_index, example in tqdm.tqdm(enumerate(lowerCAmelCase__  )		,						desc="""convert examples to features"""  ):
						if ex_index % 1_0_0_0_0 == 0:
									logger.info("""Writing example %d""" % (ex_index)  )

						UpperCAmelCase_:		Tuple							      =     tokenizer(
						    example.text_a		,						example.text_b		,						add_special_tokens=lowerCAmelCase__		,						max_length=lowerCAmelCase__		,						padding="""max_length"""		,						truncation=lowerCAmelCase__		,						return_overflowing_tokens=lowerCAmelCase__		,						)

						UpperCAmelCase_:		Optional[Any]							      =     label_map[example.label] if example.label in label_map else 0

						UpperCAmelCase_:		Tuple							      =     int(example.pairID  )

						features.append(InputFeatures(**lowerCAmelCase__		,						label=lowerCAmelCase__		,						pairID=lowerCAmelCase__  )  )

			for i, example in enumerate(examples[:5]  ):
						logger.info("""*** Example ***"""  )
						logger.info(F'guid: {example}'  )
						logger.info(F'features: {features[i]}'  )

			return features


a      :  Optional[int]			     =			{
    'hans': 3,
}

a      :  Dict			     =			{
    'hans': HansProcessor,
}






