




"""simple docstring"""


import json
from typing import TYPE_CHECKING, List, Optional, Tuple

from tokenizers import pre_tokenizers

from ...tokenization_utils_base import BatchEncoding
from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging
from .tokenization_gpta import GPTaTokenizer


if TYPE_CHECKING:
     from transformers.pipelines.conversational import Conversation


A_						=				logging.get_logger(__name__)

A_						=				{'''vocab_file''': '''vocab.json''', '''merges_file''': '''merges.txt''', '''tokenizer_file''': '''tokenizer.json'''}

A_						=				{
    '''vocab_file''': {
        '''gpt2''': '''https://huggingface.co/gpt2/resolve/main/vocab.json''',
        '''gpt2-medium''': '''https://huggingface.co/gpt2-medium/resolve/main/vocab.json''',
        '''gpt2-large''': '''https://huggingface.co/gpt2-large/resolve/main/vocab.json''',
        '''gpt2-xl''': '''https://huggingface.co/gpt2-xl/resolve/main/vocab.json''',
        '''distilgpt2''': '''https://huggingface.co/distilgpt2/resolve/main/vocab.json''',
    },
    '''merges_file''': {
        '''gpt2''': '''https://huggingface.co/gpt2/resolve/main/merges.txt''',
        '''gpt2-medium''': '''https://huggingface.co/gpt2-medium/resolve/main/merges.txt''',
        '''gpt2-large''': '''https://huggingface.co/gpt2-large/resolve/main/merges.txt''',
        '''gpt2-xl''': '''https://huggingface.co/gpt2-xl/resolve/main/merges.txt''',
        '''distilgpt2''': '''https://huggingface.co/distilgpt2/resolve/main/merges.txt''',
    },
    '''tokenizer_file''': {
        '''gpt2''': '''https://huggingface.co/gpt2/resolve/main/tokenizer.json''',
        '''gpt2-medium''': '''https://huggingface.co/gpt2-medium/resolve/main/tokenizer.json''',
        '''gpt2-large''': '''https://huggingface.co/gpt2-large/resolve/main/tokenizer.json''',
        '''gpt2-xl''': '''https://huggingface.co/gpt2-xl/resolve/main/tokenizer.json''',
        '''distilgpt2''': '''https://huggingface.co/distilgpt2/resolve/main/tokenizer.json''',
    },
}

A_						=				{
    '''gpt2''': 10_24,
    '''gpt2-medium''': 10_24,
    '''gpt2-large''': 10_24,
    '''gpt2-xl''': 10_24,
    '''distilgpt2''': 10_24,
}






class 					lowercase(     __a ):







 '''simple docstring'''





 lowercase__ 					=					VOCAB_FILES_NAMES
 lowercase__ 					=					PRETRAINED_VOCAB_FILES_MAP
 lowercase__ 					=					PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
 lowercase__ 					=					["input_ids", "attention_mask"]
 lowercase__ 					=					GPTaTokenizer


 def __init__(				self:		Any,      a_:		Optional[Any]=None,      a_:		Tuple=None,      a_:		Optional[int]=None,      a_:		Dict="<|endoftext|>",      a_:		Tuple="<|endoftext|>",      a_:		Optional[Any]="<|endoftext|>",      a_:		List[str]=False,      **a_:		Any,      ):




   '''simple docstring'''



   super().__init__(
       a_,      a_,      tokenizer_file=a_,      unk_token=a_,      bos_token=a_,      eos_token=a_,      add_prefix_space=a_,      **a_,      )

   _snake_case							:		List[Any]								=  kwargs.pop("""add_bos_token""",      a_		)

   _snake_case							:		Any								=  json.loads(self.backend_tokenizer.pre_tokenizer.__getstate__()		)
   if pre_tok_state.get("""add_prefix_space""",      a_		) != add_prefix_space:
     _snake_case							:		Any								=  getattr(a_,      pre_tok_state.pop("""type"""		)		)
     _snake_case							:		Union[str, Any]								=  add_prefix_space
     _snake_case							:		Optional[int]								=  pre_tok_class(**a_		)

   _snake_case							:		Any								=  add_prefix_space


 def  UpperCamelCase_   (				self:		Tuple,      *a_:		List[str],      **a_:		Tuple		):




   '''simple docstring'''



   _snake_case							:		Optional[Any]								=  kwargs.get("""is_split_into_words""",      a_		)
   assert self.add_prefix_space or not is_split_into_words, (
       f"You need to instantiate {self.__class__.__name__} with add_prefix_space=True "
       "to use it with pretokenized inputs."
   )

   return super()._batch_encode_plus(*a_,      **a_		)


 def  UpperCamelCase_   (				self:		Optional[Any],      *a_:		Optional[Any],      **a_:		Dict		):




   '''simple docstring'''



   _snake_case							:		Dict								=  kwargs.get("""is_split_into_words""",      a_		)

   assert self.add_prefix_space or not is_split_into_words, (
       f"You need to instantiate {self.__class__.__name__} with add_prefix_space=True "
       "to use it with pretokenized inputs."
   )

   return super()._encode_plus(*a_,      **a_		)


 def  UpperCamelCase_   (				self:		List[Any],      a_:		str,      a_:		Optional[str] = None		):




   '''simple docstring'''



   _snake_case							:		Any								=  self._tokenizer.model.save(a_,      name=a_		)
   return tuple(a_		)


 def  UpperCamelCase_   (				self:		int,      a_:		"Conversation"		):




   '''simple docstring'''



   _snake_case							:		Any								=  []
   for is_user, text in conversation.iter_texts():
     input_ids.extend(self.encode(a_,      add_special_tokens=a_		) + [self.eos_token_id]		)

   if len(a_		) > self.model_max_length:
     _snake_case							:		List[Any]								=  input_ids[-self.model_max_length :]
   return input_ids









'''simple docstring'''







import math
class 				__SCREAMING_SNAKE_CASE  :






				"""simple docstring"""







				def   UpperCamelCase__   (  self     :					List[str]					,				__a     :					list[list[float]]					,				__a     :					list[int]					):
								_a								= 0.0
								_a								= 0.0
								for i in range(len(__a					)					):
												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   UpperCamelCase__   (  self     :					List[Any]					,				__a     :					list[list[int | float]]					,				__a     :					list[int]					,				__a     :					int					,				__a     :					float					):
								for i in range(len(__a					)					):
												weights[j][i] += alpha * (sample[i] - weights[j][i])
								return weights






def  _lowerCamelCase				( )	->	None:
				# Training Examples ( m, n )
				_a								= [[1, 1, 0, 0], [0, 0, 0, 1], [1, 0, 0, 0], [0, 0, 1, 1]]

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

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

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

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

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

    # classify test sample
				_a								= [0, 0, 0, 1]
				_a								= 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()
