


'''simple docstring'''
import unittest

from transformers import AlbertTokenizer, AlbertTokenizerFast
from transformers.testing_utils import get_tests_dir, require_sentencepiece, require_tokenizers, slow

from ...test_tokenization_common import TokenizerTesterMixin


UpperCAmelCase_ :     List[Any]								=      get_tests_dir('fixtures/spiece.model')

@require_sentencepiece
@require_tokenizers
class 						_lowerCamelCase					(    snake_case_    ,		unittest.TestCase				):




 '''simple docstring'''
 __lowercase				:		int    							=						AlbertTokenizer
 __lowercase				:		Any    							=						AlbertTokenizerFast
 __lowercase				:		Optional[Any]    							=						True
 __lowercase				:		Union[str, Any]    							=						True
 __lowercase				:		Optional[Any]    							=						True


 def  snake_case__   (      self						):

  """simple docstring"""







  super().setUp()

  # We have a SentencePiece fixture for testing
  __A  :		Union[str, Any]       =			AlbertTokenizer(__lowercase						)
  tokenizer.save_pretrained(self.tmpdirname						)


 def  snake_case__   (      self      ,      __lowercase						):

  """simple docstring"""







  __A  :		List[Any]       =			'this is a test'
  __A  :		Optional[Any]       =			'this is a test'
  return input_text, output_text


 def  snake_case__   (      self						):

  """simple docstring"""







  __A  :		Optional[int]       =			'<pad>'
  __A  :		Optional[int]       =			0

  self.assertEqual(self.get_tokenizer()._convert_token_to_id(__lowercase						)      ,      __lowercase						)
  self.assertEqual(self.get_tokenizer()._convert_id_to_token(__lowercase						)      ,      __lowercase						)


 def  snake_case__   (      self						):

  """simple docstring"""







  __A  :		Optional[Any]       =			list(self.get_tokenizer().get_vocab().keys()						)

  self.assertEqual(vocab_keys[0]      ,      '<pad>'						)
  self.assertEqual(vocab_keys[1]      ,      '<unk>'						)
  self.assertEqual(vocab_keys[-1]      ,      '▁eloquent'						)
  self.assertEqual(len(__lowercase						)      ,      30_000						)


 def  snake_case__   (      self						):

  """simple docstring"""







  self.assertEqual(self.get_tokenizer().vocab_size      ,      30_000						)


 def  snake_case__   (      self						):

  """simple docstring"""







  if not self.test_rust_tokenizer:
   return

  __A  :		Optional[Any]       =			self.get_tokenizer()
  __A  :		Dict       =			self.get_rust_tokenizer()

  __A  :		Union[str, Any]       =			'I was born in 92000, and this is falsé.'

  __A  :		Optional[int]       =			tokenizer.tokenize(__lowercase						)
  __A  :		Optional[Any]       =			rust_tokenizer.tokenize(__lowercase						)
  self.assertListEqual(__lowercase      ,      __lowercase						)

  __A  :		List[str]       =			tokenizer.encode(__lowercase      ,      add_special_tokens=__lowercase						)
  __A  :		Union[str, Any]       =			rust_tokenizer.encode(__lowercase      ,      add_special_tokens=__lowercase						)
  self.assertListEqual(__lowercase      ,      __lowercase						)

  __A  :		List[str]       =			self.get_rust_tokenizer()
  __A  :		Optional[Any]       =			tokenizer.encode(__lowercase						)
  __A  :		Union[str, Any]       =			rust_tokenizer.encode(__lowercase						)
  self.assertListEqual(__lowercase      ,      __lowercase						)


 def  snake_case__   (      self						):

  """simple docstring"""







  __A  :		Union[str, Any]       =			AlbertTokenizer(__lowercase      ,      keep_accents=__lowercase						)

  __A  :		Dict       =			tokenizer.tokenize('This is a test'						)
  self.assertListEqual(__lowercase      ,      ['▁this', '▁is', '▁a', '▁test']						)

  self.assertListEqual(tokenizer.convert_tokens_to_ids(__lowercase						)      ,      [48, 25, 21, 1_289]						)

  __A  :		List[Any]       =			tokenizer.tokenize('I was born in 92000, and this is falsé.'						)
  self.assertListEqual(
      __lowercase      ,      ['▁i', '▁was', '▁born', '▁in', '▁9', '2000', ',', '▁and', '▁this', '▁is', '▁fal', 's', 'é', '.']						)
  __A  :		Optional[int]       =			tokenizer.convert_tokens_to_ids(__lowercase						)
  self.assertListEqual(__lowercase      ,      [31, 23, 386, 19, 561, 3_050, 15, 17, 48, 25, 8_256, 18, 1, 9]						)

  __A  :		List[Any]       =			tokenizer.convert_ids_to_tokens(__lowercase						)
  self.assertListEqual(
      __lowercase      ,      ['▁i', '▁was', '▁born', '▁in', '▁9', '2000', ',', '▁and', '▁this', '▁is', '▁fal', 's', '<unk>', '.']      ,      )


 def  snake_case__   (      self						):

  """simple docstring"""







  __A  :		Union[str, Any]       =			AlbertTokenizer(__lowercase						)

  __A  :		Any       =			tokenizer.encode('sequence builders'						)
  __A  :		List[str]       =			tokenizer.encode('multi-sequence build'						)

  __A  :		Dict       =			tokenizer.build_inputs_with_special_tokens(__lowercase						)
  __A  :		List[Any]       =			tokenizer.build_inputs_with_special_tokens(__lowercase      ,      __lowercase						)

  assert encoded_sentence == [tokenizer.cls_token_id] + text + [tokenizer.sep_token_id]
  assert encoded_pair == [tokenizer.cls_token_id] + text + [tokenizer.sep_token_id] + text_a + [
      tokenizer.sep_token_id
  ]







 @slow
 def  snake_case__   (      self						):

  """simple docstring"""







  __A  :		Dict       =			{'attention_mask': [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], 'input_ids': [[2, 21_970, 13, 5, 6_092, 167, 28, 7_103, 2_153, 673, 8, 7_028, 12_051, 18, 17, 7_103, 2_153, 673, 8, 3_515, 18_684, 8, 4_461, 6, 1_927, 297, 8, 12_060, 2_607, 18, 13, 5, 4_461, 15, 10_538, 38, 8, 135, 15, 822, 58, 15, 993, 10_363, 15, 1_460, 8_005, 4_461, 15, 993, 255, 2_328, 9, 9, 9, 6, 26, 1_112, 816, 3_260, 13, 5, 103, 2_377, 6, 17, 1_112, 816, 2_782, 13, 5, 103, 10_641, 6, 29, 84, 2_512, 2_430, 782, 18_684, 2_761, 19, 808, 2_430, 2_556, 17, 855, 1_480, 9_477, 4_091, 128, 11_712, 15, 7_103, 2_153, 673, 17, 24_883, 9_990, 9, 3], [2, 11_502, 25, 1_006, 20, 782, 8, 11_809, 855, 1_732, 19_393, 18_667, 37, 367, 21_018, 69, 1_854, 34, 11_860, 19_124, 27, 156, 225, 17, 193, 4_141, 19, 65, 9_124, 9, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [2, 14, 2_231, 886, 2_385, 17_659, 84, 14, 16_792, 1_952, 9, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0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0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]}  # noqa: E501
  # fmt: on

  self.tokenizer_integration_test_util(
      expected_encoding=__lowercase      ,      model_name='albert-base-v2'      ,      revision='6b6560eaf5ff2e250b00c50f380c5389a9c2d82e'      ,      )










'''simple docstring'''
import math

class 						_lowerCamelCase					:




 '''simple docstring'''


 def  snake_case__   (      self      ,      __lowercase      ,      __lowercase						):

  """simple docstring"""







  __A  :		List[str]       =			0.0
  __A  :		Optional[int]       =			0.0
  for i in range(len(__lowercase						)						):
   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  snake_case__   (      self      ,      __lowercase      ,      __lowercase      ,      __lowercase      ,      __lowercase						):

  """simple docstring"""







  for i in range(len(__lowercase						)						):
   weights[j][i] += alpha * (sample[i] - weights[j][i])
  return weights


def 			_lowercase       (				):
 # Training Examples ( m, n )
 __A  :		Union[str, Any]       =			[[1, 1, 0, 0], [0, 0, 0, 1], [1, 0, 0, 0], [0, 0, 1, 1]]

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

 # training
 __A  :		Optional[int]       =			SelfOrganizingMap()
 __A  :		int       =			3
 __A  :		Optional[Any]       =			0.5

 for _ in range(UpperCamelCase__			):
  for j in range(len(UpperCamelCase__			)			):
   # training sample
   __A  :		Dict       =			training_samples[j]

   # Compute the winning vector
   __A  :		List[Any]       =			self_organizing_map.get_winner(UpperCamelCase__,				UpperCamelCase__			)

   # Update the winning vector
   __A  :		Union[str, Any]       =			self_organizing_map.update(UpperCamelCase__,				UpperCamelCase__,				UpperCamelCase__,				UpperCamelCase__			)

    # classify test sample
 __A  :		int       =			[0, 0, 0, 1]
 __A  :		List[Any]       =			self_organizing_map.get_winner(UpperCamelCase__,				UpperCamelCase__			)

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






