





from random import shuffle

import tensorflow as tf
from numpy import array




def       __UpperCamelCase  (_SCREAMING_SNAKE_CASE		,						_SCREAMING_SNAKE_CASE		)    ->       Tuple:
  lowercase__           =  int(_SCREAMING_SNAKE_CASE		)
  assert noofclusters < len(_SCREAMING_SNAKE_CASE		)

  # Find out the dimensionality
  lowercase__           =  len(vectors[0]		)

  # Will help select random centroids from among the available vectors
  lowercase__           =  list(range(len(_SCREAMING_SNAKE_CASE		)		)		)
  shuffle(_SCREAMING_SNAKE_CASE		)

  # GRAPH OF COMPUTATION
  # We initialize a new graph and set it as the default during each run
  # of this algorithm. This ensures that as this function is called
  # multiple times, the default graph doesn't keep getting crowded with
  # unused ops and Variables from previous function calls.

  lowercase__           =  tf.Graph()

  with graph.as_default():
    # SESSION OF COMPUTATION

    lowercase__           =  tf.Session()

    ##CONSTRUCTING THE ELEMENTS OF COMPUTATION

    ##First lets ensure we have a Variable vector for each centroid,
    ##initialized to one of the vectors from the available data points
    lowercase__           =  [
        tf.Variable(vectors[vector_indices[i]]		) for i in range(_SCREAMING_SNAKE_CASE		)
    ]
    ##These nodes will assign the centroid Variables the appropriate
    ##values
    lowercase__           =  tf.placeholder('float64'		,						[dim]		)
    lowercase__           =  []
    for centroid in centroids:
      cent_assigns.append(tf.assign(_SCREAMING_SNAKE_CASE		,						_SCREAMING_SNAKE_CASE		)		)

    ##Variables for cluster assignments of individual vectors(initialized
    ##to 0 at first)
    lowercase__           =  [tf.Variable(0		) for i in range(len(_SCREAMING_SNAKE_CASE		)		)]
    ##These nodes will assign an assignment Variable the appropriate
    ##value
    lowercase__           =  tf.placeholder('int32'		)
    lowercase__           =  []
    for assignment in assignments:
      cluster_assigns.append(tf.assign(_SCREAMING_SNAKE_CASE		,						_SCREAMING_SNAKE_CASE		)		)

    ##Now lets construct the node that will compute the mean
    # The placeholder for the input
    lowercase__           =  tf.placeholder('float'		,						[None, dim]		)
    # The Node/op takes the input and computes a mean along the 0th
    # dimension, i.e. the list of input vectors
    lowercase__           =  tf.reduce_mean(_SCREAMING_SNAKE_CASE		,						0		)

    ##Node for computing Euclidean distances
    # Placeholders for input
    lowercase__           =  tf.placeholder('float'		,						[dim]		)
    lowercase__           =  tf.placeholder('float'		,						[dim]		)
    lowercase__           =  tf.sqrt(tf.reduce_sum(tf.pow(tf.sub(_SCREAMING_SNAKE_CASE		,						_SCREAMING_SNAKE_CASE		)		,						2		)		)		)

    ##This node will figure out which cluster to assign a vector to,
    ##based on Euclidean distances of the vector from the centroids.
    # Placeholder for input
    lowercase__           =  tf.placeholder('float'		,						[noofclusters]		)
    lowercase__           =  tf.argmin(_SCREAMING_SNAKE_CASE		,						0		)

    ##INITIALIZING STATE VARIABLES

    ##This will help initialization of all Variables defined with respect
    ##to the graph. The Variable-initializer should be defined after
    ##all the Variables have been constructed, so that each of them
    ##will be included in the initialization.
    lowercase__           =  tf.initialize_all_variables()

    # Initialize all variables
    sess.run(_SCREAMING_SNAKE_CASE		)

    ##CLUSTERING ITERATIONS

    # Now perform the Expectation-Maximization steps of K-Means clustering
    # iterations. To keep things simple, we will only do a set number of
    # iterations, instead of using a Stopping Criterion.
    lowercase__           =  100
    for _ in range(_SCREAMING_SNAKE_CASE		):
      ##EXPECTATION STEP
      ##Based on the centroid locations till last iteration, compute
      ##the _expected_ centroid assignments.
      # Iterate over each vector
      for vector_n in range(len(_SCREAMING_SNAKE_CASE		)		):
        lowercase__           =  vectors[vector_n]
        # Compute Euclidean distance between this vector and each
        # centroid. Remember that this list cannot be named
        #'centroid_distances', since that is the input to the
        # cluster assignment node.
        lowercase__           =  [
            sess.run(_SCREAMING_SNAKE_CASE		,						feed_dict={va: vect, va: sess.run(_SCREAMING_SNAKE_CASE		)}		)
            for centroid in centroids
        ]
        # Now use the cluster assignment node, with the distances
        # as the input
        lowercase__           =  sess.run(
            _SCREAMING_SNAKE_CASE		,						feed_dict={centroid_distances: distances}		)
        # Now assign the value to the appropriate state variable
        sess.run(
            cluster_assigns[vector_n]		,						feed_dict={assignment_value: assignment}		)

      ##MAXIMIZATION STEP
      # Based on the expected state computed from the Expectation Step,
      # compute the locations of the centroids so as to maximize the
      # overall objective of minimizing within-cluster Sum-of-Squares
      for cluster_n in range(_SCREAMING_SNAKE_CASE		):
        # Collect all the vectors assigned to this cluster
        lowercase__           =  [
            vectors[i]
            for i in range(len(_SCREAMING_SNAKE_CASE		)		)
            if sess.run(assignments[i]		) == cluster_n
        ]
        # Compute new centroid location
        lowercase__           =  sess.run(
            _SCREAMING_SNAKE_CASE		,						feed_dict={mean_input: array(_SCREAMING_SNAKE_CASE		)}		)
        # Assign value to appropriate variable
        sess.run(
            cent_assigns[cluster_n]		,						feed_dict={centroid_value: new_location}		)

        # Return centroids and assignments
    lowercase__           =  sess.run(_SCREAMING_SNAKE_CASE		)
    lowercase__           =  sess.run(_SCREAMING_SNAKE_CASE		)
    return centroids, assignments









import warnings

from ...configuration_utils import PretrainedConfig
from ...utils import logging


lowercase_          =		logging.get_logger(__name__)

lowercase_          =		{
    """xlnet-base-cased""": """https://huggingface.co/xlnet-base-cased/resolve/main/config.json""",
    """xlnet-large-cased""": """https://huggingface.co/xlnet-large-cased/resolve/main/config.json""",
}
class     SCREAMING_SNAKE_CASE       (UpperCAmelCase				):
   _UpperCamelCase   :		str			 =	'xlnet'
   _UpperCamelCase   :		Optional[Any]			 =	['mems']
   _UpperCamelCase   :		Union[str, Any]			 =	{
       'n_token': 'vocab_size',  # Backward compatibility
       'hidden_size': 'd_model',
       'num_attention_heads': 'n_head',
       'num_hidden_layers': 'n_layer',
   }


   def __init__(   self      :    str      ,					a      :    int=32_000      ,					a      :    Any=1_024      ,					a      :    Optional[Any]=24      ,					a      :    str=16      ,					a      :    int=4_096      ,					a      :    List[str]="gelu"      ,					a      :    Any=True      ,					a      :    Dict="bi"      ,					a      :    str=0.02      ,					a      :    List[str]=1E-1_2      ,					a      :    Tuple=0.1      ,					a      :    Optional[Any]=512      ,					a      :    Tuple=None      ,					a      :    Union[str, Any]=True      ,					a      :    int=False      ,					a      :    int=False      ,					a      :    Tuple=-1      ,					a      :    Any=False      ,					a      :    Tuple="last"      ,					a      :    List[str]=True      ,					a      :    Optional[Any]="tanh"      ,					a      :    List[Any]=0.1      ,					a      :    int=5      ,					a      :    List[Any]=5      ,					a      :    Optional[int]=5      ,					a      :    Dict=1      ,					a      :    Optional[Any]=2      ,					**a      :    List[Any]      ,					)->       List[str]:





     """simple docstring"""







     lowercase__           =  vocab_size
     lowercase__           =  d_model
     lowercase__           =  n_layer
     lowercase__           =  n_head
     if d_model % n_head != 0:
       raise ValueError(f"""'d_model % n_head' ({d_model % n_head}) should be equal to 0"""	)
     if "d_head" in kwargs:
       if kwargs["d_head"] != d_model // n_head:
         raise ValueError(
             f"""`d_head` ({kwargs["d_head"]}) should be equal to `d_model // n_head` ({d_model // n_head})"""	)
     lowercase__           =  d_model // n_head
     lowercase__           =  ff_activation
     lowercase__           =  d_inner
     lowercase__           =  untie_r
     lowercase__           =  attn_type

     lowercase__           =  initializer_range
     lowercase__           =  layer_norm_eps

     lowercase__           =  dropout
     lowercase__           =  mem_len
     lowercase__           =  reuse_len
     lowercase__           =  bi_data
     lowercase__           =  clamp_len
     lowercase__           =  same_length

     lowercase__           =  summary_type
     lowercase__           =  summary_use_proj
     lowercase__           =  summary_activation
     lowercase__           =  summary_last_dropout
     lowercase__           =  start_n_top
     lowercase__           =  end_n_top

     lowercase__           =  bos_token_id
     lowercase__           =  pad_token_id
     lowercase__           =  eos_token_id

     if "use_cache" in kwargs:
       warnings.warn(
           'The `use_cache` argument is deprecated and will be removed in a future version, use `use_mems_eval`'
           ' instead.'      ,					a      ,					)
       lowercase__           =  kwargs['use_cache']

     lowercase__           =  use_mems_eval
     lowercase__           =  use_mems_train
     super().__init__(pad_token_id=a      ,					bos_token_id=a      ,					eos_token_id=a      ,					**a	)


   @property
   def 	SCREAMING_SNAKE_CASE_							(   self      :    Optional[Any]	)->       List[str]:





     """simple docstring"""







     logger.info(f"""The model {self.model_type} is one of the few models that has no sequence length limit."""	)
     return -1


   @max_position_embeddings.setter
   def 	SCREAMING_SNAKE_CASE_							(   self      :    Tuple      ,					a      :    Union[str, Any]	)->       List[Any]:





     """simple docstring"""







     raise NotImplementedError(
         f"""The model {self.model_type} is one of the few models that has no sequence length limit."""	)


