




from collections import Counter
import datasets
import transformers
from transformers.convert_slow_tokenizer import SLOW_TO_FAST_CONVERTERS

from transformers.utils import logging

logging.set_verbosity_info()

lowercase_		=							{
    name: (getattr(transformers, name), getattr(transformers, name + '''Fast''')) for name in SLOW_TO_FAST_CONVERTERS
}

lowercase_		=							datasets.load_dataset('''xnli''', split='''test+validation''')

lowercase_		=							0
lowercase_		=							0
lowercase_		=							0
lowercase_		=							0







def  lowerCAmelCase  (	UpperCAmelCase,	UpperCAmelCase,	UpperCAmelCase,	UpperCAmelCase       )  ->Optional[int]:






					"""simple docstring"""






					if spm_diff == list(reversed(UpperCAmelCase       )       ):
										# AAA -> AA+A vs A+AA case.
										return True
					elif len(UpperCAmelCase       ) == len(UpperCAmelCase       ) and fast.decode(UpperCAmelCase       ) == fast.decode(UpperCAmelCase       ):
										# Second order OK
										# Barrich -> Barr + ich vs Bar + rich
										return True
					__magic_name__					:							int		   =							slow.encode(slow.decode(UpperCAmelCase       )       )
					__magic_name__					:							int		   =							fast.encode(fast.decode(UpperCAmelCase       )       )
					if spm_reencoded != spm_diff and spm_reencoded == tok_reencoded:
										# Type 3 error.
										# Snehagatha ->
										#       Sne, h, aga, th, a
										#       Sne, ha, gat, ha
										# Encoding the wrong with sp does not even recover what spm gave us
										# It fits tokenizer however...
										return True
					return False







def  lowerCAmelCase  (	UpperCAmelCase,	UpperCAmelCase,	UpperCAmelCase       )  ->str:






					"""simple docstring"""






					__magic_name__					:							Any		   =							fast.encode_plus(UpperCAmelCase       )[0]
					__magic_name__					:							int		   =							enc.offsets
					__magic_name__   , __magic_name__					:							List[str]		   =							offsets[idx], offsets[idx - 1]
					if curr is not None and line[curr[0] : curr[1]] == "\u200f":
										return True
					if prev is not None and line[prev[0] : prev[1]] == "\u200f":
										return True







def  lowerCAmelCase  (	UpperCAmelCase,	UpperCAmelCase,	UpperCAmelCase,	UpperCAmelCase,	UpperCAmelCase       )  ->Dict:






					"""simple docstring"""






					for i, (spm_id, tok_id) in enumerate(zip(UpperCAmelCase,	UpperCAmelCase       )       ):
										if spm_id != tok_id:
															break
					__magic_name__					:							int		   =							i
					for i, (spm_id, tok_id) in enumerate(zip(reversed(UpperCAmelCase       ),	reversed(UpperCAmelCase       )       )       ):
										if spm_id != tok_id:
															break
					__magic_name__					:							str		   =							len(UpperCAmelCase       ) - i

					__magic_name__					:							List[str]		   =							spm_ids[first:last]
					__magic_name__					:							Optional[int]		   =							tok_ids[first:last]

					if check_diff(UpperCAmelCase,	UpperCAmelCase,	UpperCAmelCase,	UpperCAmelCase       ):
										return True

					if check_LTR_mark(UpperCAmelCase,	UpperCAmelCase,	UpperCAmelCase       ):
										return True

					if last - first > 5:
										# We might have twice a single problem, attempt to subdivide the disjointed tokens into smaller problems
										__magic_name__					:							Dict		   =							Counter(spm_ids[first:last]       )
										__magic_name__					:							Optional[Any]		   =							Counter(tok_ids[first:last]       )

										__magic_name__					:							Any		   =							{spm_ for (spm_, si) in spms.items() if toks.get(spm_,	0       ) == si}
										__magic_name__					:							str		   =							3
										for i in range(last - first - min_width       ):
															if all(spm_ids[first + i + j] in removable_tokens for j in range(UpperCAmelCase       )       ):
																				__magic_name__					:							List[str]		   =							[
																				    k
																				    for k in range(last - first - min_width       )
																				    if tok_ids[first + k : first + k + min_width] == spm_ids[first + i : first + i + min_width]
																				]
																				for j in possible_matches:
																									if check_diff(spm_ids[first : first + i],	tok_ids[first : first + j],	UpperCAmelCase,	UpperCAmelCase       ) and check_details(
																									    UpperCAmelCase,	spm_ids[first + i : last],	tok_ids[first + j : last],	UpperCAmelCase,	UpperCAmelCase,	):
																														return True

					print(F'''Spm: {[fast.decode([spm_ids[i]]       ) for i in range(UpperCAmelCase,	UpperCAmelCase       )]}'''       )
					try:
										print(F'''Tok: {[fast.decode([tok_ids[i]]       ) for i in range(UpperCAmelCase,	UpperCAmelCase       )]}'''       )
					except Exception:
										pass

					__magic_name__					:							Optional[Any]		   =							fast.decode(spm_ids[:first]       )
					__magic_name__					:							Optional[int]		   =							fast.decode(spm_ids[last:]       )
					__magic_name__					:							Optional[Any]		   =							fast.decode(spm_ids[first:last]       )
					print()
					print(UpperCAmelCase       )
					return False







def  lowerCAmelCase  (	UpperCAmelCase,	UpperCAmelCase,	UpperCAmelCase       )  ->Dict:






					"""simple docstring"""






					global perfect
					global imperfect
					global wrong
					global total

					__magic_name__					:							Optional[Any]		   =							slow.encode(UpperCAmelCase       )
					__magic_name__					:							Optional[int]		   =							fast.encode(UpperCAmelCase       )

					__magic_name__					:							Any		   =							False
					total += 1

					if slow_ids != fast_ids:
										if check_details(UpperCAmelCase,	UpperCAmelCase,	UpperCAmelCase,	UpperCAmelCase,	UpperCAmelCase       ):
															__magic_name__					:							List[str]		   =							True
															imperfect += 1
										else:
															wrong += 1
					else:
										perfect += 1

					if total % 1_0000 == 0:
										print(F'''({perfect} / {imperfect} / {wrong} ----- {perfect + imperfect + wrong})'''       )

					if skip_assert:
										return

					assert (
					    slow_ids == fast_ids
					), F'''line {text} : \n\n{slow_ids}\n{fast_ids}\n\n{slow.tokenize(UpperCAmelCase       )}\n{fast.tokenize(UpperCAmelCase       )}'''







def  lowerCAmelCase  (	UpperCAmelCase,	UpperCAmelCase       )  ->Any:






					"""simple docstring"""






					global batch_total
					for i in range(len(UpperCAmelCase       )       ):
										# premise, all languages
										for text in dataset[i]["premise"].values():
															test_string(UpperCAmelCase,	UpperCAmelCase,	UpperCAmelCase       )

										# hypothesis, all languages
										for text in dataset[i]["hypothesis"]["translation"]:
															test_string(UpperCAmelCase,	UpperCAmelCase,	UpperCAmelCase       )


if __name__ == "__main__":
				for name, (slow_class, fast_class) in TOKENIZER_CLASSES.items():
								lowercase_		=							list(slow_class.max_model_input_sizes.keys())
								for checkpoint in checkpoint_names:
												lowercase_		=							0
												lowercase_		=							0
												lowercase_		=							0
												lowercase_		=							0

												print(f"========================== Checking {name}: {checkpoint} ==========================")
												lowercase_		=							slow_class.from_pretrained(checkpoint, force_download=True)
												lowercase_		=							fast_class.from_pretrained(checkpoint, force_download=True)
												test_tokenizer(slow, fast)
												print(f"Accuracy {perfect * 100 / total:.2f}")









import random
import sys

from . import cryptomath_module as cryptomath

lowercase_		=							(
    r''' !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`'''
    r'''abcdefghijklmnopqrstuvwxyz{|}~'''
)







def  lowerCAmelCase  (	UpperCAmelCase,	UpperCAmelCase,	UpperCAmelCase       )  ->None:






					"""simple docstring"""






					if mode == "encrypt":
										if key_a == 1:
															sys.exit(
															    '''The affine cipher becomes weak when key '''
															    '''A is set to 1. Choose different key'''       )
										if key_b == 0:
															sys.exit(
															    '''The affine cipher becomes weak when key '''
															    '''B is set to 0. Choose different key'''       )
					if key_a < 0 or key_b < 0 or key_b > len(UpperCAmelCase       ) - 1:
										sys.exit(
										    '''Key A must be greater than 0 and key B must '''
										    F'''be between 0 and {len(UpperCAmelCase       ) - 1}.'''       )
					if cryptomath.gcd(UpperCAmelCase,	len(UpperCAmelCase       )       ) != 1:
										sys.exit(
										    F'''Key A {key_a} and the symbol set size {len(UpperCAmelCase       )} '''
										    '''are not relatively prime. Choose a different key.'''       )







def  lowerCAmelCase  (	UpperCAmelCase,	UpperCAmelCase       )  ->str:






					"""simple docstring"""






					__magic_name__   , __magic_name__					:							str		   =							divmod(UpperCAmelCase,	len(UpperCAmelCase       )       )
					check_keys(UpperCAmelCase,	UpperCAmelCase,	'''encrypt'''       )
					__magic_name__					:							Dict		   =							''''''
					for symbol in message:
										if symbol in SYMBOLS:
															__magic_name__					:							Union[str, Any]		   =							SYMBOLS.find(UpperCAmelCase       )
															cipher_text += SYMBOLS[(sym_index * key_a + key_b) % len(UpperCAmelCase       )]
										else:
															cipher_text += symbol
					return cipher_text







def  lowerCAmelCase  (	UpperCAmelCase,	UpperCAmelCase       )  ->str:






					"""simple docstring"""






					__magic_name__   , __magic_name__					:							List[str]		   =							divmod(UpperCAmelCase,	len(UpperCAmelCase       )       )
					check_keys(UpperCAmelCase,	UpperCAmelCase,	'''decrypt'''       )
					__magic_name__					:							Union[str, Any]		   =							''''''
					__magic_name__					:							int		   =							cryptomath.find_mod_inverse(UpperCAmelCase,	len(UpperCAmelCase       )       )
					for symbol in message:
										if symbol in SYMBOLS:
															__magic_name__					:							Optional[Any]		   =							SYMBOLS.find(UpperCAmelCase       )
															plain_text += SYMBOLS[
															    (sym_index - key_b) * mod_inverse_of_key_a % len(UpperCAmelCase       )
															]
										else:
															plain_text += symbol
					return plain_text







def  lowerCAmelCase  (	)  ->int:






					"""simple docstring"""






					while True:
										__magic_name__					:							List[Any]		   =							random.randint(2,	len(UpperCAmelCase       )       )
										__magic_name__					:							int		   =							random.randint(2,	len(UpperCAmelCase       )       )
										if cryptomath.gcd(UpperCAmelCase,	len(UpperCAmelCase       )       ) == 1 and key_b % len(UpperCAmelCase       ) != 0:
															return key_b * len(UpperCAmelCase       ) + key_b







def  lowerCAmelCase  (	)  ->None:






					"""simple docstring"""






					__magic_name__					:							List[Any]		   =							input('''Enter message: '''       ).strip()
					__magic_name__					:							Optional[int]		   =							int(input('''Enter key [2000 - 9000]: '''       ).strip()       )
					__magic_name__					:							List[Any]		   =							input('''Encrypt/Decrypt [E/D]: '''       ).strip().lower()

					if mode.startswith('''e'''       ):
										__magic_name__					:							Any		   =							'''encrypt'''
										__magic_name__					:							Any		   =							encrypt_message(UpperCAmelCase,	UpperCAmelCase       )
					elif mode.startswith('''d'''       ):
										__magic_name__					:							Optional[Any]		   =							'''decrypt'''
										__magic_name__					:							Union[str, Any]		   =							decrypt_message(UpperCAmelCase,	UpperCAmelCase       )
					print(F'''\n{mode.title()}ed text: \n{translated}'''       )


if __name__ == "__main__":
				import doctest

				doctest.testmod()
				# main()



