import torch
from torch import nn




class    _UpperCamelCase      (						nn.Module ):


			"""simple docstring"""






			def __init__(   self      ,   lowerCAmelCase__      ,   lowerCAmelCase__      ,   lowerCAmelCase__      ,   lowerCAmelCase__      ,   lowerCAmelCase__=1      ,   lowerCAmelCase__=False						)     ->					List[str]:

							'''simple docstring'''


							super().__init__()

							__lowercase 			=							n_token
							__lowercase 			=							d_embed
							__lowercase 			=							d_proj

							__lowercase 			=							cutoffs + [n_token]
							__lowercase 			=							[0] + self.cutoffs
							__lowercase 			=							div_val

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

							if self.n_clusters > 0:
											__lowercase 			=							nn.Parameter(torch.zeros(self.n_clusters      ,   self.d_embed						)						)
											__lowercase 			=							nn.Parameter(torch.zeros(self.n_clusters						)						)

							__lowercase 			=							nn.ModuleList()
							__lowercase 			=							nn.ParameterList()

							if div_val == 1:
											for i in range(len(self.cutoffs						)						):
															if d_proj != d_embed:
																			self.out_projs.append(nn.Parameter(torch.FloatTensor(lowerCAmelCase__      ,   lowerCAmelCase__						)						)						)
															else:
																			self.out_projs.append(lowerCAmelCase__						)

											self.out_layers.append(nn.Linear(lowerCAmelCase__      ,   lowerCAmelCase__						)						)
							else:
											for i in range(len(self.cutoffs						)						):
															__lowercase			,     __lowercase 			=							self.cutoff_ends[i], self.cutoff_ends[i + 1]
															__lowercase 			=							d_embed // (div_val**i)

															self.out_projs.append(nn.Parameter(torch.FloatTensor(lowerCAmelCase__      ,   lowerCAmelCase__						)						)						)

															self.out_layers.append(nn.Linear(lowerCAmelCase__      ,   r_idx - l_idx						)						)

							__lowercase 			=							keep_order





			def        _SCREAMING_SNAKE_CASE			(   self      ,   lowerCAmelCase__      ,   lowerCAmelCase__      ,   lowerCAmelCase__      ,   lowerCAmelCase__						)     ->					str:

							'''simple docstring'''


							if proj is None:
											__lowercase 			=							nn.functional.linear(lowerCAmelCase__      ,   lowerCAmelCase__      ,   bias=lowerCAmelCase__						)
							else:
											# if CUDA_MAJOR <= 9 and CUDA_MINOR <= 1:
											__lowercase 			=							nn.functional.linear(lowerCAmelCase__      ,   proj.t().contiguous()						)
											__lowercase 			=							nn.functional.linear(lowerCAmelCase__      ,   lowerCAmelCase__      ,   bias=lowerCAmelCase__						)
											# else:
											#     logit = torch.einsum('bd,de,ev->bv', (hidden, proj, weight.t()))
											#     if bias is not None:
											#         logit = logit + bias

							return logit





			def        _SCREAMING_SNAKE_CASE			(   self      ,   lowerCAmelCase__      ,   lowerCAmelCase__=None      ,   lowerCAmelCase__=False						)     ->					Optional[int]:

							'''simple docstring'''


							if labels is not None:
											# Shift so that tokens < n predict n
											__lowercase 			=							hidden[..., :-1, :].contiguous()
											__lowercase 			=							labels[..., 1:].contiguous()
											__lowercase 			=							hidden.view(-1      ,   hidden.size(-1						)						)
											__lowercase 			=							labels.view(-1						)
											if hidden.size(0						) != labels.size(0						):
															raise RuntimeError('''Input and labels should have the same size in the batch dimension.'''						)
							else:
											__lowercase 			=							hidden.view(-1      ,   hidden.size(-1						)						)

							if self.n_clusters == 0:
											__lowercase 			=							self._compute_logit(lowerCAmelCase__      ,   self.out_layers[0].weight      ,   self.out_layers[0].bias      ,   self.out_projs[0]						)
											if labels is not None:
															__lowercase 			=							labels != -1_00
															__lowercase 			=							torch.zeros_like(lowerCAmelCase__      ,   dtype=hidden.dtype      ,   device=hidden.device						)
															__lowercase 			=							(
															    -nn.functional.log_softmax(lowerCAmelCase__      ,   dim=-1						)[mask].gather(1      ,   labels[mask].unsqueeze(1						)						).squeeze(1						)
															)
											else:
															__lowercase 			=							nn.functional.log_softmax(lowerCAmelCase__      ,   dim=-1						)
							else:
											# construct weights and biases
											__lowercase			,     __lowercase 			=							[], []
											for i in range(len(self.cutoffs						)						):
															if self.div_val == 1:
																			__lowercase			,     __lowercase 			=							self.cutoff_ends[i], self.cutoff_ends[i + 1]
																			__lowercase 			=							self.out_layers[0].weight[l_idx:r_idx]
																			__lowercase 			=							self.out_layers[0].bias[l_idx:r_idx]
															else:
																			__lowercase 			=							self.out_layers[i].weight
																			__lowercase 			=							self.out_layers[i].bias

															if i == 0:
																			__lowercase 			=							torch.cat([weight_i, self.cluster_weight]      ,   dim=0						)
																			__lowercase 			=							torch.cat([bias_i, self.cluster_bias]      ,   dim=0						)

															weights.append(lowerCAmelCase__						)
															biases.append(lowerCAmelCase__						)

											__lowercase			,     __lowercase			,     __lowercase 			=							weights[0], biases[0], self.out_projs[0]

											__lowercase 			=							self._compute_logit(lowerCAmelCase__      ,   lowerCAmelCase__      ,   lowerCAmelCase__      ,   lowerCAmelCase__						)
											__lowercase 			=							nn.functional.log_softmax(lowerCAmelCase__      ,   dim=1						)

											if labels is None:
															__lowercase 			=							hidden.new_empty((head_logit.size(0						), self.n_token)						)
											else:
															__lowercase 			=							torch.zeros_like(lowerCAmelCase__      ,   dtype=hidden.dtype      ,   device=hidden.device						)

											__lowercase 			=							0
											__lowercase 			=							[0] + self.cutoffs
											for i in range(len(lowerCAmelCase__						) - 1						):
															__lowercase			,     __lowercase 			=							cutoff_values[i], cutoff_values[i + 1]

															if labels is not None:
																			__lowercase 			=							(labels >= l_idx) & (labels < r_idx)
																			__lowercase 			=							mask_i.nonzero().squeeze()

																			if indices_i.numel() == 0:
																							continue

																			__lowercase 			=							labels.index_select(0      ,   lowerCAmelCase__						) - l_idx
																			__lowercase 			=							head_logprob.index_select(0      ,   lowerCAmelCase__						)
																			__lowercase 			=							hidden.index_select(0      ,   lowerCAmelCase__						)
															else:
																			__lowercase 			=							hidden

															if i == 0:
																			if labels is not None:
																							__lowercase 			=							head_logprob_i.gather(1      ,   target_i[:, None]						).squeeze(1						)
																			else:
																							__lowercase 			=							head_logprob[:, : self.cutoffs[0]]
															else:
																			__lowercase			,     __lowercase			,     __lowercase 			=							weights[i], biases[i], self.out_projs[i]

																			__lowercase 			=							self._compute_logit(lowerCAmelCase__      ,   lowerCAmelCase__      ,   lowerCAmelCase__      ,   lowerCAmelCase__						)
																			__lowercase 			=							nn.functional.log_softmax(lowerCAmelCase__      ,   dim=1						)
																			__lowercase 			=							self.cutoffs[0] + i - 1  # No probability for the head cluster
																			if labels is not None:
																							__lowercase 			=							head_logprob_i[:, cluster_prob_idx] + tail_logprob_i.gather(
																							    1      ,   target_i[:, None]						).squeeze(1						)
																			else:
																							__lowercase 			=							head_logprob[:, cluster_prob_idx, None] + tail_logprob_i
																							__lowercase 			=							logprob_i

															if labels is not None:
																			if (hasattr(self      ,   '''keep_order'''						) and self.keep_order) or keep_order:
																							out.index_copy_(0      ,   lowerCAmelCase__      ,   -logprob_i						)
																			else:
																							out[offset : offset + logprob_i.size(0						)].copy_(-logprob_i						)
																			offset += logprob_i.size(0						)

							return out





			def        _SCREAMING_SNAKE_CASE			(   self      ,   lowerCAmelCase__						)     ->					List[str]:

							'''simple docstring'''


							if self.n_clusters == 0:
											__lowercase 			=							self._compute_logit(lowerCAmelCase__      ,   self.out_layers[0].weight      ,   self.out_layers[0].bias      ,   self.out_projs[0]						)
											return nn.functional.log_softmax(lowerCAmelCase__      ,   dim=-1						)
							else:
											# construct weights and biases
											__lowercase			,     __lowercase 			=							[], []
											for i in range(len(self.cutoffs						)						):
															if self.div_val == 1:
																			__lowercase			,     __lowercase 			=							self.cutoff_ends[i], self.cutoff_ends[i + 1]
																			__lowercase 			=							self.out_layers[0].weight[l_idx:r_idx]
																			__lowercase 			=							self.out_layers[0].bias[l_idx:r_idx]
															else:
																			__lowercase 			=							self.out_layers[i].weight
																			__lowercase 			=							self.out_layers[i].bias

															if i == 0:
																			__lowercase 			=							torch.cat([weight_i, self.cluster_weight]      ,   dim=0						)
																			__lowercase 			=							torch.cat([bias_i, self.cluster_bias]      ,   dim=0						)

															weights.append(lowerCAmelCase__						)
															biases.append(lowerCAmelCase__						)

											__lowercase			,     __lowercase			,     __lowercase 			=							weights[0], biases[0], self.out_projs[0]
											__lowercase 			=							self._compute_logit(lowerCAmelCase__      ,   lowerCAmelCase__      ,   lowerCAmelCase__      ,   lowerCAmelCase__						)

											__lowercase 			=							hidden.new_empty((head_logit.size(0						), self.n_token)						)
											__lowercase 			=							nn.functional.log_softmax(lowerCAmelCase__      ,   dim=1						)

											__lowercase 			=							[0] + self.cutoffs
											for i in range(len(lowerCAmelCase__						) - 1						):
															__lowercase			,     __lowercase 			=							cutoff_values[i], cutoff_values[i + 1]

															if i == 0:
																			__lowercase 			=							head_logprob[:, : self.cutoffs[0]]
															else:
																			__lowercase			,     __lowercase			,     __lowercase 			=							weights[i], biases[i], self.out_projs[i]

																			__lowercase 			=							self._compute_logit(lowerCAmelCase__      ,   lowerCAmelCase__      ,   lowerCAmelCase__      ,   lowerCAmelCase__						)
																			__lowercase 			=							nn.functional.log_softmax(lowerCAmelCase__      ,   dim=1						)

																			__lowercase 			=							head_logprob[:, -i] + tail_logprob_i
																			__lowercase 			=							logprob_i

											return out
import requests





def 				UpperCAmelCase						(    lowercase							,			lowercase							):







				"""simple docstring"""



				__lowercase 			=							{'''Content-Type''': '''application/json'''}
				__lowercase 			=							requests.post(lowercase							,			json={'''text''': message_body}							,			headers=lowercase							)
				if response.status_code != 200:
								__lowercase 			=							(
								    '''Request to slack returned an error '''
								    F"{response.status_code}, the response is:\n{response.text}"
								)
								raise ValueError(lowercase							)


if __name__ == "__main__":
		# Set the slack url to the one provided by Slack when you create the webhook at
		# https://my.slack.com/services/new/incoming-webhook/
		send_slack_message("""<YOUR MESSAGE BODY>""", """<SLACK CHANNEL URL>""")