'''simple docstring'''




import tensorflow as tf

from ...tf_utils import shape_list




class     a__      (   tf.keras.layers.Layer ):






     def __init__( self		:		Tuple  ,				a		:		Any  ,				a		:		Any  ,				a		:		Optional[Any]  ,				a		:		Optional[int]  ,				a		:		str=1  ,				a		:		Optional[int]=False  ,				**a		:		str    ):





         """simple docstring"""



         super().__init__(**a    )

         __lowerCamelCase		=  vocab_size
         __lowerCamelCase		=  d_embed
         __lowerCamelCase		=  d_proj

         __lowerCamelCase		=  cutoffs + [vocab_size]
         __lowerCamelCase		=  [0] + self.cutoffs
         __lowerCamelCase		=  div_val

         __lowerCamelCase		=  self.cutoffs[0]
         __lowerCamelCase		=  len(self.cutoffs    ) - 1
         __lowerCamelCase		=  self.shortlist_size + self.n_clusters
         __lowerCamelCase		=  keep_order

         __lowerCamelCase		=  []
         __lowerCamelCase		=  []






     def    SCREAMING_SNAKE_CASE__   ( self		:		int  ,				a		:		int    ):





         """simple docstring"""



         if self.n_clusters > 0:
             __lowerCamelCase		=  self.add_weight(
                 shape=(self.n_clusters, self.d_embed)  ,				initializer='''zeros'''  ,				trainable=a  ,				name='''cluster_weight'''    )
             __lowerCamelCase		=  self.add_weight(
                 shape=(self.n_clusters,)  ,				initializer='''zeros'''  ,				trainable=a  ,				name='''cluster_bias'''    )

         if self.div_val == 1:
             for i in range(len(self.cutoffs    )    ):
                 if self.d_proj != self.d_embed:
                     __lowerCamelCase		=  self.add_weight(
                         shape=(self.d_embed, self.d_proj)  ,				initializer='''zeros'''  ,				trainable=a  ,				name=f"""out_projs_._{i}"""  ,				)
                     self.out_projs.append(a    )
                 else:
                     self.out_projs.append(a    )
                 __lowerCamelCase		=  self.add_weight(
                     shape=(self.vocab_size, self.d_embed)  ,				initializer='''zeros'''  ,				trainable=a  ,				name=f"""out_layers_._{i}_._weight"""  ,				)
                 __lowerCamelCase		=  self.add_weight(
                     shape=(self.vocab_size,)  ,				initializer='''zeros'''  ,				trainable=a  ,				name=f"""out_layers_._{i}_._bias"""  ,				)
                 self.out_layers.append((weight, bias)    )
         else:
             for i in range(len(self.cutoffs    )    ):
                 __lowerCamelCase	,  __lowerCamelCase		=  self.cutoff_ends[i], self.cutoff_ends[i + 1]
                 __lowerCamelCase		=  self.d_embed // (self.div_val**i)

                 __lowerCamelCase		=  self.add_weight(
                     shape=(d_emb_i, self.d_proj)  ,				initializer='''zeros'''  ,				trainable=a  ,				name=f"""out_projs_._{i}"""    )
                 self.out_projs.append(a    )
                 __lowerCamelCase		=  self.add_weight(
                     shape=(r_idx - l_idx, d_emb_i)  ,				initializer='''zeros'''  ,				trainable=a  ,				name=f"""out_layers_._{i}_._weight"""  ,				)
                 __lowerCamelCase		=  self.add_weight(
                     shape=(r_idx - l_idx,)  ,				initializer='''zeros'''  ,				trainable=a  ,				name=f"""out_layers_._{i}_._bias"""  ,				)
                 self.out_layers.append((weight, bias)    )
         super().build(a    )






     @staticmethod
     def    SCREAMING_SNAKE_CASE__   ( a		:		Optional[Any]  ,				a		:		Dict  ,				a		:		Optional[Any]  ,				a		:		List[str]=None    ):





         """simple docstring"""



         __lowerCamelCase		=  x
         if proj is not None:
             __lowerCamelCase		=  tf.einsum('''ibd,ed->ibe'''  ,				a  ,				a    )
         return tf.einsum('''ibd,nd->ibn'''  ,				a  ,				a    ) + b






     @staticmethod
     def    SCREAMING_SNAKE_CASE__   ( a		:		List[str]  ,				a		:		Tuple    ):





         """simple docstring"""



         __lowerCamelCase		=  shape_list(a    )
         __lowerCamelCase		=  tf.range(lp_size[0]  ,				dtype=target.dtype    )
         __lowerCamelCase		=  tf.stack([r, target]  ,				1    )
         return tf.gather_nd(a  ,				a    )






     def    SCREAMING_SNAKE_CASE__   ( self		:		List[Any]  ,				a		:		Optional[int]  ,				a		:		Dict  ,				a		:		int=True  ,				a		:		Dict=False    ):





         """simple docstring"""



         __lowerCamelCase		=  0
         if self.n_clusters == 0:
             __lowerCamelCase		=  self._logit(a  ,				self.out_layers[0][0]  ,				self.out_layers[0][1]  ,				self.out_projs[0]    )
             if target is not None:
                 __lowerCamelCase		=  tf.nn.sparse_softmax_cross_entropy_with_logits(labels=a  ,				logits=a    )
             __lowerCamelCase		=  tf.nn.log_softmax(a  ,				axis=-1    )
         else:
             __lowerCamelCase		=  shape_list(a    )
             __lowerCamelCase		=  []
             __lowerCamelCase		=  tf.zeros(hidden_sizes[:2]    )
             for i in range(len(self.cutoffs    )    ):
                 __lowerCamelCase	,  __lowerCamelCase		=  self.cutoff_ends[i], self.cutoff_ends[i + 1]
                 if target is not None:
                     __lowerCamelCase		=  (target >= l_idx) & (target < r_idx)
                     __lowerCamelCase		=  tf.where(a    )
                     __lowerCamelCase		=  tf.boolean_mask(a  ,				a    ) - l_idx

                 if self.div_val == 1:
                     __lowerCamelCase		=  self.out_layers[0][0][l_idx:r_idx]
                     __lowerCamelCase		=  self.out_layers[0][1][l_idx:r_idx]
                 else:
                     __lowerCamelCase		=  self.out_layers[i][0]
                     __lowerCamelCase		=  self.out_layers[i][1]

                 if i == 0:
                     __lowerCamelCase		=  tf.concat([cur_W, self.cluster_weight]  ,				0    )
                     __lowerCamelCase		=  tf.concat([cur_b, self.cluster_bias]  ,				0    )

                     __lowerCamelCase		=  self._logit(a  ,				a  ,				a  ,				self.out_projs[0]    )
                     __lowerCamelCase		=  tf.nn.log_softmax(a    )
                     out.append(head_logprob[..., : self.cutoffs[0]]    )
                     if target is not None:
                         __lowerCamelCase		=  tf.boolean_mask(a  ,				a    )
                         __lowerCamelCase		=  self._gather_logprob(a  ,				a    )
                 else:
                     __lowerCamelCase		=  self._logit(a  ,				a  ,				a  ,				self.out_projs[i]    )
                     __lowerCamelCase		=  tf.nn.log_softmax(a    )
                     __lowerCamelCase		=  self.cutoffs[0] + i - 1  # No probability for the head cluster
                     __lowerCamelCase		=  head_logprob[..., cluster_prob_idx, None] + tail_logprob
                     out.append(a    )
                     if target is not None:
                         __lowerCamelCase		=  tf.boolean_mask(a  ,				a    )
                         __lowerCamelCase		=  tf.boolean_mask(a  ,				a    )
                         __lowerCamelCase		=  self._gather_logprob(a  ,				a    )
                         cur_logprob += cur_head_logprob[:, self.cutoff_ends[1] + i - 1]
                 if target is not None:
                     loss += tf.scatter_nd(a  ,				-cur_logprob  ,				shape_list(a    )    )
             __lowerCamelCase		=  tf.concat(a  ,				axis=-1    )

         if target is not None:
             if return_mean:
                 __lowerCamelCase		=  tf.reduce_mean(a    )
             # Add the training-time loss value to the layer using `self.add_loss()`.
             self.add_loss(a    )

             # Log the loss as a metric (we could log arbitrary metrics,
             # including different metrics for training and inference.
             self.add_metric(a  ,				name=self.name  ,				aggregation='''mean''' if return_mean else ''''''    )

         return out




'''simple docstring'''
import pprint

import requests

UpperCamelCase__    					=      '''https://zenquotes.io/api'''





def 					a__       (					)    ->	list:
    return requests.get(API_ENDPOINT_URL + '''/today'''						).json()





def 					a__       (					)    ->	list:
    return requests.get(API_ENDPOINT_URL + '''/random'''						).json()


if __name__ == "__main__":
  UpperCamelCase__    					=      random_quotes()
  pprint.pprint(response)
