
import json
import os
from typing import Optional, Tuple

import regex as re

from ...tokenization_utils import PreTrainedTokenizer
from ...utils import logging


SCREAMING_SNAKE_CASE							:int							 =				logging.get_logger(__name__)

SCREAMING_SNAKE_CASE							:Union[str, Any]							 =				{
    'vocab_file': 'vocab.json',
    'merges_file': 'merges.txt',
}

SCREAMING_SNAKE_CASE							:List[str]							 =				{
    'vocab_file': {'ctrl': 'https://raw.githubusercontent.com/salesforce/ctrl/master/ctrl-vocab.json'},
    'merges_file': {'ctrl': 'https://raw.githubusercontent.com/salesforce/ctrl/master/ctrl-merges.txt'},
}

SCREAMING_SNAKE_CASE							:List[Any]							 =				{
    'ctrl': 256,
}

SCREAMING_SNAKE_CASE							:Optional[Any]							 =				{
    'Pregnancy': 16_8629,
    'Christianity': 7675,
    'Explain': 10_6423,
    'Fitness': 6_3440,
    'Saving': 6_3163,
    'Ask': 2_7171,
    'Ass': 9_5985,
    'Joke': 16_3509,
    'Questions': 4_5622,
    'Thoughts': 4_9605,
    'Retail': 5_2342,
    'Feminism': 16_4338,
    'Writing': 1_1992,
    'Atheism': 19_2263,
    'Netflix': 4_8616,
    'Computing': 3_9639,
    'Opinion': 4_3213,
    'Alone': 4_4967,
    'Funny': 5_8917,
    'Gaming': 4_0358,
    'Human': 4088,
    'India': 1331,
    'Joker': 7_7138,
    'Diet': 3_6206,
    'Legal': 1_1859,
    'Norman': 4939,
    'Tip': 7_2689,
    'Weight': 5_2343,
    'Movies': 4_6273,
    'Running': 2_3425,
    'Science': 2090,
    'Horror': 3_7793,
    'Confession': 6_0572,
    'Finance': 1_2250,
    'Politics': 1_6360,
    'Scary': 19_1985,
    'Support': 1_2654,
    'Technologies': 3_2516,
    'Teenage': 6_6160,
    'Event': 3_2769,
    'Learned': 6_7460,
    'Notion': 18_2770,
    'Wikipedia': 3_7583,
    'Books': 6665,
    'Extract': 7_6050,
    'Confessions': 10_2701,
    'Conspiracy': 7_5932,
    'Links': 6_3674,
    'Narcissus': 15_0425,
    'Relationship': 5_4766,
    'Relationships': 13_4796,
    'Reviews': 4_1671,
    'News': 4256,
    'Translation': 2_6820,
    'multilingual': 12_8406,
}


def 						UpperCAmelCase			(	a_						)		->	Union[str, Any]:







				"""simple docstring"""



				__A   			= set()
				__A   			= word[0]
				for char in word[1:]:
								pairs.add((prev_char, char)						)
								__A   			= char

				__A   			= set(a_						)
				return pairs





class 							UpperCAmelCase      (  __SCREAMING_SNAKE_CASE  ):




	'''simple docstring'''





	snake_case_					    =     VOCAB_FILES_NAMES
	snake_case_					    =     PRETRAINED_VOCAB_FILES_MAP
	snake_case_					    =     PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
	snake_case_					    =     CONTROL_CODES






	def __init__(       self					: Dict							,A					: List[Any]							,A					: Tuple							,A					: Optional[int]="<unk>"							,**A					: str ):
					super().__init__(unk_token=A							,**A )

					with open(A							,encoding="utf-8" ) as vocab_handle:
									__A   			= json.load(A )
					__A   			= {v: k for k, v in self.encoder.items()}
					with open(A							,encoding="utf-8" ) as merges_handle:
									__A   			= merges_handle.read().split("\n" )[1:-1]
					__A   			= [tuple(merge.split() ) for merge in merges]
					__A   			= dict(zip(A							,range(len(A ) ) ) )
					__A   			= {}






	@property
	def 				UpperCamelCase_  (       self					: int ):
					return len(self.encoder )






	def 				UpperCamelCase_  (       self					: Optional[Any] ):
					return dict(self.encoder							,**self.added_tokens_encoder )






	def 				UpperCamelCase_  (       self					: Any							,A					: Optional[Any] ):
					if token in self.cache:
									return self.cache[token]
					__A   			= tuple(A )
					__A   			= tuple(list(word[:-1] ) + [word[-1] + "</w>"] )
					__A   			= get_pairs(A )

					if not pairs:
									return token

					while True:
									__A   			= min(A							,key=lambda A : self.bpe_ranks.get(A							,float("inf" ) ) )
									if bigram not in self.bpe_ranks:
													break
									__A			,							__A   			= bigram
									__A   			= []
									__A   			= 0
									while i < len(A ):
													try:
																	__A   			= word.index(A							,A )
													except ValueError:
																	new_word.extend(word[i:] )
																	break
													else:
																	new_word.extend(word[i:j] )
																	__A   			= j

													if word[i] == first and i < len(A ) - 1 and word[i + 1] == second:
																	new_word.append(first + second )
																	i += 2
													else:
																	new_word.append(word[i] )
																	i += 1
									__A   			= tuple(A )
									__A   			= new_word
									if len(A ) == 1:
													break
									else:
													__A   			= get_pairs(A )
					__A   			= "@@ ".join(A )
					__A   			= word[:-4]
					__A   			= word
					return word






	def 				UpperCamelCase_  (       self					: Tuple							,A					: Optional[Any] ):
					__A   			= []

					__A   			= re.findall(R"\S+\n?"							,A )

					for token in words:
									split_tokens.extend(list(self.bpe(A ).split(" " ) ) )
					return split_tokens






	def 				UpperCamelCase_  (       self					: int							,A					: Optional[Any] ):
					return self.encoder.get(A							,self.encoder.get(self.unk_token ) )






	def 				UpperCamelCase_  (       self					: List[str]							,A					: Dict ):
					return self.decoder.get(A							,self.unk_token )






	def 				UpperCamelCase_  (       self					: Optional[int]							,A					: Union[str, Any] ):
					__A   			= " ".join(A ).replace("@@ "							,"" ).strip()
					return out_string







	def 				UpperCamelCase_  (       self					: Dict							,A					: str							,A					: Optional[str] = None ):
					if not os.path.isdir(A ):
									logger.error(f'''Vocabulary path ({save_directory}) should be a directory''' )
									return
					__A   			= os.path.join(
					    A							,(filename_prefix + "-" if filename_prefix else "") + VOCAB_FILES_NAMES["vocab_file"] )
					__A   			= os.path.join(
					    A							,(filename_prefix + "-" if filename_prefix else "") + VOCAB_FILES_NAMES["merges_file"] )

					with open(A							,"w"							,encoding="utf-8" ) as f:
									f.write(json.dumps(self.encoder							,indent=2							,sort_keys=A							,ensure_ascii=A ) + "\n" )

					__A   			= 0
					with open(A							,"w"							,encoding="utf-8" ) as writer:
									writer.write("#version: 0.2\n" )
									for bpe_tokens, token_index in sorted(self.bpe_ranks.items()							,key=lambda A : kv[1] ):
													if index != token_index:
																	logger.warning(
																	    f'''Saving vocabulary to {merge_file}: BPE merge indices are not consecutive.'''
																	    " Please check that the tokenizer is not corrupted!" )
																	__A   			= token_index
													writer.write(" ".join(A ) + "\n" )
													index += 1

					return vocab_file, merge_file

	# def decode(self, token_ids, skip_special_tokens=False, clean_up_tokenization_spaces=True):
	#     filtered_tokens = ' '.join(self.convert_ids_to_tokens(token_ids, skip_special_tokens=skip_special_tokens))
	#     tokens_generated_so_far = re.sub('(@@ )', '', string=filtered_tokens)
	#     tokens_generated_so_far = re.sub('(@@ ?$)', '', string=tokens_generated_so_far)
	#     return ''.join(tokens_generated_so_far)


"""simple docstring"""




from __future__ import annotations

import unittest

import numpy as np

from transformers import LayoutLMConfig, is_tf_available
from transformers.testing_utils import require_tf, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
   import tensorflow as tf

   from transformers.models.layoutlm.modeling_tf_layoutlm import (
       TF_LAYOUTLM_PRETRAINED_MODEL_ARCHIVE_LIST,
       TFLayoutLMForMaskedLM,
       TFLayoutLMForQuestionAnswering,
       TFLayoutLMForSequenceClassification,
       TFLayoutLMForTokenClassification,
       TFLayoutLMModel,
   )

class 		a__						:
   def __init__(			self	,    _a	,    _a=13	,    _a=7	,    _a=True	,    _a=True	,    _a=True	,    _a=True	,    _a=99	,    _a=32	,    _a=2	,    _a=4	,    _a=37	,    _a="gelu"	,    _a=0.1	,    _a=0.1	,    _a=512	,    _a=16	,    _a=2	,    _a=0.0_2	,    _a=3	,    _a=4	,    _a=None	,    _a=1_000	,    ):
          lowercase    :				Optional[Any]       		=							parent
          lowercase    :				Dict       		=							batch_size
          lowercase    :				str       		=							seq_length
          lowercase    :				List[Any]       		=							is_training
          lowercase    :				Dict       		=							use_input_mask
          lowercase    :				str       		=							use_token_type_ids
          lowercase    :				int       		=							use_labels
          lowercase    :				Union[str, Any]       		=							vocab_size
          lowercase    :				Dict       		=							hidden_size
          lowercase    :				List[str]       		=							num_hidden_layers
          lowercase    :				Optional[int]       		=							num_attention_heads
          lowercase    :				Tuple       		=							intermediate_size
          lowercase    :				List[str]       		=							hidden_act
          lowercase    :				int       		=							hidden_dropout_prob
          lowercase    :				Any       		=							attention_probs_dropout_prob
          lowercase    :				Dict       		=							max_position_embeddings
          lowercase    :				Optional[int]       		=							type_vocab_size
          lowercase    :				Tuple       		=							type_sequence_label_size
          lowercase    :				Optional[int]       		=							initializer_range
          lowercase    :				Dict       		=							num_labels
          lowercase    :				Optional[int]       		=							num_choices
          lowercase    :				List[Any]       		=							scope
          lowercase    :				Dict       		=							range_bbox
   def 			__magic_name__			(			self				):
          lowercase    :				Optional[int]       		=							ids_tensor([self.batch_size, self.seq_length]	,    self.vocab_size				)

          # convert bbox to numpy since TF does not support item assignment
          lowercase    :				int       		=							ids_tensor([self.batch_size, self.seq_length, 4]	,    self.range_bbox				).numpy()
          # Ensure that bbox is legal
          for i in range(bbox.shape[0]				):
                 for j in range(bbox.shape[1]				):
                        if bbox[i, j, 3] < bbox[i, j, 1]:
                               lowercase    :				Any       		=							bbox[i, j, 3]
                               lowercase    :				Optional[Any]       		=							bbox[i, j, 1]
                               lowercase    :				Optional[Any]       		=							t
                        if bbox[i, j, 2] < bbox[i, j, 0]:
                               lowercase    :				Dict       		=							bbox[i, j, 2]
                               lowercase    :				List[str]       		=							bbox[i, j, 0]
                               lowercase    :				List[Any]       		=							t
          lowercase    :				Any       		=							tf.convert_to_tensor(_a				)

          lowercase    :				Dict       		=							None
          if self.use_input_mask:
                 lowercase    :				List[str]       		=							random_attention_mask([self.batch_size, self.seq_length]				)

          lowercase    :				Optional[int]       		=							None
          if self.use_token_type_ids:
                 lowercase    :				Dict       		=							ids_tensor([self.batch_size, self.seq_length]	,    self.type_vocab_size				)

          lowercase    :				Optional[int]       		=							None
          lowercase    :				List[Any]       		=							None
          lowercase    :				Tuple       		=							None
          if self.use_labels:
                 lowercase    :				Optional[int]       		=							ids_tensor([self.batch_size]	,    self.type_sequence_label_size				)
                 lowercase    :				List[str]       		=							ids_tensor([self.batch_size, self.seq_length]	,    self.num_labels				)
                 lowercase    :				Union[str, Any]       		=							ids_tensor([self.batch_size]	,    self.num_choices				)

          lowercase    :				int       		=							LayoutLMConfig(
              vocab_size=self.vocab_size	,    hidden_size=self.hidden_size	,    num_hidden_layers=self.num_hidden_layers	,    num_attention_heads=self.num_attention_heads	,    intermediate_size=self.intermediate_size	,    hidden_act=self.hidden_act	,    hidden_dropout_prob=self.hidden_dropout_prob	,    attention_probs_dropout_prob=self.attention_probs_dropout_prob	,    max_position_embeddings=self.max_position_embeddings	,    type_vocab_size=self.type_vocab_size	,    initializer_range=self.initializer_range	,    )

          return config, input_ids, bbox, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels
   def 			__magic_name__			(			self	,    _a	,    _a	,    _a	,    _a	,    _a	,    _a	,    _a	,    _a				):
          lowercase    :				str       		=							TFLayoutLMModel(config=_a				)

          lowercase    :				Optional[Any]       		=							model(_a	,    _a	,    attention_mask=_a	,    token_type_ids=_a				)
          lowercase    :				Dict       		=							model(_a	,    _a	,    token_type_ids=_a				)
          lowercase    :				List[str]       		=							model(_a	,    _a				)
          self.parent.assertEqual(result.last_hidden_state.shape	,    (self.batch_size, self.seq_length, self.hidden_size)				)
          self.parent.assertEqual(result.pooler_output.shape	,    (self.batch_size, self.hidden_size)				)
   def 			__magic_name__			(			self	,    _a	,    _a	,    _a	,    _a	,    _a	,    _a	,    _a	,    _a				):
          lowercase    :				List[Any]       		=							TFLayoutLMForMaskedLM(config=_a				)

          lowercase    :				Union[str, Any]       		=							model(_a	,    _a	,    attention_mask=_a	,    token_type_ids=_a	,    labels=_a				)
          self.parent.assertEqual(result.logits.shape	,    (self.batch_size, self.seq_length, self.vocab_size)				)
   def 			__magic_name__			(			self	,    _a	,    _a	,    _a	,    _a	,    _a	,    _a	,    _a	,    _a				):
          lowercase    :				Dict       		=							self.num_labels
          lowercase    :				Any       		=							TFLayoutLMForSequenceClassification(config=_a				)

          lowercase    :				List[Any]       		=							model(_a	,    _a	,    attention_mask=_a	,    token_type_ids=_a				)
          self.parent.assertEqual(result.logits.shape	,    (self.batch_size, self.num_labels)				)
   def 			__magic_name__			(			self	,    _a	,    _a	,    _a	,    _a	,    _a	,    _a	,    _a	,    _a				):
          lowercase    :				int       		=							self.num_labels
          lowercase    :				Dict       		=							TFLayoutLMForTokenClassification(config=_a				)

          lowercase    :				Tuple       		=							model(_a	,    _a	,    attention_mask=_a	,    token_type_ids=_a	,    labels=_a				)
          self.parent.assertEqual(result.logits.shape	,    (self.batch_size, self.seq_length, self.num_labels)				)
   def 			__magic_name__			(			self	,    _a	,    _a	,    _a	,    _a	,    _a	,    _a	,    _a	,    _a				):
          lowercase    :				int       		=							TFLayoutLMForQuestionAnswering(config=_a				)

          lowercase    :				Any       		=							model(_a	,    _a	,    attention_mask=_a	,    token_type_ids=_a				)
          self.parent.assertEqual(result.start_logits.shape	,    (self.batch_size, self.seq_length)				)
          self.parent.assertEqual(result.end_logits.shape	,    (self.batch_size, self.seq_length)				)

   def 			__magic_name__			(			self				):
          lowercase    :				Optional[int]       		=							self.prepare_config_and_inputs()
          (
              (
              lowercase
          )		,    (
              lowercase
          )		,    (
              lowercase
          )		,    (
              lowercase
          )		,    (
              lowercase
          )		,    (
              lowercase
          )		,    (
              lowercase
          )		,    (
              lowercase
          )		,    
          )    :				List[Any]       		=							config_and_inputs
          lowercase    :				int       		=							{
              "input_ids": input_ids,
              "bbox": bbox,
              "token_type_ids": token_type_ids,
              "attention_mask": input_mask,
          }
          return config, inputs_dict


@require_tf
class 		a__						(      a_,			a_,			unittest.TestCase						):
   __lowerCAmelCase            =				(
       (
           TFLayoutLMModel,
           TFLayoutLMForMaskedLM,
           TFLayoutLMForTokenClassification,
           TFLayoutLMForSequenceClassification,
           TFLayoutLMForQuestionAnswering,
       )
       if is_tf_available()
       else ()
   )
   __lowerCAmelCase            =				(
       {
           """feature-extraction""": TFLayoutLMModel,
           """fill-mask""": TFLayoutLMForMaskedLM,
           """text-classification""": TFLayoutLMForSequenceClassification,
           """token-classification""": TFLayoutLMForTokenClassification,
           """zero-shot""": TFLayoutLMForSequenceClassification,
       }
       if is_tf_available()
       else {}
   )
   __lowerCAmelCase            =				False
   __lowerCAmelCase            =				True
   __lowerCAmelCase            =				10
   def 			__magic_name__			(			self				):
          lowercase    :				List[Any]       		=							TFLayoutLMModelTester(self				)
          lowercase    :				List[Any]       		=							ConfigTester(self	,    config_class=_a	,    hidden_size=37				)
   def 			__magic_name__			(			self				):
          self.config_tester.run_common_tests()
   def 			__magic_name__			(			self				):
          lowercase    :				Tuple       		=							self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_model(*_a				)
   def 			__magic_name__			(			self				):
          lowercase    :				Dict       		=							self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_for_masked_lm(*_a				)
   def 			__magic_name__			(			self				):
          lowercase    :				List[Any]       		=							self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_for_sequence_classification(*_a				)
   def 			__magic_name__			(			self				):
          lowercase    :				Dict       		=							self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_for_token_classification(*_a				)
   def 			__magic_name__			(			self				):
          lowercase    :				str       		=							self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_for_question_answering(*_a				)
   @slow
   def 			__magic_name__			(			self				):
          for model_name in TF_LAYOUTLM_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                 lowercase    :				List[str]       		=							TFLayoutLMModel.from_pretrained(_a				)
                 self.assertIsNotNone(_a				)

   @unittest.skip("Onnx compliancy broke with TF 2.10"				)
   def 			__magic_name__			(			self				):
          pass


def   __magic_name__	(      ) ->				Optional[int]:
       # Here we prepare a batch of 2 sequences to test a LayoutLM forward pass on:
       # fmt: off
       lowercase    :				str       		=							tf.convert_to_tensor([[101,1019,1014,1016,1037,1_2849,4747,1004,1_4246,2278,5439,4524,5002,2930,2193,2930,4341,3208,1005,1055,2171,2848,1_1300,3531,102],[101,4070,4034,7020,1024,3058,1015,1013,2861,1013,6070,1_9274,2772,6205,2_7814,1_6147,1_6147,4343,2047,1_0283,1_0969,1_4389,1012,2338,102]]  )  # noqa: E231
       lowercase    :				Union[str, Any]       		=							tf.convert_to_tensor([[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],]  )  # noqa: E231
       lowercase    :				Tuple       		=							tf.convert_to_tensor([[[0,0,0,0],[423,237,440,251],[427,272,441,287],[419,115,437,129],[961,885,992,912],[256,38,330,58],[256,38,330,58],[336,42,353,57],[360,39,401,56],[360,39,401,56],[411,39,471,59],[479,41,528,59],[533,39,630,60],[67,113,134,131],[141,115,209,132],[68,149,133,166],[141,149,187,164],[195,148,287,165],[195,148,287,165],[195,148,287,165],[295,148,349,165],[441,149,492,166],[497,149,546,164],[64,201,125,218],[1000,1000,1000,1000]],[[0,0,0,0],[662,150,754,166],[665,199,742,211],[519,213,554,228],[519,213,554,228],[134,433,187,454],[130,467,204,480],[130,467,204,480],[130,467,204,480],[130,467,204,480],[130,467,204,480],[314,469,376,482],[504,684,582,706],[941,825,973,900],[941,825,973,900],[941,825,973,900],[941,825,973,900],[610,749,652,765],[130,659,168,672],[176,657,237,672],[238,657,312,672],[443,653,628,672],[443,653,628,672],[716,301,825,317],[1000,1000,1000,1000]]]  )  # noqa: E231
       lowercase    :				Optional[Any]       		=							tf.convert_to_tensor([[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]]  )  # noqa: E231
       # these are sequence labels (i.e. at the token level)
       lowercase    :				List[Any]       		=							tf.convert_to_tensor([[-100,10,10,10,9,1,-100,7,7,-100,7,7,4,2,5,2,8,8,-100,-100,5,0,3,2,-100],[-100,12,12,12,-100,12,10,-100,-100,-100,-100,10,12,9,-100,-100,-100,10,10,10,9,12,-100,10,-100]]  )  # noqa: E231
       # fmt: on

       return input_ids, attention_mask, bbox, token_type_ids, labels

@require_tf
class 		a__						(      unittest.TestCase						):
   @slow
   def 			__magic_name__			(			self				):
          lowercase    :				Dict       		=							TFLayoutLMModel.from_pretrained("microsoft/layoutlm-base-uncased"				)

          lowercase		,    lowercase		,    lowercase		,    lowercase		,    lowercase    :				Union[str, Any]       		=							prepare_layoutlm_batch_inputs()

          # forward pass
          lowercase    :				Optional[int]       		=							model(input_ids=_a	,    bbox=_a	,    attention_mask=_a	,    token_type_ids=_a				)

          # test the sequence output on [0, :3, :3]
          lowercase    :				Any       		=							tf.convert_to_tensor(
              [[0.1_7_8_5, -0.1_9_4_7, -0.0_4_2_5], [-0.3_2_5_4, -0.2_8_0_7, 0.2_5_5_3], [-0.5_3_9_1, -0.3_3_2_2, 0.3_3_6_4]]	,    )

          self.assertTrue(np.allclose(outputs.last_hidden_state[0, :3, :3]	,    _a	,    atol=1E-3				)				)

          # test the pooled output on [1, :3]
          lowercase    :				Optional[Any]       		=							tf.convert_to_tensor([-0.6_5_8_0, -0.0_2_1_4, 0.8_5_5_2]				)

          self.assertTrue(np.allclose(outputs.pooler_output[1, :3]	,    _a	,    atol=1E-3				)				)
   @slow
   def 			__magic_name__			(			self				):
          # initialize model with randomly initialized sequence classification head
          lowercase    :				List[Any]       		=							TFLayoutLMForSequenceClassification.from_pretrained("microsoft/layoutlm-base-uncased"	,    num_labels=2				)

          lowercase		,    lowercase		,    lowercase		,    lowercase		,    lowercase    :				Optional[Any]       		=							prepare_layoutlm_batch_inputs()

          # forward pass
          lowercase    :				Optional[Any]       		=							model(
              input_ids=_a	,    bbox=_a	,    attention_mask=_a	,    token_type_ids=_a	,    labels=tf.convert_to_tensor([1, 1]				)	,    )

          # test whether we get a loss as a scalar
          lowercase    :				Union[str, Any]       		=							outputs.loss
          lowercase    :				Union[str, Any]       		=							(2,)
          self.assertEqual(loss.shape	,    _a				)

          # test the shape of the logits
          lowercase    :				List[str]       		=							outputs.logits
          lowercase    :				Optional[Any]       		=							(2, 2)
          self.assertEqual(logits.shape	,    _a				)
   @slow
   def 			__magic_name__			(			self				):
          # initialize model with randomly initialized token classification head
          lowercase    :				Any       		=							TFLayoutLMForTokenClassification.from_pretrained("microsoft/layoutlm-base-uncased"	,    num_labels=13				)

          lowercase		,    lowercase		,    lowercase		,    lowercase		,    lowercase    :				str       		=							prepare_layoutlm_batch_inputs()

          # forward pass
          lowercase    :				List[Any]       		=							model(
              input_ids=_a	,    bbox=_a	,    attention_mask=_a	,    token_type_ids=_a	,    labels=_a				)

          # test the shape of the logits
          lowercase    :				int       		=							outputs.logits
          lowercase    :				Optional[Any]       		=							tf.convert_to_tensor((2, 25, 13)				)
          self.assertEqual(logits.shape	,    _a				)

   @slow
   def 			__magic_name__			(			self				):
          # initialize model with randomly initialized token classification head
          lowercase    :				Union[str, Any]       		=							TFLayoutLMForQuestionAnswering.from_pretrained("microsoft/layoutlm-base-uncased"				)

          lowercase		,    lowercase		,    lowercase		,    lowercase		,    lowercase    :				Tuple       		=							prepare_layoutlm_batch_inputs()

          # forward pass
          lowercase    :				Optional[int]       		=							model(input_ids=_a	,    bbox=_a	,    attention_mask=_a	,    token_type_ids=_a				)

          # test the shape of the logits
          lowercase    :				Any       		=							tf.convert_to_tensor((2, 25)				)
          self.assertEqual(outputs.start_logits.shape	,    _a				)
          self.assertEqual(outputs.end_logits.shape	,    _a				)


