





import math

class   lowerCAmelCase				:
 def 	A_      ( self    : Tuple     ,	UpperCAmelCase    : list[list[float]]     ,	UpperCAmelCase    : list[int]      )     ->      int:
     lowerCamelCase__       : str   					=						0.0
     lowerCamelCase__       : Dict   					=						0.0
     for i in range(len(UpperCAmelCase      )      ):
         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    : Union[str, Any]     ,	UpperCAmelCase    : list[list[int | float]]     ,	UpperCAmelCase    : list[int]     ,	UpperCAmelCase    : int     ,	UpperCAmelCase    : float      )     ->      list[list[int | float]]:
     for i in range(len(UpperCAmelCase      )      ):
         weights[j][i] += alpha * (sample[i] - weights[j][i])
     return weights


def 			SCREAMING_SNAKE_CASE (			)     ->	None:
    # Training Examples ( m, n )
    lowerCamelCase__       : Union[str, Any]   					=						[[1, 1, 0, 0], [0, 0, 0, 1], [1, 0, 0, 0], [0, 0, 1, 1]]

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

    # training
    lowerCamelCase__       : Any   					=						SelfOrganizingMap()
    lowerCamelCase__       : Any   					=						3
    lowerCamelCase__       : Dict   					=						0.5

    for _ in range(_UpperCAmelCase					):
        for j in range(len(_UpperCAmelCase					)					):
            # training sample
            lowerCamelCase__       : Union[str, Any]   					=						training_samples[j]

            # Compute the winning vector
            lowerCamelCase__       : Optional[Any]   					=						self_organizing_map.get_winner(_UpperCAmelCase		,      _UpperCAmelCase					)

            # Update the winning vector
            lowerCamelCase__       : str   					=						self_organizing_map.update(_UpperCAmelCase		,      _UpperCAmelCase		,      _UpperCAmelCase		,      _UpperCAmelCase					)

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












from __future__ import annotations

import unittest

from transformers import is_tf_available
from transformers.testing_utils import require_sentencepiece, require_tf, require_tokenizers, slow


if is_tf_available():
    import numpy as np
    import tensorflow as tf

    from transformers import TFCamembertModel

@require_tf
@require_sentencepiece
@require_tokenizers
class   lowerCAmelCase				(   unittest.TestCase     ):
 @slow
 def 	A_      ( self    : Union[str, Any]      )     ->      List[Any]:
     lowerCamelCase__       : Tuple   					=						TFCamembertModel.from_pretrained('jplu/tf-camembert-base'      )

     lowerCamelCase__       : Any   					=						tf.convert_to_tensor(
         [[5, 121, 11, 660, 16, 730, 25543, 110, 83, 6]]     ,	dtype=tf.intaa     ,	)  # J'aime le camembert !"

     lowerCamelCase__       : List[str]   					=						model(UpperCAmelCase      )['last_hidden_state']
     lowerCamelCase__       : Tuple   					=						tf.TensorShape((1, 10, 768)      )
     self.assertEqual(output.shape     ,	UpperCAmelCase      )
     # compare the actual values for a slice.
     lowerCamelCase__       : Optional[Any]   					=						tf.convert_to_tensor(
         [[[-0.0_2_5_4, 0.0_2_3_5, 0.1_0_2_7], [0.0_6_0_6, -0.1_8_1_1, -0.0_4_1_8], [-0.1_5_6_1, -0.1_1_2_7, 0.2_6_8_7]]]     ,	dtype=tf.floataa     ,	)
     # camembert = torch.hub.load('pytorch/fairseq', 'camembert.v0')
     # camembert.eval()
     # expected_slice = roberta.model.forward(input_ids)[0][:, :3, :3].detach()

     self.assertTrue(np.allclose(output[:, :3, :3].numpy()     ,	expected_slice.numpy()     ,	atol=1e-4      )      )





