




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


_snake_case   :   int     							=	logging.getLogger(__name__)

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



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


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

				class     A					(	_a					):
											lowercase_           =       42







											def __init__(						self :						Tuple							,    lowerCAmelCase_ :						str							,    lowerCAmelCase_ :						PreTrainedTokenizer							,    lowerCAmelCase_ :						str							,    lowerCAmelCase_ :						Optional[int] = None							,    lowerCAmelCase_ :						List[str]=False							,    lowerCAmelCase_ :						bool = False							,    )    ->							Optional[int]:


																		"""simple docstring"""


																		_a			  =       hans_processors[task]()

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

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

																																_a			  =       (
																																    processor.get_dev_examples(lowerCAmelCase_      ) if evaluate else processor.get_train_examples(lowerCAmelCase_      )
																																)

																																logger.info('''Training examples: %s'''							,    len(lowerCAmelCase_      )      )
																																_a			  =       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 :						str      )    ->							int:


																		"""simple docstring"""


																		return len(self.features      )







											def __getitem__(						self :						Dict							,    lowerCAmelCase_ :						Tuple      )    ->							InputFeatures:


																		"""simple docstring"""


																		return self.features[i]







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


																		"""simple docstring"""


																		return self.label_list


if is_tf_available():
				import tensorflow as tf

				class     A					:
											lowercase_           =       42







											def __init__(						self :						Optional[Any]							,    lowerCAmelCase_ :						str							,    lowerCAmelCase_ :						PreTrainedTokenizer							,    lowerCAmelCase_ :						str							,    lowerCAmelCase_ :						Optional[int] = 1_28							,    lowerCAmelCase_ :						Optional[int]=False							,    lowerCAmelCase_ :						bool = False							,    )    ->							Tuple:


																		"""simple docstring"""


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

																		_a			  =       processor.get_dev_examples(lowerCAmelCase_      ) if evaluate else processor.get_train_examples(lowerCAmelCase_      )
																		_a			  =       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_00_00 == 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,
																																)

																		_a			  =       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      __lowerCAmelCase    (						self :						Tuple      )    ->							Optional[int]:


																		"""simple docstring"""


																		return self.dataset







											def __len__(						self :						int      )    ->							Dict:


																		"""simple docstring"""


																		return len(self.features      )







											def __getitem__(						self :						List[str]							,    lowerCAmelCase_ :						Union[str, Any]      )    ->							InputFeatures:


																		"""simple docstring"""


																		return self.features[i]







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


																		"""simple docstring"""


																		return self.label_list

class     A					(	_a					):







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


														"""simple docstring"""


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







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


														"""simple docstring"""


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







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


														"""simple docstring"""


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







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


														"""simple docstring"""


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



def 	snake_case_					(UpperCamelCase :						List[InputExample]				,		UpperCamelCase :						List[str]				,		UpperCamelCase :						int				,		UpperCamelCase :						PreTrainedTokenizer				,		):





							'''simple docstring'''


							_a			  =       {label: i for i, label in enumerate(UpperCamelCase   )}

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

														_a			  =       tokenizer(
														    example.text_a				,		example.text_b				,		add_special_tokens=UpperCamelCase				,		max_length=UpperCamelCase				,		padding='''max_length'''				,		truncation=UpperCamelCase				,		return_overflowing_tokens=UpperCamelCase				,		)

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

														_a			  =       int(example.pairID   )

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

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

							return features


_snake_case   :   Tuple     							=	{
    'hans': 3,
}

_snake_case   :   List[Any]     							=	{
    'hans': HansProcessor,
}







'''simple docstring'''


import math
import unittest
def 	snake_case_					(UpperCamelCase :						int   ):





							'''simple docstring'''


							assert isinstance(UpperCamelCase				,		UpperCamelCase   ) and (
							    number >= 0
							), "'number' must been an int and positive"

							if 1 < number < 4:
														# 2 and 3 are primes
														return True
							elif number < 2 or number % 2 == 0 or number % 3 == 0:
														# Negatives, 0, 1, all even numbers, all multiples of 3 are not primes
														return False

							# All primes number are in format of 6k +/- 1
							for i in range(5				,		int(math.sqrt(UpperCamelCase   ) + 1   )				,		6   ):
														if number % i == 0 or number % (i + 2) == 0:
																					return False
							return True

class     A					(	unittest.TestCase					):







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


														"""simple docstring"""


														self.assertTrue(is_prime(2      )      )
														self.assertTrue(is_prime(3      )      )
														self.assertTrue(is_prime(5      )      )
														self.assertTrue(is_prime(7      )      )
														self.assertTrue(is_prime(11      )      )
														self.assertTrue(is_prime(13      )      )
														self.assertTrue(is_prime(17      )      )
														self.assertTrue(is_prime(19      )      )
														self.assertTrue(is_prime(23      )      )
														self.assertTrue(is_prime(29      )      )







							def      __lowerCAmelCase    (						self :						Any      )    ->							Dict:


														"""simple docstring"""


														with self.assertRaises(lowerCAmelCase_      ):
																					is_prime(-19      )
														self.assertFalse(
														    is_prime(0      )							,    '''Zero doesn\'t have any positive factors, primes must have exactly two.'''							,    )
														self.assertFalse(
														    is_prime(1      )							,    '''One only has 1 positive factor, primes must have exactly two.'''							,    )
														self.assertFalse(is_prime(2 * 2      )      )
														self.assertFalse(is_prime(2 * 3      )      )
														self.assertFalse(is_prime(3 * 3      )      )
														self.assertFalse(is_prime(3 * 5      )      )
														self.assertFalse(is_prime(3 * 5 * 7      )      )


if __name__ == "__main__":
				unittest.main()

