





import json
import os
import unittest

from transformers.models.roc_bert.tokenization_roc_bert import (
    VOCAB_FILES_NAMES,
    RoCBertBasicTokenizer,
    RoCBertTokenizer,
    RoCBertWordpieceTokenizer,
    _is_control,
    _is_punctuation,
    _is_whitespace,
)
from transformers.testing_utils import require_tokenizers, slow

from ...test_tokenization_common import TokenizerTesterMixin, filter_non_english


@require_tokenizers
class       __lowerCAmelCase					(       _lowercase   ,    unittest.TestCase      ):


	'''simple docstring'''





	_A													=				RoCBertTokenizer
	_A													=				None
	_A													=				False
	_A													=				True
	_A													=				filter_non_english

	def    snake_case__(						self:						int			):
			super().setUp()

			lowercase__					:      Any      =		['[UNK]', '[CLS]', '[SEP]', '[PAD]', '[MASK]', '你', '好', '是', '谁', 'a', 'b', 'c', 'd']
			lowercase__					:      Any      =		{}
			lowercase__					:      Tuple      =		{}
			for i, value in enumerate(lowerCamelCase_			):
					lowercase__					:      Optional[int]      =		i
					lowercase__					:      Union[str, Any]      =		i
			lowercase__					:      List[str]      =		os.path.join(self.tmpdirname,					VOCAB_FILES_NAMES['vocab_file']			)
			lowercase__					:      Union[str, Any]      =		os.path.join(self.tmpdirname,					VOCAB_FILES_NAMES['word_shape_file']			)
			lowercase__					:      str      =		os.path.join(self.tmpdirname,					VOCAB_FILES_NAMES['word_pronunciation_file']			)
			with open(self.vocab_file,					'w',					encoding='utf-8'			) as vocab_writer:
					vocab_writer.write(''.join([x + '\n' for x in vocab_tokens]			)			)
			with open(self.word_shape_file,					'w',					encoding='utf-8'			) as word_shape_writer:
					json.dump(lowerCamelCase_,					lowerCamelCase_,					ensure_ascii=lowerCamelCase_			)
			with open(self.word_pronunciation_file,					'w',					encoding='utf-8'			) as word_pronunciation_writer:
					json.dump(lowerCamelCase_,					lowerCamelCase_,					ensure_ascii=lowerCamelCase_			)

	def    snake_case__(						self:						int			):
			lowercase__					:      Tuple      =		self.tokenizer_class(self.vocab_file,					self.word_shape_file,					self.word_pronunciation_file			)

			lowercase__					:      str      =		tokenizer.tokenize('你好[SEP]你是谁'			)
			self.assertListEqual(lowerCamelCase_,					['你', '好', '[SEP]', '你', '是', '谁']			)
			self.assertListEqual(tokenizer.convert_tokens_to_ids(lowerCamelCase_			),					[5, 6, 2, 5, 7, 8]			)
			self.assertListEqual(tokenizer.convert_tokens_to_shape_ids(lowerCamelCase_			),					[5, 6, 2, 5, 7, 8]			)
			self.assertListEqual(tokenizer.convert_tokens_to_pronunciation_ids(lowerCamelCase_			),					[5, 6, 2, 5, 7, 8]			)

	def    snake_case__(						self:						Any			):
			lowercase__					:      List[Any]      =		RoCBertBasicTokenizer()

			self.assertListEqual(tokenizer.tokenize('ah\u535A\u63A8zz'			),					['ah', '\u535A', '\u63A8', 'zz']			)

	def    snake_case__(						self:						Dict			):
			lowercase__					:      Dict      =		RoCBertBasicTokenizer(do_lower_case=lowerCamelCase_			)

			self.assertListEqual(
			    tokenizer.tokenize(' \tHeLLo!how  \n Are yoU?  '			),					['hello', '!', 'how', 'are', 'you', '?']			)
			self.assertListEqual(tokenizer.tokenize('H\u00E9llo'			),					['hello']			)

	def    snake_case__(						self:						Optional[Any]			):
			lowercase__					:      Union[str, Any]      =		RoCBertBasicTokenizer(do_lower_case=lowerCamelCase_,					strip_accents=lowerCamelCase_			)

			self.assertListEqual(
			    tokenizer.tokenize(' \tHäLLo!how  \n Are yoU?  '			),					['hällo', '!', 'how', 'are', 'you', '?']			)
			self.assertListEqual(tokenizer.tokenize('H\u00E9llo'			),					['h\u00E9llo']			)

	def    snake_case__(						self:						Dict			):
			lowercase__					:      Union[str, Any]      =		RoCBertBasicTokenizer(do_lower_case=lowerCamelCase_,					strip_accents=lowerCamelCase_			)

			self.assertListEqual(
			    tokenizer.tokenize(' \tHäLLo!how  \n Are yoU?  '			),					['hallo', '!', 'how', 'are', 'you', '?']			)
			self.assertListEqual(tokenizer.tokenize('H\u00E9llo'			),					['hello']			)

	def    snake_case__(						self:						str			):
			lowercase__					:      List[str]      =		RoCBertBasicTokenizer(do_lower_case=lowerCamelCase_			)

			self.assertListEqual(
			    tokenizer.tokenize(' \tHäLLo!how  \n Are yoU?  '			),					['hallo', '!', 'how', 'are', 'you', '?']			)
			self.assertListEqual(tokenizer.tokenize('H\u00E9llo'			),					['hello']			)

	def    snake_case__(						self:						Any			):
			lowercase__					:      Any      =		RoCBertBasicTokenizer(do_lower_case=lowerCamelCase_			)

			self.assertListEqual(
			    tokenizer.tokenize(' \tHeLLo!how  \n Are yoU?  '			),					['HeLLo', '!', 'how', 'Are', 'yoU', '?']			)

	def    snake_case__(						self:						Dict			):
			lowercase__					:      Dict      =		RoCBertBasicTokenizer(do_lower_case=lowerCamelCase_,					strip_accents=lowerCamelCase_			)

			self.assertListEqual(
			    tokenizer.tokenize(' \tHäLLo!how  \n Are yoU?  '			),					['HäLLo', '!', 'how', 'Are', 'yoU', '?']			)

	def    snake_case__(						self:						str			):
			lowercase__					:      Optional[Any]      =		RoCBertBasicTokenizer(do_lower_case=lowerCamelCase_,					strip_accents=lowerCamelCase_			)

			self.assertListEqual(
			    tokenizer.tokenize(' \tHäLLo!how  \n Are yoU?  '			),					['HaLLo', '!', 'how', 'Are', 'yoU', '?']			)

	def    snake_case__(						self:						str			):
			lowercase__					:      Dict      =		RoCBertBasicTokenizer(do_lower_case=lowerCamelCase_,					never_split=['[UNK]']			)

			self.assertListEqual(
			    tokenizer.tokenize(' \tHeLLo!how  \n Are yoU? [UNK]'			),					['HeLLo', '!', 'how', 'Are', 'yoU', '?', '[UNK]']			)

	def    snake_case__(						self:						Union[str, Any]			):
			lowercase__					:      Optional[int]      =		['[UNK]', '[CLS]', '[SEP]', 'want', '##want', '##ed', 'wa', 'un', 'runn', '##ing']

			lowercase__					:      str      =		{}
			for i, token in enumerate(lowerCamelCase_			):
					lowercase__					:      Optional[int]      =		i
			lowercase__					:      List[Any]      =		RoCBertWordpieceTokenizer(vocab=lowerCamelCase_,					unk_token='[UNK]'			)

			self.assertListEqual(tokenizer.tokenize(''			),					[]			)

			self.assertListEqual(tokenizer.tokenize('unwanted running'			),					['un', '##want', '##ed', 'runn', '##ing']			)

			self.assertListEqual(tokenizer.tokenize('unwantedX running'			),					['[UNK]', 'runn', '##ing']			)

	def    snake_case__(						self:						Dict			):
			self.assertTrue(_is_whitespace(' '			)			)
			self.assertTrue(_is_whitespace('\t'			)			)
			self.assertTrue(_is_whitespace('\r'			)			)
			self.assertTrue(_is_whitespace('\n'			)			)
			self.assertTrue(_is_whitespace('\u00A0'			)			)

			self.assertFalse(_is_whitespace('A'			)			)
			self.assertFalse(_is_whitespace('-'			)			)

	def    snake_case__(						self:						Union[str, Any]			):
			self.assertTrue(_is_control('\u0005'			)			)

			self.assertFalse(_is_control('A'			)			)
			self.assertFalse(_is_control(' '			)			)
			self.assertFalse(_is_control('\t'			)			)
			self.assertFalse(_is_control('\r'			)			)

	def    snake_case__(						self:						Optional[Any]			):
			self.assertTrue(_is_punctuation('-'			)			)
			self.assertTrue(_is_punctuation('$'			)			)
			self.assertTrue(_is_punctuation('`'			)			)
			self.assertTrue(_is_punctuation('.'			)			)

			self.assertFalse(_is_punctuation('A'			)			)
			self.assertFalse(_is_punctuation(' '			)			)

	def    snake_case__(						self:						Optional[int]			):
			lowercase__					:      str      =		self.get_tokenizer()

			# Example taken from the issue https://github.com/huggingface/tokenizers/issues/340
			self.assertListEqual([tokenizer.tokenize(lowerCamelCase_			) for t in ['Test', '\xad', 'test']],					[['[UNK]'], [], ['[UNK]']]			)

			if self.test_rust_tokenizer:
					lowercase__					:      str      =		self.get_rust_tokenizer()
					self.assertListEqual(
					    [rust_tokenizer.tokenize(lowerCamelCase_			) for t in ['Test', '\xad', 'test']],					[['[UNK]'], [], ['[UNK]']]			)

	def    snake_case__(						self:						Any			):
			for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
					with self.subTest(F"""{tokenizer.__class__.__name__} ({pretrained_name})"""			):
							lowercase__					:      List[str]      =		self.rust_tokenizer_class.from_pretrained(lowerCamelCase_,					**lowerCamelCase_			)

							lowercase__					:      List[str]      =		F"""A, naïve {tokenizer_r.mask_token} AllenNLP sentence."""
							lowercase__					:      int      =		tokenizer_r.encode_plus(
							    lowerCamelCase_,					return_attention_mask=lowerCamelCase_,					return_token_type_ids=lowerCamelCase_,					return_offsets_mapping=lowerCamelCase_,					add_special_tokens=lowerCamelCase_,					)

							lowercase__					:      List[str]      =		tokenizer_r.do_lower_case if hasattr(lowerCamelCase_,					'do_lower_case'			) else False
							lowercase__					:      List[Any]      =		(
							    [
							        ((0, 0), tokenizer_r.cls_token),
							        ((0, 1), 'A'),
							        ((1, 2), ','),
							        ((3, 5), 'na'),
							        ((5, 6), '##ï'),
							        ((6, 8), '##ve'),
							        ((9, 15), tokenizer_r.mask_token),
							        ((16, 21), 'Allen'),
							        ((21, 23), '##NL'),
							        ((23, 24), '##P'),
							        ((25, 33), 'sentence'),
							        ((33, 34), '.'),
							        ((0, 0), tokenizer_r.sep_token),
							    ]
							    if not do_lower_case
							    else [
							        ((0, 0), tokenizer_r.cls_token),
							        ((0, 1), 'a'),
							        ((1, 2), ','),
							        ((3, 8), 'naive'),
							        ((9, 15), tokenizer_r.mask_token),
							        ((16, 21), 'allen'),
							        ((21, 23), '##nl'),
							        ((23, 24), '##p'),
							        ((25, 33), 'sentence'),
							        ((33, 34), '.'),
							        ((0, 0), tokenizer_r.sep_token),
							    ]
							)

							self.assertEqual(
							    [e[1] for e in expected_results],					tokenizer_r.convert_ids_to_tokens(tokens['input_ids']			)			)
							self.assertEqual([e[0] for e in expected_results],					tokens['offset_mapping']			)

	def    snake_case__(						self:						Optional[Any]			):
			lowercase__					:      int      =		['的', '人', '有']
			lowercase__					:      Dict      =		''.join(lowerCamelCase_			)
			for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
					with self.subTest(F"""{tokenizer.__class__.__name__} ({pretrained_name})"""			):
							lowercase__					:      Union[str, Any]      =		True
							lowercase__					:      str      =		self.tokenizer_class.from_pretrained(lowerCamelCase_,					**lowerCamelCase_			)
							lowercase__					:      Union[str, Any]      =		self.rust_tokenizer_class.from_pretrained(lowerCamelCase_,					**lowerCamelCase_			)

							lowercase__					:      Tuple      =		tokenizer_p.encode(lowerCamelCase_,					add_special_tokens=lowerCamelCase_			)
							lowercase__					:      List[str]      =		tokenizer_r.encode(lowerCamelCase_,					add_special_tokens=lowerCamelCase_			)

							lowercase__					:      Dict      =		tokenizer_r.convert_ids_to_tokens(lowerCamelCase_			)
							lowercase__					:      Optional[Any]      =		tokenizer_p.convert_ids_to_tokens(lowerCamelCase_			)

							# it is expected that each Chinese character is not preceded by "##"
							self.assertListEqual(lowerCamelCase_,					lowerCamelCase_			)
							self.assertListEqual(lowerCamelCase_,					lowerCamelCase_			)

							lowercase__					:      Optional[Any]      =		False
							lowercase__					:      Optional[Any]      =		self.rust_tokenizer_class.from_pretrained(lowerCamelCase_,					**lowerCamelCase_			)
							lowercase__					:      Tuple      =		self.tokenizer_class.from_pretrained(lowerCamelCase_,					**lowerCamelCase_			)

							lowercase__					:      int      =		tokenizer_r.encode(lowerCamelCase_,					add_special_tokens=lowerCamelCase_			)
							lowercase__					:      Optional[int]      =		tokenizer_p.encode(lowerCamelCase_,					add_special_tokens=lowerCamelCase_			)

							lowercase__					:      Optional[int]      =		tokenizer_r.convert_ids_to_tokens(lowerCamelCase_			)
							lowercase__					:      int      =		tokenizer_p.convert_ids_to_tokens(lowerCamelCase_			)

							# it is expected that only the first Chinese character is not preceded by "##".
							lowercase__					:      List[Any]      =		[
							    F"""##{token}""" if idx != 0 else token for idx, token in enumerate(lowerCamelCase_			)
							]
							self.assertListEqual(lowerCamelCase_,					lowerCamelCase_			)
							self.assertListEqual(lowerCamelCase_,					lowerCamelCase_			)

	@slow
	def    snake_case__(						self:						int			):
			lowercase__					:      Any      =		self.tokenizer_class(self.vocab_file,					self.word_shape_file,					self.word_pronunciation_file			)

			lowercase__					:      str      =		tokenizer.encode('你好',					add_special_tokens=lowerCamelCase_			)
			lowercase__					:      str      =		tokenizer.encode('你是谁',					add_special_tokens=lowerCamelCase_			)

			lowercase__					:      Optional[int]      =		tokenizer.build_inputs_with_special_tokens(lowerCamelCase_			)
			lowercase__					:      int      =		tokenizer.build_inputs_with_special_tokens(lowerCamelCase_,					lowerCamelCase_			)

			assert encoded_sentence == [1] + text + [2]
			assert encoded_pair == [1] + text + [2] + text_a + [2]





	def    snake_case__(						self:						Optional[int]			):
			lowercase__					:      Tuple      =		self.get_tokenizers(do_lower_case=lowerCamelCase_			)
			for tokenizer in tokenizers:
					with self.subTest(F"""{tokenizer.__class__.__name__}"""			):
							lowercase__					:      Dict      =		'你好，你是谁'
							lowercase__					:      Tuple      =		tokenizer.tokenize(lowerCamelCase_			)
							lowercase__					:      List[Any]      =		tokenizer.convert_tokens_to_ids(lowerCamelCase_			)
							lowercase__					:      Dict      =		tokenizer.convert_tokens_to_shape_ids(lowerCamelCase_			)
							lowercase__					:      int      =		tokenizer.convert_tokens_to_pronunciation_ids(lowerCamelCase_			)
							lowercase__					:      Dict      =		tokenizer.prepare_for_model(
							    lowerCamelCase_,					lowerCamelCase_,					lowerCamelCase_,					add_special_tokens=lowerCamelCase_			)

							lowercase__					:      Optional[Any]      =		tokenizer.encode_plus(lowerCamelCase_,					add_special_tokens=lowerCamelCase_			)

							self.assertEqual(lowerCamelCase_,					lowerCamelCase_			)







import torch
from torch import nn
class    __UpperCamelCase			(       nn.Module				):

 """simple docstring"""



 def __init__(	self		,				SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE=1		,				SCREAMING_SNAKE_CASE=False      ) ->			Tuple:
  super().__init__()

  a__												= n_token
  a__												= d_embed
  a__												= d_proj

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

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

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

  a__												= nn.ModuleList()
  a__												= 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(SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE      )      )      )
    else:
     self.out_projs.append(SCREAMING_SNAKE_CASE      )

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

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

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

  a__												= keep_order

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

  return logit

 def 						_UpperCAmelCase       (	self		,				SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE=None		,				SCREAMING_SNAKE_CASE=False      ) ->			Optional[int]:

  if labels is not None:
   # Shift so that tokens < n predict n
   a__												= hidden[..., :-1, :].contiguous()
   a__												= labels[..., 1:].contiguous()
   a__												= hidden.view(-1		,				hidden.size(-1      )      )
   a__												= 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:
   a__												= hidden.view(-1		,				hidden.size(-1      )      )

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

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

    weights.append(SCREAMING_SNAKE_CASE      )
    biases.append(SCREAMING_SNAKE_CASE      )

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

   a__												= self._compute_logit(SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE      )
   a__												= nn.functional.log_softmax(SCREAMING_SNAKE_CASE		,				dim=1      )

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

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

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

     if indices_i.numel() == 0:
      continue

     a__												= labels.index_select(0		,				SCREAMING_SNAKE_CASE      ) - l_idx
     a__												= head_logprob.index_select(0		,				SCREAMING_SNAKE_CASE      )
     a__												= hidden.index_select(0		,				SCREAMING_SNAKE_CASE      )
    else:
     a__												= hidden

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

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

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

  return out



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

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

    weights.append(SCREAMING_SNAKE_CASE      )
    biases.append(SCREAMING_SNAKE_CASE      )

   a__							,			a__							,			a__												= weights[0], biases[0], self.out_projs[0]
   a__												= self._compute_logit(SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE      )

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

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

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

     a__												= self._compute_logit(SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE      )
     a__												= nn.functional.log_softmax(SCREAMING_SNAKE_CASE		,				dim=1      )

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

   return out





