

'''simple docstring'''
import math

class 						__magic_name__   :







 def 						_A(       self  , snake_case_  , snake_case_   ):
   lowercase									=0.0
   lowercase									=0.0
   for i in range(len(snake_case_   )   ):
     da += math.pow((sample[i] - weights[0][i])  , 2   )
     da += math.pow((sample[i] - weights[1][i])  , 2   )
     return 0 if da > da else 1
   return 0







 def 						_A(       self  , snake_case_  , snake_case_  , snake_case_  , snake_case_   ):
   for i in range(len(snake_case_   )   ):
     weights[j][i] += alpha * (sample[i] - weights[j][i])
   return weights




def 	UpperCamelCase   (       )		->	None:




  '''simple docstring'''



  lowercase									=[[1, 1, 0, 0], [0, 0, 0, 1], [1, 0, 0, 0], [0, 0, 1, 1]]

  # weight initialization ( n, C )
  lowercase									=[[0.2, 0.6, 0.5, 0.9], [0.8, 0.4, 0.7, 0.3]]

  # training
  lowercase									=SelfOrganizingMap()
  lowercase									=3
  lowercase									=0.5

  for _ in range(lowercase_	):
    for j in range(len(lowercase_	)	):
      # training sample
      lowercase									=training_samples[j]

      # Compute the winning vector
      lowercase									=self_organizing_map.get_winner(lowercase_     ,					lowercase_	)

      # Update the winning vector
      lowercase									=self_organizing_map.update(lowercase_     ,					lowercase_     ,					lowercase_     ,					lowercase_	)

    # classify test sample
  lowercase									=[0, 0, 0, 1]
  lowercase									=self_organizing_map.get_winner(lowercase_     ,					lowercase_	)

  # results
  print(f'Clusters that the test sample belongs to : {winner}'	)
  print(f'Weights that have been trained : {weights}'	)


# running the main() function
if __name__ == "__main__":
     main()


"""simple docstring"""


import torch
import torch.nn as nn
from transformers.modeling_utils import ModuleUtilsMixin
from transformers.models.ta.modeling_ta import TaBlock, TaConfig, TaLayerNorm

from ...configuration_utils import ConfigMixin, register_to_config
from ...models import ModelMixin



class 	__a	(   _lowerCAmelCase     ,  _lowerCAmelCase     ,  _lowerCAmelCase						):






       @register_to_config
       def __init__(	self			:				Union[str, Any]							,   UpperCAmelCase_			:				int							,   UpperCAmelCase_			:				int							,   UpperCAmelCase_			:				int							,   UpperCAmelCase_			:				float							,   UpperCAmelCase_			:				int							,   UpperCAmelCase_			:				int							,   UpperCAmelCase_			:				int							,   UpperCAmelCase_			:				int							,   UpperCAmelCase_			:				str							,   UpperCAmelCase_			:				bool = False							,   )->	str:







              """simple docstring"""
              super().__init__()

              UpperCamelCase       			=		nn.Embedding(UpperCAmelCase_							,   UpperCAmelCase_      )

              UpperCamelCase       			=		nn.Embedding(UpperCAmelCase_							,   UpperCAmelCase_      )
              UpperCamelCase       			=		False

              UpperCamelCase       			=		nn.Dropout(p=UpperCAmelCase_      )

              UpperCamelCase       			=		TaConfig(
                  vocab_size=UpperCAmelCase_							,   d_model=UpperCAmelCase_							,   num_heads=UpperCAmelCase_							,   d_kv=UpperCAmelCase_							,   d_ff=UpperCAmelCase_							,   dropout_rate=UpperCAmelCase_							,   feed_forward_proj=UpperCAmelCase_							,   is_decoder=UpperCAmelCase_							,   is_encoder_decoder=UpperCAmelCase_							,   )

              UpperCamelCase       			=		nn.ModuleList()
              for lyr_num in range(UpperCAmelCase_      ):
                     UpperCamelCase       			=		TaBlock(UpperCAmelCase_      )
                     self.encoders.append(UpperCAmelCase_      )

              UpperCamelCase       			=		TaLayerNorm(UpperCAmelCase_      )
              UpperCamelCase       			=		nn.Dropout(p=UpperCAmelCase_      )






       def 						_SCREAMING_SNAKE_CASE							(	self			:				int							,   UpperCAmelCase_			:				int							,   UpperCAmelCase_			:				str      )->	List[Any]:







              """simple docstring"""
              UpperCamelCase       			=		self.token_embedder(UpperCAmelCase_      )

              UpperCamelCase       			=		encoder_input_tokens.shape[1]
              UpperCamelCase       			=		torch.arange(UpperCAmelCase_							,   device=encoder_input_tokens.device      )
              x += self.position_encoding(UpperCAmelCase_      )

              UpperCamelCase       			=		self.dropout_pre(UpperCAmelCase_      )

              # inverted the attention mask
              UpperCamelCase       			=		encoder_input_tokens.size()
              UpperCamelCase       			=		self.get_extended_attention_mask(UpperCAmelCase_							,   UpperCAmelCase_      )

              for lyr in self.encoders:
                     UpperCamelCase       			=		lyr(UpperCAmelCase_							,   UpperCAmelCase_      )[0]
              UpperCamelCase       			=		self.layer_norm(UpperCAmelCase_      )

              return self.dropout_post(UpperCAmelCase_      ), encoder_inputs_mask





