


import inspect
import math
import tempfile
import unittest

import numpy as np

from transformers import ViTMAEConfig
from transformers.testing_utils import require_torch, 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 ViTMAEForPreTraining, ViTMAEModel
		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.02     ,       _SCREAMING_SNAKE_CASE=3     ,       _SCREAMING_SNAKE_CASE=0.6     ,       _SCREAMING_SNAKE_CASE=None     ,       )					->			Tuple:




									"""simple docstring"""





									_UpperCAmelCase											=     parent
									_UpperCAmelCase											=     batch_size
									_UpperCAmelCase											=     image_size
									_UpperCAmelCase											=     patch_size
									_UpperCAmelCase											=     num_channels
									_UpperCAmelCase											=     is_training
									_UpperCAmelCase											=     use_labels
									_UpperCAmelCase											=     hidden_size
									_UpperCAmelCase											=     num_hidden_layers
									_UpperCAmelCase											=     num_attention_heads
									_UpperCAmelCase											=     intermediate_size
									_UpperCAmelCase											=     hidden_act
									_UpperCAmelCase											=     hidden_dropout_prob
									_UpperCAmelCase											=     attention_probs_dropout_prob
									_UpperCAmelCase											=     type_sequence_label_size
									_UpperCAmelCase											=     initializer_range
									_UpperCAmelCase											=     mask_ratio
									_UpperCAmelCase											=     scope

									# in ViTMAE, the expected sequence length = (num_patches + 1) * (1 - config.mask_ratio), rounded above
									# (we add 1 for the [CLS] token)
									_UpperCAmelCase											=     (image_size // patch_size) ** 2
									_UpperCAmelCase											=     int(math.ceil((1 - mask_ratio) * (num_patches + 1)		)		)
		def       UpperCAmelCase__							(     self		)					->			Optional[Any]:




									"""simple docstring"""





									_UpperCAmelCase											=     floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]		)

									_UpperCAmelCase											=     None
									if self.use_labels:
																_UpperCAmelCase											=     ids_tensor([self.batch_size]     ,       self.type_sequence_label_size		)

									_UpperCAmelCase											=     self.get_config()

									return config, pixel_values, labels
		def       UpperCAmelCase__							(     self		)					->			List[Any]:




									"""simple docstring"""





									return ViTMAEConfig(
									    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     ,       mask_ratio=self.mask_ratio     ,       )
		def       UpperCAmelCase__							(     self     ,       _SCREAMING_SNAKE_CASE     ,       _SCREAMING_SNAKE_CASE     ,       _SCREAMING_SNAKE_CASE		)					->			Optional[Any]:




									"""simple docstring"""





									_UpperCAmelCase											=     ViTMAEModel(config=_SCREAMING_SNAKE_CASE		)
									model.to(_SCREAMING_SNAKE_CASE		)
									model.eval()
									_UpperCAmelCase											=     model(_SCREAMING_SNAKE_CASE		)
									self.parent.assertEqual(result.last_hidden_state.shape     ,       (self.batch_size, self.seq_length, self.hidden_size)		)
		def       UpperCAmelCase__							(     self     ,       _SCREAMING_SNAKE_CASE     ,       _SCREAMING_SNAKE_CASE     ,       _SCREAMING_SNAKE_CASE		)					->			int:




									"""simple docstring"""





									_UpperCAmelCase											=     ViTMAEForPreTraining(_SCREAMING_SNAKE_CASE		)
									model.to(_SCREAMING_SNAKE_CASE		)
									model.eval()
									_UpperCAmelCase											=     model(_SCREAMING_SNAKE_CASE		)
									_UpperCAmelCase											=     (self.image_size // self.patch_size) ** 2
									_UpperCAmelCase											=     self.patch_size**2 * self.num_channels
									self.parent.assertEqual(result.logits.shape     ,       (self.batch_size, num_patches, expected_num_channels)		)

									# test greyscale images
									_UpperCAmelCase											=     1
									_UpperCAmelCase											=     ViTMAEForPreTraining(_SCREAMING_SNAKE_CASE		)
									model.to(_SCREAMING_SNAKE_CASE		)
									model.eval()
									_UpperCAmelCase											=     floats_tensor([self.batch_size, 1, self.image_size, self.image_size]		)
									_UpperCAmelCase											=     model(_SCREAMING_SNAKE_CASE		)
									_UpperCAmelCase											=     self.patch_size**2
									self.parent.assertEqual(result.logits.shape     ,       (self.batch_size, num_patches, expected_num_channels)		)






		def       UpperCAmelCase__							(     self		)					->			str:




									"""simple docstring"""





									_UpperCAmelCase											=     self.prepare_config_and_inputs()
									_UpperCAmelCase						,			_UpperCAmelCase						,			_UpperCAmelCase											=     config_and_inputs
									_UpperCAmelCase											=     {'pixel_values': pixel_values}
									return config, inputs_dict



@require_torch
class 						__a (							UpperCAmelCase       , UpperCAmelCase       , unittest.TestCase     ):
		_a      :    Tuple           =      (ViTMAEModel, ViTMAEForPreTraining) if is_torch_available() else ()
		_a      :    Any           =      {'feature-extraction': ViTMAEModel} if is_torch_available() else {}

		_a      :    List[Any]           =      False
		_a      :    Union[str, Any]           =      False
		_a      :    List[str]           =      False
		_a      :    str           =      False
		def       UpperCAmelCase__							(     self		)					->			Optional[Any]:




									"""simple docstring"""





									_UpperCAmelCase											=     ViTMAEModelTester(self		)
									_UpperCAmelCase											=     ConfigTester(self     ,       config_class=_SCREAMING_SNAKE_CASE     ,       has_text_modality=_SCREAMING_SNAKE_CASE     ,       hidden_size=37		)
		def       UpperCAmelCase__							(     self		)					->			Union[str, Any]:




									"""simple docstring"""





									self.config_tester.run_common_tests()
		@unittest.skip(reason='ViTMAE does not use inputs_embeds'		)
		def       UpperCAmelCase__							(     self		)					->			str:




									"""simple docstring"""





									pass
		def       UpperCAmelCase__							(     self		)					->			Optional[Any]:




									"""simple docstring"""





									_UpperCAmelCase						,			_UpperCAmelCase											=     self.model_tester.prepare_config_and_inputs_for_common()

									for model_class in self.all_model_classes:
																_UpperCAmelCase											=     model_class(_SCREAMING_SNAKE_CASE		)
																self.assertIsInstance(model.get_input_embeddings()     ,       (nn.Module)		)
																_UpperCAmelCase											=     model.get_output_embeddings()
																self.assertTrue(x is None or isinstance(_SCREAMING_SNAKE_CASE     ,       nn.Linear		)		)
		def       UpperCAmelCase__							(     self		)					->			Optional[Any]:




									"""simple docstring"""





									_UpperCAmelCase						,			_UpperCAmelCase											=     self.model_tester.prepare_config_and_inputs_for_common()

									for model_class in self.all_model_classes:
																_UpperCAmelCase											=     model_class(_SCREAMING_SNAKE_CASE		)
																_UpperCAmelCase											=     inspect.signature(model.forward		)
																# signature.parameters is an OrderedDict => so arg_names order is deterministic
																_UpperCAmelCase											=     [*signature.parameters.keys()]

																_UpperCAmelCase											=     ['pixel_values']
																self.assertListEqual(arg_names[:1]     ,       _SCREAMING_SNAKE_CASE		)
		def       UpperCAmelCase__							(     self		)					->			str:




									"""simple docstring"""





									_UpperCAmelCase											=     self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_model(*_SCREAMING_SNAKE_CASE		)
		def       UpperCAmelCase__							(     self		)					->			Optional[Any]:




									"""simple docstring"""





									_UpperCAmelCase											=     self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_pretraining(*_SCREAMING_SNAKE_CASE		)
		def       UpperCAmelCase__							(     self     ,       _SCREAMING_SNAKE_CASE     ,       _SCREAMING_SNAKE_CASE     ,       _SCREAMING_SNAKE_CASE		)					->			List[Any]:




									"""simple docstring"""





									np.random.seed(2		)

									_UpperCAmelCase											=     int((pt_model.config.image_size // pt_model.config.patch_size) ** 2		)
									_UpperCAmelCase											=     np.random.uniform(size=(self.model_tester.batch_size, num_patches)		)
									_UpperCAmelCase											=     torch.from_numpy(_SCREAMING_SNAKE_CASE		)

									# Add `noise` argument.
									# PT inputs will be prepared in `super().check_pt_tf_models()` with this added `noise` argument
									_UpperCAmelCase											=     pt_noise

									super().check_pt_tf_models(_SCREAMING_SNAKE_CASE     ,       _SCREAMING_SNAKE_CASE     ,       _SCREAMING_SNAKE_CASE		)
		def       UpperCAmelCase__							(     self		)					->			Dict:




									"""simple docstring"""





									_UpperCAmelCase						,			_UpperCAmelCase											=     self.model_tester.prepare_config_and_inputs_for_common()

									for model_class in self.all_model_classes:
																_UpperCAmelCase											=     model_class(_SCREAMING_SNAKE_CASE		)
																model.to(_SCREAMING_SNAKE_CASE		)
																model.eval()
																# make random mask reproducible
																torch.manual_seed(2		)
																with torch.no_grad():
																							_UpperCAmelCase											=     model(**self._prepare_for_class(_SCREAMING_SNAKE_CASE     ,       _SCREAMING_SNAKE_CASE		)		)

																_UpperCAmelCase											=     outputs[0].cpu().numpy()
																_UpperCAmelCase											=     0

																with tempfile.TemporaryDirectory() as tmpdirname:
																							model.save_pretrained(_SCREAMING_SNAKE_CASE		)
																							_UpperCAmelCase											=     model_class.from_pretrained(_SCREAMING_SNAKE_CASE		)
																							model.to(_SCREAMING_SNAKE_CASE		)
																							# make random mask reproducible
																							torch.manual_seed(2		)
																							with torch.no_grad():
																														_UpperCAmelCase											=     model(**self._prepare_for_class(_SCREAMING_SNAKE_CASE     ,       _SCREAMING_SNAKE_CASE		)		)

																							# Make sure we don't have nans
																							_UpperCAmelCase											=     after_outputs[0].cpu().numpy()
																							_UpperCAmelCase											=     0
																							_UpperCAmelCase											=     np.amax(np.abs(out_a - out_a		)		)
																							self.assertLessEqual(_SCREAMING_SNAKE_CASE     ,       1e-5		)
		@unittest.skip(
		    reason='ViTMAE returns a random mask + ids_restore in each forward pass. See test_save_load\n    to get deterministic results.'		)
		def       UpperCAmelCase__							(     self		)					->			List[Any]:




									"""simple docstring"""





									pass
		@unittest.skip(
		    reason='ViTMAE returns a random mask + ids_restore in each forward pass. See test_save_load\n    to get deterministic results.'		)
		def       UpperCAmelCase__							(     self		)					->			Tuple:




									"""simple docstring"""





									pass
		@unittest.skip(
		    reason='ViTMAE returns a random mask + ids_restore in each forward pass. See test_save_load\n    to get deterministic results.'		)
		def       UpperCAmelCase__							(     self		)					->			Any:




									"""simple docstring"""





									pass
		@unittest.skip(reason='ViTMAE returns a random mask + ids_restore in each forward pass. See test_save_load'		)
		def       UpperCAmelCase__							(     self		)					->			Any:




									"""simple docstring"""





									pass
		@unittest.skip('Will be fixed soon by reducing the size of the model used for common tests.'		)
		def       UpperCAmelCase__							(     self		)					->			Optional[Any]:




									"""simple docstring"""





									pass






		@slow
		def       UpperCAmelCase__							(     self		)					->			Optional[Any]:




									"""simple docstring"""





									for model_name in VIT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																_UpperCAmelCase											=     ViTMAEModel.from_pretrained(_SCREAMING_SNAKE_CASE		)
																self.assertIsNotNone(_SCREAMING_SNAKE_CASE		)



def 			lowerCAmelCase__					(     )    ->						Any:


							'''simple docstring'''





							_UpperCAmelCase											=     Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png'			)
							return image







@require_torch
@require_vision
class 						__a (							unittest.TestCase     ):
		@cached_property
		def       UpperCAmelCase__							(     self		)					->			Union[str, Any]:




									"""simple docstring"""





									return ViTImageProcessor.from_pretrained('facebook/vit-mae-base'		) if is_vision_available() else None






		@slow
		def       UpperCAmelCase__							(     self		)					->			List[Any]:




									"""simple docstring"""





									np.random.seed(2		)

									_UpperCAmelCase											=     ViTMAEForPreTraining.from_pretrained('facebook/vit-mae-base'		).to(_SCREAMING_SNAKE_CASE		)

									_UpperCAmelCase											=     self.default_image_processor
									_UpperCAmelCase											=     prepare_img()
									_UpperCAmelCase											=     image_processor(images=_SCREAMING_SNAKE_CASE     ,       return_tensors='pt'		).to(_SCREAMING_SNAKE_CASE		)

									# prepare a noise vector that will be also used for testing the TF model
									# (this way we can ensure that the PT and TF models operate on the same inputs)
									_UpperCAmelCase											=     ViTMAEConfig()
									_UpperCAmelCase											=     int((vit_mae_config.image_size // vit_mae_config.patch_size) ** 2		)
									_UpperCAmelCase											=     np.random.uniform(size=(1, num_patches)		)

									# forward pass
									with torch.no_grad():
																_UpperCAmelCase											=     model(**_SCREAMING_SNAKE_CASE     ,       noise=torch.from_numpy(_SCREAMING_SNAKE_CASE		).to(device=_SCREAMING_SNAKE_CASE		)		)

									# verify the logits
									_UpperCAmelCase											=     torch.Size((1, 196, 768)		)
									self.assertEqual(outputs.logits.shape     ,       _SCREAMING_SNAKE_CASE		)

									_UpperCAmelCase											=     torch.tensor(
									    [[-0.0548, -1.7023, -0.9325], [0.3721, -0.5670, -0.2233], [0.8235, -1.3878, -0.3524]]		)

									self.assertTrue(torch.allclose(outputs.logits[0, :3, :3]     ,       expected_slice.to(_SCREAMING_SNAKE_CASE		)     ,       atol=1e-4		)		)




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


lowerCAmelCase__    :List[str]       =				logging.getLogger(__name__)

@dataclass(frozen=UpperCAmelCase     )
class 						__a :
		_a      :    str
		_a      :    str
		_a      :    Optional[str]           =      None
		_a      :    Optional[str]           =      None
		_a      :    Optional[str]           =      None



@dataclass(frozen=UpperCAmelCase     )
class 						__a :
		_a      :    List[int]
		_a      :    Optional[List[int]]           =      None
		_a      :    Optional[List[int]]           =      None
		_a      :    Optional[Union[int, float]]           =      None
		_a      :    Optional[int]           =      None


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

		class 						__a (							UpperCAmelCase     ):
				_a      :    List[InputFeatures]
				def __init__(     self     ,       _SCREAMING_SNAKE_CASE     ,       _SCREAMING_SNAKE_CASE     ,       _SCREAMING_SNAKE_CASE     ,       _SCREAMING_SNAKE_CASE = None     ,       _SCREAMING_SNAKE_CASE=False     ,       _SCREAMING_SNAKE_CASE = False     ,       )					->			List[Any]:




											"""simple docstring"""





											_UpperCAmelCase											=     hans_processors[task]()

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

											# Make sure only the first process in distributed training processes the dataset,
											# and the others will use the cache.
											_UpperCAmelCase											=     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											=     torch.load(_SCREAMING_SNAKE_CASE		)
																		else:
																									logger.info(f'''Creating features from dataset file at {data_dir}'''		)

																									_UpperCAmelCase											=     (
																									    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											=     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		)					->			List[str]:




											"""simple docstring"""





											return len(self.features		)
				def __getitem__(     self     ,       _SCREAMING_SNAKE_CASE		)					->			InputFeatures:




											"""simple docstring"""





											return self.features[i]






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




											"""simple docstring"""





											return self.label_list


if is_tf_available():
		import tensorflow as tf

		class 						__a :
				_a      :    List[InputFeatures]
				def __init__(     self     ,       _SCREAMING_SNAKE_CASE     ,       _SCREAMING_SNAKE_CASE     ,       _SCREAMING_SNAKE_CASE     ,       _SCREAMING_SNAKE_CASE = 128     ,       _SCREAMING_SNAKE_CASE=False     ,       _SCREAMING_SNAKE_CASE = False     ,       )					->			Tuple:




											"""simple docstring"""





											_UpperCAmelCase											=     hans_processors[task]()
											_UpperCAmelCase											=     processor.get_labels()
											if tokenizer.__class__ in (
											    RobertaTokenizer,
											    RobertaTokenizerFast,
											    XLMRobertaTokenizer,
											    BartTokenizer,
											    BartTokenizerFast,
											):
																		# HACK(label indices are swapped in RoBERTa pretrained model)
																		_UpperCAmelCase						,			_UpperCAmelCase											=     label_list[2], label_list[1]
											_UpperCAmelCase											=     label_list

											_UpperCAmelCase											=     processor.get_dev_examples(_SCREAMING_SNAKE_CASE		) if evaluate else processor.get_train_examples(_SCREAMING_SNAKE_CASE		)
											_UpperCAmelCase											=     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											=     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       UpperCAmelCase__							(     self		)					->			Dict:




											"""simple docstring"""





											return self.dataset
				def __len__(     self		)					->			List[Any]:




											"""simple docstring"""





											return len(self.features		)
				def __getitem__(     self     ,       _SCREAMING_SNAKE_CASE		)					->			InputFeatures:




											"""simple docstring"""





											return self.features[i]






				def       UpperCAmelCase__							(     self		)					->			List[Any]:




											"""simple docstring"""





											return self.label_list

class 						__a (							UpperCAmelCase     ):
		def       UpperCAmelCase__							(     self     ,       _SCREAMING_SNAKE_CASE		)					->			List[Any]:




									"""simple docstring"""





									return self._create_examples(self._read_tsv(os.path.join(_SCREAMING_SNAKE_CASE     ,       'heuristics_train_set.txt'		)		)     ,       'train'		)
		def       UpperCAmelCase__							(     self     ,       _SCREAMING_SNAKE_CASE		)					->			Union[str, Any]:




									"""simple docstring"""





									return self._create_examples(self._read_tsv(os.path.join(_SCREAMING_SNAKE_CASE     ,       'heuristics_evaluation_set.txt'		)		)     ,       'dev'		)
		def       UpperCAmelCase__							(     self		)					->			List[str]:




									"""simple docstring"""





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






		def       UpperCAmelCase__							(     self     ,       _SCREAMING_SNAKE_CASE     ,       _SCREAMING_SNAKE_CASE		)					->			Any:




									"""simple docstring"""





									_UpperCAmelCase											=     []
									for i, line in enumerate(_SCREAMING_SNAKE_CASE		):
																if i == 0:
																							continue
																_UpperCAmelCase											=     '%s-%s' % (set_type, line[0])
																_UpperCAmelCase											=     line[5]
																_UpperCAmelCase											=     line[6]
																_UpperCAmelCase											=     line[7][2:] if line[7].startswith('ex'		) else line[7]
																_UpperCAmelCase											=     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__					(     a__:						List[InputExample]     ,    a__:						List[str]     ,    a__:						int     ,    a__:						PreTrainedTokenizer     ,    )    ->						str:


							'''simple docstring'''





							_UpperCAmelCase											=     {label: i for i, label in enumerate(a__			)}

							_UpperCAmelCase											=     []
							for ex_index, example in tqdm.tqdm(enumerate(a__			)     ,    desc='convert examples to features'			):
														if ex_index % 1_0_0_0_0 == 0:
																					logger.info('Writing example %d' % (ex_index)			)

														_UpperCAmelCase											=     tokenizer(
														    example.text_a     ,    example.text_b     ,    add_special_tokens=a__     ,    max_length=a__     ,    padding='max_length'     ,    truncation=a__     ,    return_overflowing_tokens=a__     ,    )

														_UpperCAmelCase											=     label_map[example.label] if example.label in label_map else 0

														_UpperCAmelCase											=     int(example.pairID			)

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

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

							return features


lowerCAmelCase__    :Optional[Any]       =				{
    '''hans''': 3,
}







lowerCAmelCase__    :Optional[int]       =				{
    '''hans''': HansProcessor,
}
