





"""simple docstring"""





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											=		logging.getLogger(__name__)






@dataclass(frozen=lowerCamelCase__       )
class 					_lowerCAmelCase   :
       """simple docstring"""




       __magic_name__     :str
       __magic_name__     :str
       __magic_name__     :Optional[str]		  =					None
       __magic_name__     :Optional[str]		  =					None
       __magic_name__     :Optional[str]		  =					None






@dataclass(frozen=lowerCamelCase__       )
class 					_lowerCAmelCase   :
       """simple docstring"""




       __magic_name__     :List[int]
       __magic_name__     :Optional[List[int]]		  =					None
       __magic_name__     :Optional[List[int]]		  =					None
       __magic_name__     :Optional[Union[int, float]]		  =					None
       __magic_name__     :Optional[int]		  =					None


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






  class 					_lowerCAmelCase   (     lowerCamelCase__       ):
         """simple docstring"""




         __magic_name__     :List[InputFeatures]






         def __init__(    self    , __UpperCAmelCase    , __UpperCAmelCase    , __UpperCAmelCase    , __UpperCAmelCase = None    , __UpperCAmelCase=False    , __UpperCAmelCase = False    , ):



           '''simple docstring'''

           lowerCAmelCase__			:Optional[Any]											=							hans_processors[task]()

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

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

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

               logger.info('Training examples: %s'    , len(lowerCAmelCase__      )      )
               lowerCAmelCase__			:Tuple											=							hans_convert_examples_to_features(lowerCAmelCase__    , lowerCAmelCase__    , lowerCAmelCase__    , lowerCAmelCase__      )
               logger.info('Saving features into cached file %s'    , lowerCAmelCase__      )
               torch.save(self.features    , lowerCAmelCase__      )






         def __len__(    self      ):



           '''simple docstring'''

           return len(self.features      )






         def __getitem__(    self    , __UpperCAmelCase      ):



           '''simple docstring'''

           return self.features[i]






         def      snake_case						(    self      ):



           '''simple docstring'''

           return self.label_list


if is_tf_available():
  import tensorflow as tf






  class 					_lowerCAmelCase   :
         """simple docstring"""




         __magic_name__     :List[InputFeatures]






         def __init__(    self    , __UpperCAmelCase    , __UpperCAmelCase    , __UpperCAmelCase    , __UpperCAmelCase = 1_2_8    , __UpperCAmelCase=False    , __UpperCAmelCase = False    , ):



           '''simple docstring'''

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

           lowerCAmelCase__			:List[str]											=							processor.get_dev_examples(lowerCAmelCase__      ) if evaluate else processor.get_train_examples(lowerCAmelCase__      )
           lowerCAmelCase__			:Tuple											=							hans_convert_examples_to_features(lowerCAmelCase__    , lowerCAmelCase__    , lowerCAmelCase__    , lowerCAmelCase__      )

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

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

           lowerCAmelCase__			:List[Any]											=							tf.data.Dataset.from_generator(
               lowerCAmelCase__    , (
                   {
                       '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      ):



           '''simple docstring'''

           return self.dataset






         def __len__(    self      ):



           '''simple docstring'''

           return len(self.features      )






         def __getitem__(    self    , __UpperCAmelCase      ):



           '''simple docstring'''

           return self.features[i]






         def      snake_case						(    self      ):



           '''simple docstring'''

           return self.label_list






class 					_lowerCAmelCase   (     lowerCamelCase__       ):
       """simple docstring"""




       def      snake_case						(    self    , __UpperCAmelCase      ):



         '''simple docstring'''

         return self._create_examples(self._read_tsv(os.path.join(lowerCAmelCase__    , 'heuristics_train_set.txt'      )      )    , 'train'      )






       def      snake_case						(    self    , __UpperCAmelCase      ):



         '''simple docstring'''

         return self._create_examples(self._read_tsv(os.path.join(lowerCAmelCase__    , 'heuristics_evaluation_set.txt'      )      )    , 'dev'      )






       def      snake_case						(    self      ):



         '''simple docstring'''

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






       def      snake_case						(    self    , __UpperCAmelCase    , __UpperCAmelCase      ):



         '''simple docstring'''

         lowerCAmelCase__			:Dict											=							[]
         for i, line in enumerate(lowerCAmelCase__      ):
           if i == 0:
             continue
           lowerCAmelCase__			:Any											=							"""%s-%s""" % (set_type, line[0])
           lowerCAmelCase__			:Tuple											=							line[5]
           lowerCAmelCase__			:Dict											=							line[6]
           lowerCAmelCase__			:Tuple											=							line[7][2:] if line[7].startswith('ex'      ) else line[7]
           lowerCAmelCase__			:Tuple											=							line[0]
           examples.append(InputExample(guid=lowerCAmelCase__    , text_a=lowerCAmelCase__    , text_b=lowerCAmelCase__    , label=lowerCAmelCase__    , pairID=lowerCAmelCase__      )      )
         return examples






def  __A   (_SCREAMING_SNAKE_CASE     ,   _SCREAMING_SNAKE_CASE     ,   _SCREAMING_SNAKE_CASE     ,   _SCREAMING_SNAKE_CASE     ,   )					->int:





  """simple docstring"""


  lowerCAmelCase__			:Dict											=							{label: i for i, label in enumerate(_lowerCamelCase			)}

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

    lowerCAmelCase__			:Optional[Any]											=							tokenizer(
        example.text_a     ,   example.text_b     ,   add_special_tokens=_lowerCamelCase     ,   max_length=_lowerCamelCase     ,   padding='max_length'     ,   truncation=_lowerCamelCase     ,   return_overflowing_tokens=_lowerCamelCase     ,   )

    lowerCAmelCase__			:Optional[int]											=							label_map[example.label] if example.label in label_map else 0

    lowerCAmelCase__			:Optional[Any]											=							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											=		{
    '''hans''': 3,
}




__A											=		{
    '''hans''': HansProcessor,
}





'''simple docstring'''




import string


def 				lowerCAmelCase_   (	_lowerCamelCase:   str					):
		__SCREAMING_SNAKE_CASE       :		Dict           =		""""""
		for i in sequence:
				__SCREAMING_SNAKE_CASE       :		Any           =		ord(_lowerCamelCase					)
				if 65 <= extract <= 90:
						output += chr(1_55 - extract					)
				elif 97 <= extract <= 1_22:
						output += chr(2_19 - extract					)
				else:
						output += i
		return output


def 				lowerCAmelCase_   (	_lowerCamelCase:   str					):
		__SCREAMING_SNAKE_CASE       :		Optional[Any]           =		string.ascii_letters
		__SCREAMING_SNAKE_CASE       :		Union[str, Any]           =		string.ascii_lowercase[::-1] + string.ascii_uppercase[::-1]
		return "".join(
		    letters_reversed[letters.index(_lowerCamelCase					)] if c in letters else c for c in sequence					)


def 				lowerCAmelCase_   (	):
		from timeit import timeit

		print("""Running performance benchmarks..."""					)
		__SCREAMING_SNAKE_CASE       :		Union[str, Any]           =		"""from string import printable ; from __main__ import atbash, atbash_slow"""
		print(F"> atbash_slow(): {timeit('atbash_slow(printable)'       ,      setup=_lowerCamelCase					)} seconds"					)
		print(F">      atbash(): {timeit('atbash(printable)'       ,      setup=_lowerCamelCase					)} seconds"					)


if __name__ == "__main__":
						for example in ("ABCDEFGH", "123GGjj", "testStringtest", "with space"):
												print(f"{example} encrypted in atbash: {atbash(example)}")
						benchmark()