





import copy
import inspect
import unittest

import numpy as np
from huggingface_hub import hf_hub_download

from transformers import VideoMAEConfig
from transformers.models.auto import get_values
from transformers.testing_utils import require_torch, require_vision, slow, torch_device
from transformers.utils import cached_property, is_torch_available, is_vision_available

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


if is_torch_available():
		import torch
		from torch import nn

		from transformers import (
		    MODEL_FOR_VIDEO_CLASSIFICATION_MAPPING,
		    VideoMAEForPreTraining,
		    VideoMAEForVideoClassification,
		    VideoMAEModel,
		)
		from transformers.models.videomae.modeling_videomae import VIDEOMAE_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
		from transformers import VideoMAEImageProcessor


class 						lowerCamelCase       :







							"""simple docstring"""




							def __init__( self     :					Dict,			_UpperCAmelCase     :					Any,			_UpperCAmelCase     :					Tuple=1_3,			_UpperCAmelCase     :					Tuple=1_0,			_UpperCAmelCase     :					Optional[Any]=3,			_UpperCAmelCase     :					int=2,			_UpperCAmelCase     :					List[Any]=2,			_UpperCAmelCase     :					str=2,			_UpperCAmelCase     :					Union[str, Any]=True,			_UpperCAmelCase     :					int=True,			_UpperCAmelCase     :					Any=3_2,			_UpperCAmelCase     :					str=5,			_UpperCAmelCase     :					int=4,			_UpperCAmelCase     :					Optional[int]=3_7,			_UpperCAmelCase     :					int="gelu",			_UpperCAmelCase     :					List[Any]=0.1,			_UpperCAmelCase     :					List[Any]=0.1,			_UpperCAmelCase     :					List[Any]=1_0,			_UpperCAmelCase     :					Tuple=0.02,			_UpperCAmelCase     :					Tuple=0.9,			_UpperCAmelCase     :					List[str]=None,			)				->			Union[str, Any]:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__       :      Tuple     =						parent
														SCREAMING_SNAKE_CASE__       :      Any     =						batch_size
														SCREAMING_SNAKE_CASE__       :      str     =						image_size
														SCREAMING_SNAKE_CASE__       :      List[Any]     =						num_channels
														SCREAMING_SNAKE_CASE__       :      List[str]     =						patch_size
														SCREAMING_SNAKE_CASE__       :      Optional[int]     =						tubelet_size
														SCREAMING_SNAKE_CASE__       :      List[str]     =						num_frames
														SCREAMING_SNAKE_CASE__       :      int     =						is_training
														SCREAMING_SNAKE_CASE__       :      Union[str, Any]     =						use_labels
														SCREAMING_SNAKE_CASE__       :      int     =						hidden_size
														SCREAMING_SNAKE_CASE__       :      int     =						num_hidden_layers
														SCREAMING_SNAKE_CASE__       :      str     =						num_attention_heads
														SCREAMING_SNAKE_CASE__       :      List[Any]     =						intermediate_size
														SCREAMING_SNAKE_CASE__       :      List[str]     =						hidden_act
														SCREAMING_SNAKE_CASE__       :      List[str]     =						hidden_dropout_prob
														SCREAMING_SNAKE_CASE__       :      Union[str, Any]     =						attention_probs_dropout_prob
														SCREAMING_SNAKE_CASE__       :      str     =						type_sequence_label_size
														SCREAMING_SNAKE_CASE__       :      List[Any]     =						initializer_range
														SCREAMING_SNAKE_CASE__       :      Optional[int]     =						mask_ratio
														SCREAMING_SNAKE_CASE__       :      Optional[int]     =						scope

														# in VideoMAE, the number of tokens equals num_frames/tubelet_size * num_patches per frame
														SCREAMING_SNAKE_CASE__       :      Tuple     =						(image_size // patch_size) ** 2
														SCREAMING_SNAKE_CASE__       :      str     =						(num_frames // tubelet_size) * self.num_patches_per_frame

														# use this variable to define bool_masked_pos
														SCREAMING_SNAKE_CASE__       :      Optional[Any]     =						int(mask_ratio * self.seq_length						)






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





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__       :      List[str]     =						floats_tensor(
														    [self.batch_size, self.num_frames, self.num_channels, self.image_size, self.image_size]						)

														SCREAMING_SNAKE_CASE__       :      List[str]     =						None
														if self.use_labels:
																					SCREAMING_SNAKE_CASE__       :      List[Any]     =						ids_tensor([self.batch_size],			self.type_sequence_label_size						)

														SCREAMING_SNAKE_CASE__       :      Optional[Any]     =						self.get_config()

														return config, pixel_values, labels






							def  A_     ( self     :					List[str]						)				->			List[str]:





														"""simple docstring"""
														return VideoMAEConfig(
														    image_size=self.image_size,			patch_size=self.patch_size,			num_channels=self.num_channels,			num_frames=self.num_frames,			tubelet_size=self.tubelet_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,			is_decoder=_UpperCAmelCase,			initializer_range=self.initializer_range,			)






							def  A_     ( self     :					Union[str, Any],			_UpperCAmelCase     :					List[Any],			_UpperCAmelCase     :					Union[str, Any],			_UpperCAmelCase     :					Dict						)				->			Any:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__       :      Union[str, Any]     =						VideoMAEModel(config=_UpperCAmelCase						)
														model.to(_UpperCAmelCase						)
														model.eval()
														SCREAMING_SNAKE_CASE__       :      str     =						model(_UpperCAmelCase						)
														self.parent.assertEqual(result.last_hidden_state.shape,			(self.batch_size, self.seq_length, self.hidden_size)						)






							def  A_     ( self     :					int,			_UpperCAmelCase     :					Tuple,			_UpperCAmelCase     :					List[str],			_UpperCAmelCase     :					Dict						)				->			Tuple:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__       :      Union[str, Any]     =						VideoMAEForPreTraining(_UpperCAmelCase						)
														model.to(_UpperCAmelCase						)
														model.eval()
														# important: each video needs to have the same number of masked patches
														# hence we define a single mask, which we then repeat for each example in the batch
														SCREAMING_SNAKE_CASE__       :      Optional[Any]     =						torch.ones((self.num_masks,)						)
														SCREAMING_SNAKE_CASE__       :      Optional[Any]     =						torch.cat([mask, torch.zeros(self.seq_length - mask.size(0						)						)]						)
														SCREAMING_SNAKE_CASE__       :      List[Any]     =						mask.expand(self.batch_size,			-1						).bool()

														SCREAMING_SNAKE_CASE__       :      Any     =						model(_UpperCAmelCase,			_UpperCAmelCase						)
														# model only returns predictions for masked patches
														SCREAMING_SNAKE_CASE__       :      Optional[int]     =						mask.sum().item()
														SCREAMING_SNAKE_CASE__       :      Tuple     =						3 * self.tubelet_size * self.patch_size**2
														self.parent.assertEqual(result.logits.shape,			(self.batch_size, num_masked_patches, decoder_num_labels)						)






							def  A_     ( self     :					Union[str, Any]						)				->			Dict:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__       :      str     =						self.prepare_config_and_inputs()
														SCREAMING_SNAKE_CASE__   ,SCREAMING_SNAKE_CASE__   ,SCREAMING_SNAKE_CASE__       :      Union[str, Any]     =						config_and_inputs
														SCREAMING_SNAKE_CASE__       :      int     =						{"pixel_values": pixel_values}
														return config, inputs_dict


@require_torch
class 						lowerCamelCase       (__lowerCamelCase							,     __lowerCamelCase							,     unittest.TestCase      ):







							"""simple docstring"""




							UpperCAmelCase_      						=   (
							    (VideoMAEModel, VideoMAEForPreTraining, VideoMAEForVideoClassification) if is_torch_available() else ()
							)
							UpperCAmelCase_      						=   (
							    {"feature-extraction": VideoMAEModel, "video-classification": VideoMAEForVideoClassification}
							    if is_torch_available()
							    else {}
							)

							UpperCAmelCase_      						=   False
							UpperCAmelCase_      						=   False
							UpperCAmelCase_      						=   False
							UpperCAmelCase_      						=   False






							def  A_     ( self     :					Dict						)				->			List[Any]:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__       :      Optional[int]     =						VideoMAEModelTester(self						)
														SCREAMING_SNAKE_CASE__       :      Optional[int]     =						ConfigTester(self,			config_class=_UpperCAmelCase,			has_text_modality=_UpperCAmelCase,			hidden_size=3_7						)






							def  A_     ( self     :					Tuple,			_UpperCAmelCase     :					int,			_UpperCAmelCase     :					Dict,			_UpperCAmelCase     :					List[str]=False						)				->			List[str]:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__       :      Dict     =						copy.deepcopy(_UpperCAmelCase						)

														if model_class == VideoMAEForPreTraining:
																					# important: each video needs to have the same number of masked patches
																					# hence we define a single mask, which we then repeat for each example in the batch
																					SCREAMING_SNAKE_CASE__       :      Tuple     =						torch.ones((self.model_tester.num_masks,)						)
																					SCREAMING_SNAKE_CASE__       :      Union[str, Any]     =						torch.cat([mask, torch.zeros(self.model_tester.seq_length - mask.size(0						)						)]						)
																					SCREAMING_SNAKE_CASE__       :      List[Any]     =						mask.expand(self.model_tester.batch_size,			-1						).bool()
																					SCREAMING_SNAKE_CASE__       :      Optional[int]     =						bool_masked_pos.to(_UpperCAmelCase						)

														if return_labels:
																					if model_class in [
																					    *get_values(_UpperCAmelCase						),
																					]:
																												SCREAMING_SNAKE_CASE__       :      Any     =						torch.zeros(
																												    self.model_tester.batch_size,			dtype=torch.long,			device=_UpperCAmelCase						)

														return inputs_dict






							def  A_     ( self     :					List[str]						)				->			List[str]:





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






							@unittest.skip(reason="VideoMAE does not use inputs_embeds"						)
							def  A_     ( self     :					List[str]						)				->			str:





														"""simple docstring"""
														pass






							def  A_     ( self     :					List[str]						)				->			List[str]:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__   ,SCREAMING_SNAKE_CASE__       :      int     =						self.model_tester.prepare_config_and_inputs_for_common()

														for model_class in self.all_model_classes:
																					SCREAMING_SNAKE_CASE__       :      Optional[int]     =						model_class(_UpperCAmelCase						)
																					self.assertIsInstance(model.get_input_embeddings(),			(nn.Module)						)
																					SCREAMING_SNAKE_CASE__       :      Optional[Any]     =						model.get_output_embeddings()
																					self.assertTrue(x is None or isinstance(_UpperCAmelCase,			nn.Linear						)						)






							def  A_     ( self     :					int						)				->			Union[str, Any]:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__   ,SCREAMING_SNAKE_CASE__       :      Dict     =						self.model_tester.prepare_config_and_inputs_for_common()

														for model_class in self.all_model_classes:
																					SCREAMING_SNAKE_CASE__       :      str     =						model_class(_UpperCAmelCase						)
																					SCREAMING_SNAKE_CASE__       :      Any     =						inspect.signature(model.forward						)
																					# signature.parameters is an OrderedDict => so arg_names order is deterministic
																					SCREAMING_SNAKE_CASE__       :      Optional[int]     =						[*signature.parameters.keys()]

																					SCREAMING_SNAKE_CASE__       :      int     =						["pixel_values"]
																					self.assertListEqual(arg_names[:1],			_UpperCAmelCase						)






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





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__       :      str     =						self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_model(*_UpperCAmelCase						)






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





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__       :      Optional[Any]     =						self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_for_pretraining(*_UpperCAmelCase						)






							@slow
							def  A_     ( self     :					Tuple						)				->			Union[str, Any]:





														"""simple docstring"""
														for model_name in VIDEOMAE_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																					SCREAMING_SNAKE_CASE__       :      str     =						VideoMAEModel.from_pretrained(_UpperCAmelCase						)
																					self.assertIsNotNone(_UpperCAmelCase						)






							def  A_     ( self     :					Optional[Any]						)				->			str:





														"""simple docstring"""
														if not self.has_attentions:
																					pass

														else:
																					SCREAMING_SNAKE_CASE__   ,SCREAMING_SNAKE_CASE__       :      List[Any]     =						self.model_tester.prepare_config_and_inputs_for_common()
																					SCREAMING_SNAKE_CASE__       :      Optional[int]     =						True

																					for model_class in self.all_model_classes:
																												SCREAMING_SNAKE_CASE__       :      List[str]     =						self.model_tester.seq_length - self.model_tester.num_masks
																												SCREAMING_SNAKE_CASE__       :      int     =						(
																												    num_visible_patches if model_class == VideoMAEForPreTraining else self.model_tester.seq_length
																												)

																												SCREAMING_SNAKE_CASE__       :      List[str]     =						True
																												SCREAMING_SNAKE_CASE__       :      Optional[Any]     =						False
																												SCREAMING_SNAKE_CASE__       :      int     =						True
																												SCREAMING_SNAKE_CASE__       :      List[str]     =						model_class(_UpperCAmelCase						)
																												model.to(_UpperCAmelCase						)
																												model.eval()
																												with torch.no_grad():
																																			SCREAMING_SNAKE_CASE__       :      Tuple     =						model(**self._prepare_for_class(_UpperCAmelCase,			_UpperCAmelCase						)						)
																												SCREAMING_SNAKE_CASE__       :      Optional[int]     =						outputs.attentions
																												self.assertEqual(len(_UpperCAmelCase						),			self.model_tester.num_hidden_layers						)

																												# check that output_attentions also work using config
																												del inputs_dict["output_attentions"]
																												SCREAMING_SNAKE_CASE__       :      List[Any]     =						True
																												SCREAMING_SNAKE_CASE__       :      List[str]     =						model_class(_UpperCAmelCase						)
																												model.to(_UpperCAmelCase						)
																												model.eval()
																												with torch.no_grad():
																																			SCREAMING_SNAKE_CASE__       :      int     =						model(**self._prepare_for_class(_UpperCAmelCase,			_UpperCAmelCase						)						)
																												SCREAMING_SNAKE_CASE__       :      List[Any]     =						outputs.attentions
																												self.assertEqual(len(_UpperCAmelCase						),			self.model_tester.num_hidden_layers						)

																												self.assertListEqual(
																												    list(attentions[0].shape[-3:]						),			[self.model_tester.num_attention_heads, seq_len, seq_len],			)
																												SCREAMING_SNAKE_CASE__       :      Union[str, Any]     =						len(_UpperCAmelCase						)

																												# Check attention is always last and order is fine
																												SCREAMING_SNAKE_CASE__       :      Tuple     =						True
																												SCREAMING_SNAKE_CASE__       :      Tuple     =						True
																												SCREAMING_SNAKE_CASE__       :      Union[str, Any]     =						model_class(_UpperCAmelCase						)
																												model.to(_UpperCAmelCase						)
																												model.eval()
																												with torch.no_grad():
																																			SCREAMING_SNAKE_CASE__       :      Union[str, Any]     =						model(**self._prepare_for_class(_UpperCAmelCase,			_UpperCAmelCase						)						)

																												self.assertEqual(out_len + 1,			len(_UpperCAmelCase						)						)

																												SCREAMING_SNAKE_CASE__       :      Any     =						outputs.attentions

																												self.assertEqual(len(_UpperCAmelCase						),			self.model_tester.num_hidden_layers						)
																												self.assertListEqual(
																												    list(self_attentions[0].shape[-3:]						),			[self.model_tester.num_attention_heads, seq_len, seq_len],			)






							def  A_     ( self     :					Any						)				->			List[Any]:





														"""simple docstring"""
														def check_hidden_states_output(_UpperCAmelCase     :					Union[str, Any],			_UpperCAmelCase     :					List[Any],			_UpperCAmelCase     :					Any						):
																					SCREAMING_SNAKE_CASE__       :      List[str]     =						model_class(_UpperCAmelCase						)
																					model.to(_UpperCAmelCase						)
																					model.eval()

																					with torch.no_grad():
																												SCREAMING_SNAKE_CASE__       :      Optional[int]     =						model(**self._prepare_for_class(_UpperCAmelCase,			_UpperCAmelCase						)						)

																					SCREAMING_SNAKE_CASE__       :      Tuple     =						outputs.hidden_states
																					SCREAMING_SNAKE_CASE__       :      Optional[Any]     =						self.model_tester.num_hidden_layers + 1
																					self.assertEqual(len(_UpperCAmelCase						),			_UpperCAmelCase						)

																					SCREAMING_SNAKE_CASE__       :      str     =						self.model_tester.seq_length - self.model_tester.num_masks
																					SCREAMING_SNAKE_CASE__       :      Any     =						num_visible_patches if model_class == VideoMAEForPreTraining else self.model_tester.seq_length

																					self.assertListEqual(
																					    list(hidden_states[0].shape[-2:]						),			[seq_length, self.model_tester.hidden_size],			)

														SCREAMING_SNAKE_CASE__   ,SCREAMING_SNAKE_CASE__       :      Any     =						self.model_tester.prepare_config_and_inputs_for_common()

														for model_class in self.all_model_classes:
																					SCREAMING_SNAKE_CASE__       :      Optional[Any]     =						True
																					check_hidden_states_output(_UpperCAmelCase,			_UpperCAmelCase,			_UpperCAmelCase						)

																					# check that output_hidden_states also work using config
																					del inputs_dict["output_hidden_states"]
																					SCREAMING_SNAKE_CASE__       :      Tuple     =						True

																					check_hidden_states_output(_UpperCAmelCase,			_UpperCAmelCase,			_UpperCAmelCase						)






							@unittest.skip("Will be fixed soon by reducing the size of the model used for common tests."						)
							def  A_     ( self     :					Optional[int]						)				->			str:





														"""simple docstring"""
														pass




def _a (  )	->    int:

							'''simple docstring'''






							SCREAMING_SNAKE_CASE__       :      Optional[Any]     =						hf_hub_download(
							    repo_id="hf-internal-testing/spaghetti-video"			,				filename="eating_spaghetti.npy"			,				repo_type="dataset"       )
							SCREAMING_SNAKE_CASE__       :      str     =						np.load(SCREAMING_SNAKE_CASE__       )
							return list(SCREAMING_SNAKE_CASE__       )







@require_torch
@require_vision
class 						lowerCamelCase       (unittest.TestCase      ):







							"""simple docstring"""




							@cached_property
							def  A_     ( self     :					Dict						)				->			Optional[Any]:





														"""simple docstring"""
														# logits were tested with a different mean and std, so we use the same here
														return (
														    VideoMAEImageProcessor(image_mean=[0.5, 0.5, 0.5],			image_std=[0.5, 0.5, 0.5]						)
														    if is_vision_available()
														    else None
														)






							@slow
							def  A_     ( self     :					List[str]						)				->			Any:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__       :      Tuple     =						VideoMAEForVideoClassification.from_pretrained("MCG-NJU/videomae-base-finetuned-kinetics"						).to(
														    _UpperCAmelCase						)

														SCREAMING_SNAKE_CASE__       :      Optional[Any]     =						self.default_image_processor
														SCREAMING_SNAKE_CASE__       :      Dict     =						prepare_video()
														SCREAMING_SNAKE_CASE__       :      Dict     =						image_processor(_UpperCAmelCase,			return_tensors="pt"						).to(_UpperCAmelCase						)

														# forward pass
														with torch.no_grad():
																					SCREAMING_SNAKE_CASE__       :      int     =						model(**_UpperCAmelCase						)

														# verify the logits
														SCREAMING_SNAKE_CASE__       :      Tuple     =						torch.Size((1, 4_0_0)						)
														self.assertEqual(outputs.logits.shape,			_UpperCAmelCase						)

														SCREAMING_SNAKE_CASE__       :      str     =						torch.tensor([0.3669, -0.0688, -0.2421]						).to(_UpperCAmelCase						)

														self.assertTrue(torch.allclose(outputs.logits[0, :3],			_UpperCAmelCase,			atol=1E-4						)						)






							@slow
							def  A_     ( self     :					Optional[int]						)				->			Dict:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__       :      List[Any]     =						VideoMAEForPreTraining.from_pretrained("MCG-NJU/videomae-base-short"						).to(_UpperCAmelCase						)

														SCREAMING_SNAKE_CASE__       :      Union[str, Any]     =						self.default_image_processor
														SCREAMING_SNAKE_CASE__       :      int     =						prepare_video()
														SCREAMING_SNAKE_CASE__       :      List[str]     =						image_processor(_UpperCAmelCase,			return_tensors="pt"						).to(_UpperCAmelCase						)

														# add boolean mask, indicating which patches to mask
														SCREAMING_SNAKE_CASE__       :      Optional[Any]     =						hf_hub_download(repo_id="hf-internal-testing/bool-masked-pos",			filename="bool_masked_pos.pt"						)
														SCREAMING_SNAKE_CASE__       :      Dict     =						torch.load(_UpperCAmelCase						)

														# forward pass
														with torch.no_grad():
																					SCREAMING_SNAKE_CASE__       :      List[Any]     =						model(**_UpperCAmelCase						)

														# verify the logits
														SCREAMING_SNAKE_CASE__       :      Tuple     =						torch.Size([1, 1_4_0_8, 1_5_3_6]						)
														SCREAMING_SNAKE_CASE__       :      Optional[Any]     =						torch.tensor(
														    [[0.7994, 0.9612, 0.8508], [0.7401, 0.8958, 0.8302], [0.5862, 0.7468, 0.7325]],			device=_UpperCAmelCase						)
														self.assertEqual(outputs.logits.shape,			_UpperCAmelCase						)
														self.assertTrue(torch.allclose(outputs.logits[0, :3, :3],			_UpperCAmelCase,			atol=1E-4						)						)

														# verify the loss (`config.norm_pix_loss` = `True`)
														SCREAMING_SNAKE_CASE__       :      Union[str, Any]     =						torch.tensor([0.5142],			device=_UpperCAmelCase						)
														self.assertTrue(torch.allclose(outputs.loss,			_UpperCAmelCase,			atol=1E-4						)						)

														# verify the loss (`config.norm_pix_loss` = `False`)
														SCREAMING_SNAKE_CASE__       :      Tuple     =						VideoMAEForPreTraining.from_pretrained("MCG-NJU/videomae-base-short",			norm_pix_loss=_UpperCAmelCase						).to(
														    _UpperCAmelCase						)

														with torch.no_grad():
																					SCREAMING_SNAKE_CASE__       :      Optional[Any]     =						model(**_UpperCAmelCase						)

														SCREAMING_SNAKE_CASE__       :      int     =						torch.tensor(torch.tensor([0.6469]						),			device=_UpperCAmelCase						)
														self.assertTrue(torch.allclose(outputs.loss,			_UpperCAmelCase,			atol=1E-4						)						)













from __future__ import annotations

import math
from collections import Counter
from string import ascii_lowercase




def _a (  SCREAMING_SNAKE_CASE__      :  str       )	->    None:

							'''simple docstring'''






							SCREAMING_SNAKE_CASE__   ,SCREAMING_SNAKE_CASE__       :      Dict     =						analyze_text(SCREAMING_SNAKE_CASE__       )
							SCREAMING_SNAKE_CASE__       :      Tuple     =						list(" " + ascii_lowercase       )
							# what is our total sum of probabilities.
							SCREAMING_SNAKE_CASE__       :      str     =						sum(single_char_strings.values()       )

							# one length string
							SCREAMING_SNAKE_CASE__       :      str     =						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:
																					SCREAMING_SNAKE_CASE__       :      Optional[int]     =						single_char_strings[ch]
																					SCREAMING_SNAKE_CASE__       :      Any     =						my_str / all_sum
																					my_fir_sum += prob * math.loga(SCREAMING_SNAKE_CASE__       )  # entropy formula.

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

							# two len string
							SCREAMING_SNAKE_CASE__       :      Union[str, Any]     =						sum(two_char_strings.values()       )
							SCREAMING_SNAKE_CASE__       :      int     =						0
							# for each alpha (two in size) calculate entropy.
							for cha in my_alphas:
														for cha in my_alphas:
																					SCREAMING_SNAKE_CASE__       :      List[str]     =						cha + cha
																					if sequence in two_char_strings:
																												SCREAMING_SNAKE_CASE__       :      Optional[Any]     =						two_char_strings[sequence]
																												SCREAMING_SNAKE_CASE__       :      Tuple     =						int(SCREAMING_SNAKE_CASE__       ) / all_sum
																												my_sec_sum += prob * math.loga(SCREAMING_SNAKE_CASE__       )

    # 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 _a (  SCREAMING_SNAKE_CASE__      :  str       )	->    tuple[dict, dict]:

							'''simple docstring'''






							SCREAMING_SNAKE_CASE__       :      str     =						Counter()  # type: ignore
							SCREAMING_SNAKE_CASE__       :      Dict     =						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(SCREAMING_SNAKE_CASE__       ) - 1       ):
														single_char_strings[text[i]] += 1
														two_char_strings[text[i : i + 2]] += 1
							return single_char_strings, two_char_strings




def _a (  )	->    str:

							'''simple docstring'''






							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()






