from __future__ import annotations

import math
from collections import Counter
from string import ascii_lowercase






def 					snake_case    (			snake_case__     :str)		->  None:
       _A  ,    _A	  =    analyze_text(UpperCamelCase__)
       _A	  =    list(""" """ + ascii_lowercase)
       # what is our total sum of probabilities.
       _A	  =    sum(single_char_strings.values())

       # one length string
       _A	  =    0
       # for each alpha we go in our dict and if it is in it we calculate entropy
       for ch in my_alphas:
              if ch in single_char_strings:
                     _A	  =    single_char_strings[ch]
                     _A	  =    my_str / all_sum
                     my_fir_sum += prob * math.loga(UpperCamelCase__)  # entropy formula.

    # print entropy
       print(F'''{round(-1 * my_fir_sum):.1f}''')

       # two len string
       _A	  =    sum(two_char_strings.values())
       _A	  =    0
       # for each alpha (two in size) calculate entropy.
       for cha in my_alphas:
              for cha in my_alphas:
                     _A	  =    cha + cha
                     if sequence in two_char_strings:
                            _A	  =    two_char_strings[sequence]
                            _A	  =    int(UpperCamelCase__) / all_sum
                            my_sec_sum += prob * math.loga(UpperCamelCase__)

    # print second entropy
       print(F'''{round(-1 * my_sec_sum):.1f}''')

       # print the difference between them
       print(F'''{round((-1 * my_sec_sum) - (-1 * my_fir_sum)):.1f}''')






def 					snake_case    (			snake_case__     :str)		->  tuple[dict, dict]:
       _A	  =    Counter()  # type: ignore
       _A	  =    Counter()  # type: ignore
       single_char_strings[text[-1]] += 1

       # first case when we have space at start.
       two_char_strings[" " + text[0]] += 1
       for i in range(0  ,      len(UpperCamelCase__) - 1):
              single_char_strings[text[i]] += 1
              two_char_strings[text[i : i + 2]] += 1
       return single_char_strings, two_char_strings






def 					snake_case    (			)		->  Dict:
       import doctest

       doctest.testmod()
       # text = (
       #     "Had repulsive dashwoods suspicion sincerity but advantage now him. Remark "
       #     "easily garret nor nay. Civil those mrs enjoy shy fat merry. You greatest "
       #     "jointure saw horrible. He private he on be imagine suppose. Fertile "
       #     "beloved evident through no service elderly is. Blind there if every no so "
       #     "at. Own neglected you preferred way sincerity delivered his attempted. To "
       #     "of message cottage windows do besides against uncivil.  Delightful "
       #     "unreserved impossible few estimating men favourable see entreaties. She "
       #     "propriety immediate was improving. He or entrance humoured likewise "
       #     "moderate. Much nor game son say feel. Fat make met can must form into "
       #     "gate. Me we offending prevailed discovery. "
       # )

       # calculate_prob(text)


if __name__ == "__main__":
    main()










import unittest

from transformers import EsmConfig, is_torch_available
from transformers.testing_utils import TestCasePlus, require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
					import torch

					from transformers.models.esm.modeling_esmfold import EsmForProteinFolding







class        __lowerCAmelCase					:

			"""simple docstring"""







			def __init__( self     ,		lowerCamelCase__     ,		lowerCamelCase__=13     ,		lowerCamelCase__=7     ,		lowerCamelCase__=False     ,		lowerCamelCase__=True     ,		lowerCamelCase__=False     ,		lowerCamelCase__=False     ,		lowerCamelCase__=19     ,		lowerCamelCase__=32     ,		lowerCamelCase__=5     ,		lowerCamelCase__=4     ,		lowerCamelCase__=37     ,		lowerCamelCase__="gelu"     ,		lowerCamelCase__=0.1     ,		lowerCamelCase__=0.1     ,		lowerCamelCase__=512     ,		lowerCamelCase__=16     ,		lowerCamelCase__=2     ,		lowerCamelCase__=0.02     ,		lowerCamelCase__=3     ,		lowerCamelCase__=4     ,		lowerCamelCase__=None     ,		)       -> Any:



							'''simple docstring'''
							__lowerCamelCase									=       parent
							__lowerCamelCase									=       batch_size
							__lowerCamelCase									=       seq_length
							__lowerCamelCase									=       is_training
							__lowerCamelCase									=       use_input_mask
							__lowerCamelCase									=       use_token_type_ids
							__lowerCamelCase									=       use_labels
							__lowerCamelCase									=       vocab_size
							__lowerCamelCase									=       hidden_size
							__lowerCamelCase									=       num_hidden_layers
							__lowerCamelCase									=       num_attention_heads
							__lowerCamelCase									=       intermediate_size
							__lowerCamelCase									=       hidden_act
							__lowerCamelCase									=       hidden_dropout_prob
							__lowerCamelCase									=       attention_probs_dropout_prob
							__lowerCamelCase									=       max_position_embeddings
							__lowerCamelCase									=       type_vocab_size
							__lowerCamelCase									=       type_sequence_label_size
							__lowerCamelCase									=       initializer_range
							__lowerCamelCase									=       num_labels
							__lowerCamelCase									=       num_choices
							__lowerCamelCase									=       scope


			def  lowercase_       ( self				)       -> str:



							'''simple docstring'''
							__lowerCamelCase									=       ids_tensor([self.batch_size, self.seq_length]     ,		self.vocab_size				)

							__lowerCamelCase									=       None
							if self.use_input_mask:
											__lowerCamelCase									=       random_attention_mask([self.batch_size, self.seq_length]				)

							__lowerCamelCase									=       None
							__lowerCamelCase									=       None
							__lowerCamelCase									=       None
							if self.use_labels:
											__lowerCamelCase									=       ids_tensor([self.batch_size]     ,		self.type_sequence_label_size				)
											__lowerCamelCase									=       ids_tensor([self.batch_size, self.seq_length]     ,		self.num_labels				)
											__lowerCamelCase									=       ids_tensor([self.batch_size]     ,		self.num_choices				)

							__lowerCamelCase									=       self.get_config()

							return config, input_ids, input_mask, sequence_labels, token_labels, choice_labels


			def  lowercase_       ( self				)       -> Tuple:



							'''simple docstring'''
							__lowerCamelCase									=       EsmConfig(
							    vocab_size=33     ,		hidden_size=self.hidden_size     ,		pad_token_id=1     ,		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     ,		initializer_range=self.initializer_range     ,		is_folding_model=lowerCamelCase__     ,		esmfold_config={'trunk': {'num_blocks': 2}, 'fp16_esm': False}     ,		)
							return config


			def  lowercase_       ( self     ,		lowerCamelCase__     ,		lowerCamelCase__     ,		lowerCamelCase__     ,		lowerCamelCase__     ,		lowerCamelCase__     ,		lowerCamelCase__				)       -> Optional[Any]:



							'''simple docstring'''
							__lowerCamelCase									=       EsmForProteinFolding(config=lowerCamelCase__				).float()
							model.to(lowerCamelCase__				)
							model.eval()
							__lowerCamelCase									=       model(lowerCamelCase__     ,		attention_mask=lowerCamelCase__				)
							__lowerCamelCase									=       model(lowerCamelCase__				)
							__lowerCamelCase									=       model(lowerCamelCase__				)

							self.parent.assertEqual(result.positions.shape     ,		(8, self.batch_size, self.seq_length, 14, 3)				)
							self.parent.assertEqual(result.angles.shape     ,		(8, self.batch_size, self.seq_length, 7, 2)				)






			def  lowercase_       ( self				)       -> int:



							'''simple docstring'''
							__lowerCamelCase									=       self.prepare_config_and_inputs()
							(
							    (
							    __lowerCamelCase
							)			,		(
							    __lowerCamelCase
							)			,		(
							    __lowerCamelCase
							)			,		(
							    __lowerCamelCase
							)			,		(
							    __lowerCamelCase
							)			,		(
							    __lowerCamelCase
							)			,		
							)									=       config_and_inputs
							__lowerCamelCase									=       {'input_ids': input_ids, 'attention_mask': input_mask}
							return config, inputs_dict







@require_torch
class        __lowerCAmelCase					(			__magic_name__     ,							__magic_name__     ,							unittest.TestCase					):

			"""simple docstring"""







			snake_case_  						=			False

			snake_case_  						=			(EsmForProteinFolding,) if is_torch_available() else ()
			snake_case_  						=			()
			snake_case_  						=			{} if is_torch_available() else {}
			snake_case_  						=			False


			def  lowercase_       ( self				)       -> Tuple:



							'''simple docstring'''
							__lowerCamelCase									=       EsmFoldModelTester(self				)
							__lowerCamelCase									=       ConfigTester(self     ,		config_class=lowerCamelCase__     ,		hidden_size=37				)


			def  lowercase_       ( self				)       -> Any:



							'''simple docstring'''
							self.config_tester.run_common_tests()


			def  lowercase_       ( self				)       -> str:



							'''simple docstring'''
							__lowerCamelCase									=       self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_model(*lowerCamelCase__				)


			@unittest.skip('Does not support attention outputs'				)
			def  lowercase_       ( self				)       -> int:



							'''simple docstring'''
							pass


			@unittest.skip
			def  lowercase_       ( self				)       -> Tuple:



							'''simple docstring'''
							pass


			@unittest.skip('Esm does not support embedding resizing'				)
			def  lowercase_       ( self				)       -> Any:



							'''simple docstring'''
							pass


			@unittest.skip('Esm does not support embedding resizing'				)
			def  lowercase_       ( self				)       -> int:



							'''simple docstring'''
							pass


			@unittest.skip('ESMFold does not support passing input embeds!'				)
			def  lowercase_       ( self				)       -> Any:



							'''simple docstring'''
							pass


			@unittest.skip('ESMFold does not support head pruning.'				)
			def  lowercase_       ( self				)       -> List[Any]:



							'''simple docstring'''
							pass


			@unittest.skip('ESMFold does not support head pruning.'				)
			def  lowercase_       ( self				)       -> Dict:



							'''simple docstring'''
							pass


			@unittest.skip('ESMFold does not support head pruning.'				)
			def  lowercase_       ( self				)       -> List[Any]:



							'''simple docstring'''
							pass


			@unittest.skip('ESMFold does not support head pruning.'				)
			def  lowercase_       ( self				)       -> int:



							'''simple docstring'''
							pass


			@unittest.skip('ESMFold does not support head pruning.'				)
			def  lowercase_       ( self				)       -> Dict:



							'''simple docstring'''
							pass


			@unittest.skip('ESMFold does not output hidden states in the normal way.'				)
			def  lowercase_       ( self				)       -> List[str]:



							'''simple docstring'''
							pass


			@unittest.skip('ESMfold does not output hidden states in the normal way.'				)
			def  lowercase_       ( self				)       -> Optional[int]:



							'''simple docstring'''
							pass


			@unittest.skip('ESMFold only has one output format.'				)
			def  lowercase_       ( self				)       -> Tuple:



							'''simple docstring'''
							pass


			@unittest.skip('This test doesn\'t work for ESMFold and doesn\'t test core functionality'				)
			def  lowercase_       ( self				)       -> int:



							'''simple docstring'''
							pass


			@unittest.skip('ESMFold does not support input chunking.'				)
			def  lowercase_       ( self				)       -> Dict:



							'''simple docstring'''
							pass


			@unittest.skip('ESMFold doesn\'t respect you and it certainly doesn\'t respect your initialization arguments.'				)
			def  lowercase_       ( self				)       -> Any:



							'''simple docstring'''
							pass


			@unittest.skip('ESMFold doesn\'t support torchscript compilation.'				)
			def  lowercase_       ( self				)       -> Union[str, Any]:



							'''simple docstring'''
							pass


			@unittest.skip('ESMFold doesn\'t support torchscript compilation.'				)
			def  lowercase_       ( self				)       -> str:



							'''simple docstring'''
							pass


			@unittest.skip('ESMFold doesn\'t support torchscript compilation.'				)
			def  lowercase_       ( self				)       -> Dict:



							'''simple docstring'''
							pass


			@unittest.skip('ESMFold doesn\'t support data parallel.'				)
			def  lowercase_       ( self				)       -> str:



							'''simple docstring'''
							pass






			@unittest.skip('Will be fixed soon by reducing the size of the model used for common tests.'				)
			def  lowercase_       ( self				)       -> List[Any]:



							'''simple docstring'''
							pass







@require_torch
class        __lowerCAmelCase					(			__magic_name__					):

			"""simple docstring"""







			@slow
			def  lowercase_       ( self				)       -> str:



							'''simple docstring'''
							__lowerCamelCase									=       EsmForProteinFolding.from_pretrained('facebook/esmfold_v1'				).float()
							model.eval()
							__lowerCamelCase									=       torch.tensor([[0, 6, 4, 13, 5, 4, 16, 12, 11, 7, 2]]				)
							__lowerCamelCase									=       model(lowerCamelCase__				)['positions']
							__lowerCamelCase									=       torch.tensor([2.58_28, 0.79_93, -10.93_34]     ,		dtype=torch.floataa				)
							self.assertTrue(torch.allclose(position_outputs[0, 0, 0, 0]     ,		lowerCamelCase__     ,		atol=1e-4				)				)


