
'''simple docstring'''






from __future__ import annotations

import unittest

from transformers import is_tf_available
from transformers.testing_utils import require_tf, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
					import numpy
					import tensorflow as tf

					from transformers import (
					    TF_DPR_CONTEXT_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST,
					    TF_DPR_QUESTION_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST,
					    TF_DPR_READER_PRETRAINED_MODEL_ARCHIVE_LIST,
					    BertConfig,
					    DPRConfig,
					    TFDPRContextEncoder,
					    TFDPRQuestionEncoder,
					    TFDPRReader,
					)




class     __snake_case		:
					def __init__(     self,    A,    A=13,    A=7,    A=True,    A=True,    A=True,    A=True,    A=99,    A=32,    A=2,    A=4,    A=37,    A="gelu",    A=0.1,    A=0.1,    A=512,    A=16,    A=2,    A=0.02,    A=3,    A=4,    A=None,    A=0,    ):

									"""simple docstring"""


									lowerCamelCase					:			Optional[Any]									= parent
									lowerCamelCase					:			Any									= batch_size
									lowerCamelCase					:			Optional[Any]									= seq_length
									lowerCamelCase					:			List[str]									= is_training
									lowerCamelCase					:			Optional[int]									= use_input_mask
									lowerCamelCase					:			int									= use_token_type_ids
									lowerCamelCase					:			List[Any]									= use_labels
									lowerCamelCase					:			List[str]									= vocab_size
									lowerCamelCase					:			List[Any]									= hidden_size
									lowerCamelCase					:			Dict									= num_hidden_layers
									lowerCamelCase					:			List[str]									= num_attention_heads
									lowerCamelCase					:			Union[str, Any]									= intermediate_size
									lowerCamelCase					:			int									= hidden_act
									lowerCamelCase					:			str									= hidden_dropout_prob
									lowerCamelCase					:			Union[str, Any]									= attention_probs_dropout_prob
									lowerCamelCase					:			str									= max_position_embeddings
									lowerCamelCase					:			int									= type_vocab_size
									lowerCamelCase					:			List[Any]									= type_sequence_label_size
									lowerCamelCase					:			int									= initializer_range
									lowerCamelCase					:			Any									= num_labels
									lowerCamelCase					:			Tuple									= num_choices
									lowerCamelCase					:			Dict									= scope
									lowerCamelCase					:			List[Any]									= projection_dim
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									lowerCamelCase					:			Tuple									= ids_tensor([self.batch_size, self.seq_length],    self.vocab_size      )

									lowerCamelCase					:			Tuple									= None
									if self.use_input_mask:
													# follow test_modeling_tf_ctrl.py
													lowerCamelCase					:			int									= random_attention_mask([self.batch_size, self.seq_length]      )

									lowerCamelCase					:			Union[str, Any]									= None
									if self.use_token_type_ids:
													lowerCamelCase					:			Union[str, Any]									= ids_tensor([self.batch_size, self.seq_length],    self.type_vocab_size      )

									lowerCamelCase					:			Dict									= None
									lowerCamelCase					:			Any									= None
									lowerCamelCase					:			Optional[Any]									= None
									if self.use_labels:
													lowerCamelCase					:			Any									= ids_tensor([self.batch_size],    self.type_sequence_label_size      )
													lowerCamelCase					:			List[str]									= ids_tensor([self.batch_size, self.seq_length],    self.num_labels      )
													lowerCamelCase					:			Dict									= ids_tensor([self.batch_size],    self.num_choices      )

									lowerCamelCase					:			int									= BertConfig(
									    vocab_size=self.vocab_size,    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,    max_position_embeddings=self.max_position_embeddings,    type_vocab_size=self.type_vocab_size,    is_decoder=A,    initializer_range=self.initializer_range,    )
									lowerCamelCase					:			Dict									= DPRConfig(projection_dim=self.projection_dim,    **config.to_dict()      )

									return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels
					def     UpperCAmelCase_							(     self,    A,    A,    A,    A,    A,    A,    A      ):

									"""simple docstring"""


									lowerCamelCase					:			Dict									= TFDPRContextEncoder(config=A      )
									lowerCamelCase					:			Optional[Any]									= model(A,    attention_mask=A,    token_type_ids=A      )
									lowerCamelCase					:			int									= model(A,    token_type_ids=A      )
									lowerCamelCase					:			int									= model(A      )
									self.parent.assertEqual(result.pooler_output.shape,    (self.batch_size, self.projection_dim or self.hidden_size)      )
					def     UpperCAmelCase_							(     self,    A,    A,    A,    A,    A,    A,    A      ):

									"""simple docstring"""


									lowerCamelCase					:			Union[str, Any]									= TFDPRQuestionEncoder(config=A      )
									lowerCamelCase					:			Optional[int]									= model(A,    attention_mask=A,    token_type_ids=A      )
									lowerCamelCase					:			Union[str, Any]									= model(A,    token_type_ids=A      )
									lowerCamelCase					:			List[Any]									= model(A      )
									self.parent.assertEqual(result.pooler_output.shape,    (self.batch_size, self.projection_dim or self.hidden_size)      )
					def     UpperCAmelCase_							(     self,    A,    A,    A,    A,    A,    A,    A      ):

									"""simple docstring"""


									lowerCamelCase					:			Dict									= TFDPRReader(config=A      )
									lowerCamelCase					:			Dict									= model(A,    attention_mask=A      )

									self.parent.assertEqual(result.start_logits.shape,    (self.batch_size, self.seq_length)      )
									self.parent.assertEqual(result.end_logits.shape,    (self.batch_size, self.seq_length)      )
									self.parent.assertEqual(result.relevance_logits.shape,    (self.batch_size,)      )




					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									lowerCamelCase					:			int									= self.prepare_config_and_inputs()
									(
									    (
									    lowerCamelCase
									)			, (
									    lowerCamelCase
									)			, (
									    lowerCamelCase
									)			, (
									    lowerCamelCase
									)			, (
									    lowerCamelCase
									)			, (
									    lowerCamelCase
									)			, (
									    lowerCamelCase
									)			, 
									)					:			Dict									= config_and_inputs
									lowerCamelCase					:			Optional[int]									= {'input_ids': input_ids}
									return config, inputs_dict





@require_tf
class     __snake_case		(   a__    ,   a__    ,   unittest.TestCase):
					_lowerCAmelCase			     =	(
					    (
					        TFDPRContextEncoder,
					        TFDPRQuestionEncoder,
					        TFDPRReader,
					    )
					    if is_tf_available()
					    else ()
					)
					_lowerCAmelCase			     =	{'''feature-extraction''': TFDPRQuestionEncoder} if is_tf_available() else {}

					_lowerCAmelCase			     =	False
					_lowerCAmelCase			     =	False
					_lowerCAmelCase			     =	False
					_lowerCAmelCase			     =	False
					_lowerCAmelCase			     =	False
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									lowerCamelCase					:			Dict									= TFDPRModelTester(self      )
									lowerCamelCase					:			Union[str, Any]									= ConfigTester(self,    config_class=A,    hidden_size=37      )
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									self.config_tester.run_common_tests()
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									lowerCamelCase					:			List[Any]									= self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_dpr_context_encoder(*A      )
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									lowerCamelCase					:			int									= self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_dpr_question_encoder(*A      )
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									lowerCamelCase					:			Tuple									= self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_dpr_reader(*A      )




					@slow
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									for model_name in TF_DPR_CONTEXT_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
													lowerCamelCase					:			Any									= TFDPRContextEncoder.from_pretrained(A      )
													self.assertIsNotNone(A      )

									for model_name in TF_DPR_CONTEXT_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
													lowerCamelCase					:			Union[str, Any]									= TFDPRContextEncoder.from_pretrained(A      )
													self.assertIsNotNone(A      )

									for model_name in TF_DPR_QUESTION_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
													lowerCamelCase					:			str									= TFDPRQuestionEncoder.from_pretrained(A      )
													self.assertIsNotNone(A      )

									for model_name in TF_DPR_READER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
													lowerCamelCase					:			Union[str, Any]									= TFDPRReader.from_pretrained(A      )
													self.assertIsNotNone(A      )





@require_tf
class     __snake_case		(   unittest.TestCase):
					@slow
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									lowerCamelCase					:			Tuple									= TFDPRQuestionEncoder.from_pretrained('facebook/dpr-question_encoder-single-nq-base'      )

									lowerCamelCase					:			Optional[int]									= tf.constant(
									    [[101, 7592, 1010, 2003, 2026, 3899, 1_0140, 1029, 102]]      )  # [CLS] hello, is my dog cute? [SEP]
									lowerCamelCase					:			Optional[Any]									= model(A      )[0]  # embedding shape = (1, 768)
									# compare the actual values for a slice.
									lowerCamelCase					:			List[Any]									= tf.constant(
									    [
									        [
									            0.0323_6253,
									            0.1275_3335,
									            0.1681_8509,
									            0.0027_9786,
									            0.389_6933,
									            0.2426_4945,
									            0.217_8971,
									            -0.0233_5227,
									            -0.0848_1959,
									            -0.1432_4117,
									        ]
									    ]      )
									self.assertTrue(numpy.allclose(output[:, :10].numpy(),    expected_slice.numpy(),    atol=1e-4      )      )


'''simple docstring'''






from __future__ import annotations

import string
from itertools import cycle, product
from pathlib import Path

A			      =      (
    string.ascii_letters + string.digits + string.punctuation + string.whitespace
)
A			      =      [ord(letter) for letter in string.ascii_lowercase]
A			      =      {ord(char) for char in VALID_CHARS}

A			      =      ["the", "be", "to", "of", "and", "in", "that", "have"]





def    UpperCAmelCase							(  UpperCAmelCase__							:							list[int]       ,							UpperCAmelCase__							:							tuple[int, ...]):
				lowerCamelCase					:			str									= ""
				lowerCamelCase					:			int
				lowerCamelCase					:			int
				lowerCamelCase					:			int

				for keychar, cipherchar in zip(cycle(UpperCAmelCase__)       ,							UpperCAmelCase__):
								lowerCamelCase					:			Optional[Any]									= cipherchar ^ keychar
								if decodedchar not in VALID_INTS:
												return None
								decoded += chr(UpperCAmelCase__)

				return decoded





def    UpperCAmelCase							(  UpperCAmelCase__							:							list[int]):
				lowerCamelCase					:			list[str]									= []
				for key in product(UpperCAmelCase__       ,							repeat=3):
								lowerCamelCase					:			Dict									= try_key(UpperCAmelCase__       ,							UpperCAmelCase__)
								if encoded is not None:
												possibles.append(UpperCAmelCase__)
				return possibles





def    UpperCAmelCase							(  UpperCAmelCase__							:							list[str]       ,							UpperCAmelCase__							:							str):
				return [possible for possible in possibles if common_word in possible.lower()]





def    UpperCAmelCase							(  UpperCAmelCase__							:							str = "p059_cipher.txt"):
				lowerCamelCase					:			list[int]
				lowerCamelCase					:			list[str]
				lowerCamelCase					:			str
				lowerCamelCase					:			str
				lowerCamelCase					:			str									= Path(UpperCAmelCase__).parent.joinpath(UpperCAmelCase__).read_text(encoding='utf-8')

				lowerCamelCase					:			Tuple									= [int(UpperCAmelCase__) for number in data.strip().split(',')]

				lowerCamelCase					:			str									= filter_valid_chars(UpperCAmelCase__)
				for common_word in COMMON_WORDS:
								lowerCamelCase					:			List[str]									= filter_common_word(UpperCAmelCase__       ,							UpperCAmelCase__)
								if len(UpperCAmelCase__) == 1:
												break

				lowerCamelCase					:			Dict									= possibles[0]
				return sum(ord(UpperCAmelCase__) for char in decoded_text)


if __name__ == "__main__":
					print(f"""{solution() = }""")
