


from typing import Dict, List, Optional, Union

import numpy as np

from ...image_processing_utils import BaseImageProcessor, BatchFeature, get_size_dict
from ...image_transforms import (
    center_crop,
    convert_to_rgb,
    get_resize_output_image_size,
    normalize,
    rescale,
    resize,
    to_channel_dimension_format,
)
from ...image_utils import (
    OPENAI_CLIP_MEAN,
    OPENAI_CLIP_STD,
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, is_vision_available, logging


SCREAMING_SNAKE_CASE       :      Union[str, Any]												= logging.get_logger(__name__)


if is_vision_available():
 import PIL






class _lowerCamelCase(						a_   ):
       lowercase_ :	List[Any]     =			["""pixel_values"""]
       def __init__(					self,      lowerCamelCase = True,      lowerCamelCase = None,      lowerCamelCase = PILImageResampling.BICUBIC,      lowerCamelCase = True,      lowerCamelCase = None,      lowerCamelCase = True,      lowerCamelCase = 1 / 2_55,      lowerCamelCase = True,      lowerCamelCase = None,      lowerCamelCase = None,      lowerCamelCase = True,      **lowerCamelCase,      )       ->   Optional[int]:




           """simple docstring"""

           super().__init__(**_a)
           _lowercase       :							int      		=		size if size is not None else {"shortest_edge": 2_24}
           _lowercase       :							Optional[Any]      		=		get_size_dict(_a,      default_to_square=_a)
           _lowercase       :							Optional[int]      		=		crop_size if crop_size is not None else {"height": 2_24, "width": 2_24}
           _lowercase       :							int      		=		get_size_dict(_a,      default_to_square=_a,      param_name='crop_size')

           _lowercase       :							Optional[int]      		=		do_resize
           _lowercase       :							str      		=		size
           _lowercase       :							Any      		=		resample
           _lowercase       :							Tuple      		=		do_center_crop
           _lowercase       :							Dict      		=		crop_size
           _lowercase       :							Dict      		=		do_rescale
           _lowercase       :							List[Any]      		=		rescale_factor
           _lowercase       :							str      		=		do_normalize
           _lowercase       :							Dict      		=		image_mean if image_mean is not None else OPENAI_CLIP_MEAN
           _lowercase       :							Optional[Any]      		=		image_std if image_std is not None else OPENAI_CLIP_STD
           _lowercase       :							List[Any]      		=		do_convert_rgb
       def 			UpperCamelCase     (					self,      lowerCamelCase,      lowerCamelCase,      lowerCamelCase = PILImageResampling.BICUBIC,      lowerCamelCase = None,      **lowerCamelCase,      )       ->   Optional[Any]:




           """simple docstring"""

           _lowercase       :							Dict      		=		get_size_dict(_a,      default_to_square=_a)
           if "shortest_edge" not in size:
               raise ValueError(F'''The `size` parameter must contain the key `shortest_edge`. Got {size.keys()}''')
           _lowercase       :							Union[str, Any]      		=		get_resize_output_image_size(_a,      size=size['shortest_edge'],      default_to_square=_a)
           return resize(_a,      size=_a,      resample=_a,      data_format=_a,      **_a)
       def 			UpperCamelCase     (					self,      lowerCamelCase,      lowerCamelCase,      lowerCamelCase = None,      **lowerCamelCase,      )       ->   Dict:




           """simple docstring"""

           _lowercase       :							Optional[Any]      		=		get_size_dict(_a)
           if "height" not in size or "width" not in size:
               raise ValueError(F'''The `size` parameter must contain the keys (height, width). Got {size.keys()}''')
           return center_crop(_a,      size=(size['height'], size['width']),      data_format=_a,      **_a)
       def 			UpperCamelCase     (					self,      lowerCamelCase,      lowerCamelCase,      lowerCamelCase = None,      **lowerCamelCase,      )       ->   Dict:




           """simple docstring"""

           return rescale(_a,      scale=_a,      data_format=_a,      **_a)
       def 			UpperCamelCase     (					self,      lowerCamelCase,      lowerCamelCase,      lowerCamelCase,      lowerCamelCase = None,      **lowerCamelCase,      )       ->   Optional[Any]:




           """simple docstring"""

           return normalize(_a,      mean=_a,      std=_a,      data_format=_a,      **_a)




       def 			UpperCamelCase     (					self,      lowerCamelCase,      lowerCamelCase = None,      lowerCamelCase = None,      lowerCamelCase = None,      lowerCamelCase = None,      lowerCamelCase = None,      lowerCamelCase = None,      lowerCamelCase = None,      lowerCamelCase = None,      lowerCamelCase = None,      lowerCamelCase = None,      lowerCamelCase = None,      lowerCamelCase = None,      lowerCamelCase = ChannelDimension.FIRST,      **lowerCamelCase,      )       ->   Tuple:




           """simple docstring"""

           _lowercase       :							Optional[int]      		=		do_resize if do_resize is not None else self.do_resize
           _lowercase       :							Optional[int]      		=		size if size is not None else self.size
           _lowercase       :							int      		=		get_size_dict(_a,      param_name='size',      default_to_square=_a)
           _lowercase       :							str      		=		resample if resample is not None else self.resample
           _lowercase       :							str      		=		do_center_crop if do_center_crop is not None else self.do_center_crop
           _lowercase       :							List[Any]      		=		crop_size if crop_size is not None else self.crop_size
           _lowercase       :							Optional[int]      		=		get_size_dict(_a,      param_name='crop_size',      default_to_square=_a)
           _lowercase       :							Union[str, Any]      		=		do_rescale if do_rescale is not None else self.do_rescale
           _lowercase       :							Optional[int]      		=		rescale_factor if rescale_factor is not None else self.rescale_factor
           _lowercase       :							Any      		=		do_normalize if do_normalize is not None else self.do_normalize
           _lowercase       :							str      		=		image_mean if image_mean is not None else self.image_mean
           _lowercase       :							Optional[Any]      		=		image_std if image_std is not None else self.image_std
           _lowercase       :							Tuple      		=		do_convert_rgb if do_convert_rgb is not None else self.do_convert_rgb

           _lowercase       :							Optional[Any]      		=		make_list_of_images(_a)

           if not valid_images(_a):
               raise ValueError(
                   'Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, '
                   'torch.Tensor, tf.Tensor or jax.ndarray.')

           if do_resize and size is None:
               raise ValueError('Size must be specified if do_resize is True.')

           if do_center_crop and crop_size is None:
               raise ValueError('Crop size must be specified if do_center_crop is True.')

           if do_rescale and rescale_factor is None:
               raise ValueError('Rescale factor must be specified if do_rescale is True.')

           if do_normalize and (image_mean is None or image_std is None):
               raise ValueError('Image mean and std must be specified if do_normalize is True.')

           # PIL RGBA images are converted to RGB
           if do_convert_rgb:
               _lowercase       :							Any      		=		[convert_to_rgb(_a) for image in images]

           # All transformations expect numpy arrays.
           _lowercase       :							str      		=		[to_numpy_array(_a) for image in images]

           if do_resize:
               _lowercase       :							Union[str, Any]      		=		[self.resize(image=_a,      size=_a,      resample=_a) for image in images]

           if do_center_crop:
               _lowercase       :							List[Any]      		=		[self.center_crop(image=_a,      size=_a) for image in images]

           if do_rescale:
               _lowercase       :							Dict      		=		[self.rescale(image=_a,      scale=_a) for image in images]

           if do_normalize:
               _lowercase       :							int      		=		[self.normalize(image=_a,      mean=_a,      std=_a) for image in images]

           _lowercase       :							str      		=		[to_channel_dimension_format(_a,      _a) for image in images]

           _lowercase       :							List[Any]      		=		{"pixel_values": images}
           return BatchFeature(data=_a,      tensor_type=_a)




"""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				)


