



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=__UpperCAmelCase					)
class 					_A :
       UpperCamelCase__						:					str
       UpperCamelCase__						:					str
       UpperCamelCase__						:					Optional[str]		      =		None
       UpperCamelCase__						:					Optional[str]		      =		None
       UpperCamelCase__						:					Optional[str]		      =		None


@dataclass(frozen=__UpperCAmelCase					)
class 					_A :
       UpperCamelCase__						:					List[int]
       UpperCamelCase__						:					Optional[List[int]]		      =		None
       UpperCamelCase__						:					Optional[List[int]]		      =		None
       UpperCamelCase__						:					Optional[Union[int, float]]		      =		None
       UpperCamelCase__						:					Optional[int]		      =		None


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

 class 					_A (			__UpperCAmelCase					):
        UpperCamelCase__						:					List[InputFeatures]



        def __init__(	self							:  List[Any]  ,	__SCREAMING_SNAKE_CASE							:  str  ,	__SCREAMING_SNAKE_CASE							:  PreTrainedTokenizer  ,	__SCREAMING_SNAKE_CASE							:  str  ,	__SCREAMING_SNAKE_CASE							:  Optional[int] = None  ,	__SCREAMING_SNAKE_CASE							:  Tuple=False  ,	__SCREAMING_SNAKE_CASE							:  bool = False  ,	):


            '''simple docstring'''

            __a		 =       hans_processors[task]()

            __a		 =       os.path.join(
                __SCREAMING_SNAKE_CASE  ,	'''cached_{}_{}_{}_{}'''.format(
                    '''dev''' if evaluate else '''train'''  ,	tokenizer.__class__.__name__  ,	str(__SCREAMING_SNAKE_CASE)  ,	__SCREAMING_SNAKE_CASE  ,	)  ,	)
            __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(__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}')
                    __a		 =       torch.load(__SCREAMING_SNAKE_CASE)
                else:
                    logger.info(F'Creating features from dataset file at {data_dir}')

                    __a		 =       (
                        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))
                    __a		 =       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							:  Tuple):


            '''simple docstring'''

            return len(self.features)



        def __getitem__(	self							:  Tuple  ,	__SCREAMING_SNAKE_CASE							:  Optional[int]):


            '''simple docstring'''

            return self.features[i]





        def 	_lowerCamelCase    (	self							:  Dict):


            '''simple docstring'''

            return self.label_list


if is_tf_available():
 import tensorflow as tf

 class 					_A :
        UpperCamelCase__						:					List[InputFeatures]



        def __init__(	self							:  Optional[int]  ,	__SCREAMING_SNAKE_CASE							:  str  ,	__SCREAMING_SNAKE_CASE							:  PreTrainedTokenizer  ,	__SCREAMING_SNAKE_CASE							:  str  ,	__SCREAMING_SNAKE_CASE							:  Optional[int] = 128  ,	__SCREAMING_SNAKE_CASE							:  Union[str, Any]=False  ,	__SCREAMING_SNAKE_CASE							:  bool = False  ,	):


            '''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(__SCREAMING_SNAKE_CASE) if evaluate else processor.get_train_examples(__SCREAMING_SNAKE_CASE)
            __a		 =       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 % 10_000 == 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,
                    )

            __a		 =       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 	_lowerCamelCase    (	self							:  Dict):


            '''simple docstring'''

            return self.dataset



        def __len__(	self							:  Dict):


            '''simple docstring'''

            return len(self.features)



        def __getitem__(	self							:  str  ,	__SCREAMING_SNAKE_CASE							:  Optional[int]):


            '''simple docstring'''

            return self.features[i]





        def 	_lowerCamelCase    (	self							:  int):


            '''simple docstring'''

            return self.label_list

class 					_A (			__UpperCAmelCase					):



       def 	_lowerCamelCase    (	self							:  Optional[int]  ,	__SCREAMING_SNAKE_CASE							:  Any):


           '''simple docstring'''

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



       def 	_lowerCamelCase    (	self							:  Union[str, Any]  ,	__SCREAMING_SNAKE_CASE							:  Tuple):


           '''simple docstring'''

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



       def 	_lowerCamelCase    (	self							:  int):


           '''simple docstring'''

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





       def 	_lowerCamelCase    (	self							:  Union[str, Any]  ,	__SCREAMING_SNAKE_CASE							:  List[str]  ,	__SCREAMING_SNAKE_CASE							:  Optional[Any]):


           '''simple docstring'''

           __a		 =       []
           for i, line in enumerate(__SCREAMING_SNAKE_CASE):
               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=__SCREAMING_SNAKE_CASE  ,	text_a=__SCREAMING_SNAKE_CASE  ,	text_b=__SCREAMING_SNAKE_CASE  ,	label=__SCREAMING_SNAKE_CASE  ,	pairID=__SCREAMING_SNAKE_CASE))
           return examples





def   __snake_case			(    _UpperCAmelCase     ,				_UpperCAmelCase     ,				_UpperCAmelCase     ,				_UpperCAmelCase     ,				):
    __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 % 10000 == 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		:Union[str, Any]   	=  {
    '''hans''': 3,
}
__snake_case		:List[Any]   	=  {
    '''hans''': HansProcessor,
}










from collections.abc import Generator
from math import sin





def   __snake_case			(    _UpperCAmelCase       ):
    if len(_UpperCAmelCase       ) != 32:
        raise ValueError('''Input must be of length 32'''       )

    __a		 =       b''''''
    for i in [3, 2, 1, 0]:
        little_endian += string_aa[8 * i : 8 * i + 8]
    return little_endian





def   __snake_case			(    _UpperCAmelCase       ):
    if i < 0:
        raise ValueError('''Input must be non-negative'''       )

    __a		 =       format(_UpperCAmelCase     ,				'''08x'''       )[-8:]
    __a		 =       b''''''
    for i in [3, 2, 1, 0]:
        little_endian_hex += hex_rep[2 * i : 2 * i + 2].encode('''utf-8'''       )
    return little_endian_hex





def   __snake_case			(    _UpperCAmelCase       ):
    __a		 =       b''''''
    for char in message:
        bit_string += format(_UpperCAmelCase     ,				'''08b'''       ).encode('''utf-8'''       )
    __a		 =       format(len(_UpperCAmelCase       )     ,				'''064b'''       ).encode('''utf-8'''       )

    # Pad bit_string to a multiple of 512 chars
    bit_string += b"1"
    while len(_UpperCAmelCase       ) % 512 != 448:
        bit_string += b"0"
    bit_string += to_little_endian(start_len[32:]       ) + to_little_endian(start_len[:32]       )

    return bit_string





def   __snake_case			(    _UpperCAmelCase       ):
    if len(_UpperCAmelCase       ) % 512 != 0:
        raise ValueError('''Input must have length that\'s a multiple of 512'''       )

    for pos in range(0     ,				len(_UpperCAmelCase       )     ,				512       ):
        __a		 =       bit_string[pos : pos + 512]
        __a		 =       []
        for i in range(0     ,				512     ,				32       ):
            block_words.append(int(to_little_endian(block[i : i + 32]       )     ,				2       )       )
        yield block_words





def   __snake_case			(    _UpperCAmelCase       ):
    if i < 0:
        raise ValueError('''Input must be non-negative'''       )

    __a		 =       format(_UpperCAmelCase     ,				'''032b'''       )
    __a		 =       ''''''
    for c in i_str:
        new_str += "1" if c == "0" else "0"
    return int(_UpperCAmelCase     ,				2       )





def   __snake_case			(    _UpperCAmelCase     ,				_UpperCAmelCase       ):
    return (a + b) % 2**32





def   __snake_case			(    _UpperCAmelCase     ,				_UpperCAmelCase       ):
    if i < 0:
        raise ValueError('''Input must be non-negative'''       )
    if shift < 0:
        raise ValueError('''Shift must be non-negative'''       )
    return ((i << shift) ^ (i >> (32 - shift))) % 2**32





def   __snake_case			(    _UpperCAmelCase       ):
    __a		 =       preprocess(_UpperCAmelCase       )

    __a		 =       [int(2**32 * abs(sin(i + 1       )       )       ) for i in range(64       )]

    # Starting states
    __a		 =       0X67_452_301
    __a		 =       0Xef_cda_b89
    __a		 =       0X98_bad_cfe
    __a		 =       0X10_325_476

    __a		 =       [
        7,
        12,
        17,
        22,
        7,
        12,
        17,
        22,
        7,
        12,
        17,
        22,
        7,
        12,
        17,
        22,
        5,
        9,
        14,
        20,
        5,
        9,
        14,
        20,
        5,
        9,
        14,
        20,
        5,
        9,
        14,
        20,
        4,
        11,
        16,
        23,
        4,
        11,
        16,
        23,
        4,
        11,
        16,
        23,
        4,
        11,
        16,
        23,
        6,
        10,
        15,
        21,
        6,
        10,
        15,
        21,
        6,
        10,
        15,
        21,
        6,
        10,
        15,
        21,
    ]

    # Process bit string in chunks, each with 16 32-char words
    for block_words in get_block_words(_UpperCAmelCase       ):
        __a		 =       aa
        __a		 =       ba
        __a		 =       ca
        __a		 =       da

        # Hash current chunk
        for i in range(64       ):
            if i <= 15:
                # f = (b & c) | (not_32(b) & d)     # Alternate definition for f
                __a		 =       d ^ (b & (c ^ d))
                __a		 =       i
            elif i <= 31:
                # f = (d & b) | (not_32(d) & c)     # Alternate definition for f
                __a		 =       c ^ (d & (b ^ c))
                __a		 =       (5 * i + 1) % 16
            elif i <= 47:
                __a		 =       b ^ c ^ d
                __a		 =       (3 * i + 5) % 16
            else:
                __a		 =       c ^ (b | not_aa(_UpperCAmelCase       ))
                __a		 =       (7 * i) % 16
            __a		 =       (f + a + added_consts[i] + block_words[g]) % 2**32
            __a		 =       d
            __a		 =       c
            __a		 =       b
            __a		 =       sum_aa(_UpperCAmelCase     ,				left_rotate_aa(_UpperCAmelCase     ,				shift_amounts[i]       )       )

        # Add hashed chunk to running total
        __a		 =       sum_aa(_UpperCAmelCase     ,				_UpperCAmelCase       )
        __a		 =       sum_aa(_UpperCAmelCase     ,				_UpperCAmelCase       )
        __a		 =       sum_aa(_UpperCAmelCase     ,				_UpperCAmelCase       )
        __a		 =       sum_aa(_UpperCAmelCase     ,				_UpperCAmelCase       )

    __a		 =       reformat_hex(_UpperCAmelCase       ) + reformat_hex(_UpperCAmelCase       ) + reformat_hex(_UpperCAmelCase       ) + reformat_hex(_UpperCAmelCase       )
    return digest


if __name__ == "__main__":
 import doctest

 doctest.testmod()





