






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__     :

     '''simple docstring'''






     def __init__( self      :    int   ,						_SCREAMING_SNAKE_CASE      :    List[str]   ,						_SCREAMING_SNAKE_CASE      :    Optional[Any]=13   ,						_SCREAMING_SNAKE_CASE      :    List[str]=7   ,						_SCREAMING_SNAKE_CASE      :    List[str]=True   ,						_SCREAMING_SNAKE_CASE      :    Union[str, Any]=True   ,						_SCREAMING_SNAKE_CASE      :    int=True   ,						_SCREAMING_SNAKE_CASE      :    Optional[int]=True   ,						_SCREAMING_SNAKE_CASE      :    Dict=99   ,						_SCREAMING_SNAKE_CASE      :    Optional[Any]=32   ,						_SCREAMING_SNAKE_CASE      :    Dict=2   ,						_SCREAMING_SNAKE_CASE      :    Tuple=4   ,						_SCREAMING_SNAKE_CASE      :    Dict=37   ,						_SCREAMING_SNAKE_CASE      :    Tuple="gelu"   ,						_SCREAMING_SNAKE_CASE      :    List[Any]=0.1   ,						_SCREAMING_SNAKE_CASE      :    str=0.1   ,						_SCREAMING_SNAKE_CASE      :    str=512   ,						_SCREAMING_SNAKE_CASE      :    Optional[Any]=16   ,						_SCREAMING_SNAKE_CASE      :    Union[str, Any]=2   ,						_SCREAMING_SNAKE_CASE      :    Optional[int]=0.0_2   ,						_SCREAMING_SNAKE_CASE      :    str=3   ,						_SCREAMING_SNAKE_CASE      :    Optional[Any]=4   ,						_SCREAMING_SNAKE_CASE      :    Optional[Any]=None   ,						_SCREAMING_SNAKE_CASE      :    Optional[int]=1000   ,						):






           """simple docstring"""




           UpperCamelCase					       =  parent
           UpperCamelCase					       =  batch_size
           UpperCamelCase					       =  seq_length
           UpperCamelCase					       =  is_training
           UpperCamelCase					       =  use_input_mask
           UpperCamelCase					       =  use_token_type_ids
           UpperCamelCase					       =  use_labels
           UpperCamelCase					       =  vocab_size
           UpperCamelCase					       =  hidden_size
           UpperCamelCase					       =  num_hidden_layers
           UpperCamelCase					       =  num_attention_heads
           UpperCamelCase					       =  intermediate_size
           UpperCamelCase					       =  hidden_act
           UpperCamelCase					       =  hidden_dropout_prob
           UpperCamelCase					       =  attention_probs_dropout_prob
           UpperCamelCase					       =  max_position_embeddings
           UpperCamelCase					       =  type_vocab_size
           UpperCamelCase					       =  type_sequence_label_size
           UpperCamelCase					       =  initializer_range
           UpperCamelCase					       =  num_labels
           UpperCamelCase					       =  num_choices
           UpperCamelCase					       =  scope
           UpperCamelCase					       =  range_bbox







     def   _SCREAMING_SNAKE_CASE     ( self      :    Tuple ):






           """simple docstring"""




           UpperCamelCase					       =  ids_tensor([self.batch_size, self.seq_length]   ,						self.vocab_size )

           # convert bbox to numpy since TF does not support item assignment
           UpperCamelCase					       =  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]:
                             UpperCamelCase					       =  bbox[i, j, 3]
                             UpperCamelCase					       =  bbox[i, j, 1]
                             UpperCamelCase					       =  t
                       if bbox[i, j, 2] < bbox[i, j, 0]:
                             UpperCamelCase					       =  bbox[i, j, 2]
                             UpperCamelCase					       =  bbox[i, j, 0]
                             UpperCamelCase					       =  t
           UpperCamelCase					       =  tf.convert_to_tensor(_SCREAMING_SNAKE_CASE )

           UpperCamelCase					       =  None
           if self.use_input_mask:
                 UpperCamelCase					       =  random_attention_mask([self.batch_size, self.seq_length] )

           UpperCamelCase					       =  None
           if self.use_token_type_ids:
                 UpperCamelCase					       =  ids_tensor([self.batch_size, self.seq_length]   ,						self.type_vocab_size )

           UpperCamelCase					       =  None
           UpperCamelCase					       =  None
           UpperCamelCase					       =  None
           if self.use_labels:
                 UpperCamelCase					       =  ids_tensor([self.batch_size]   ,						self.type_sequence_label_size )
                 UpperCamelCase					       =  ids_tensor([self.batch_size, self.seq_length]   ,						self.num_labels )
                 UpperCamelCase					       =  ids_tensor([self.batch_size]   ,						self.num_choices )

           UpperCamelCase					       =  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   _SCREAMING_SNAKE_CASE     ( self      :    Tuple   ,						_SCREAMING_SNAKE_CASE      :    List[str]   ,						_SCREAMING_SNAKE_CASE      :    Union[str, Any]   ,						_SCREAMING_SNAKE_CASE      :    Any   ,						_SCREAMING_SNAKE_CASE      :    List[Any]   ,						_SCREAMING_SNAKE_CASE      :    Dict   ,						_SCREAMING_SNAKE_CASE      :    Any   ,						_SCREAMING_SNAKE_CASE      :    Tuple   ,						_SCREAMING_SNAKE_CASE      :    List[str] ):






           """simple docstring"""




           UpperCamelCase					       =  TFLayoutLMModel(config=_SCREAMING_SNAKE_CASE )

           UpperCamelCase					       =  model(_SCREAMING_SNAKE_CASE   ,						_SCREAMING_SNAKE_CASE   ,						attention_mask=_SCREAMING_SNAKE_CASE   ,						token_type_ids=_SCREAMING_SNAKE_CASE )
           UpperCamelCase					       =  model(_SCREAMING_SNAKE_CASE   ,						_SCREAMING_SNAKE_CASE   ,						token_type_ids=_SCREAMING_SNAKE_CASE )
           UpperCamelCase					       =  model(_SCREAMING_SNAKE_CASE   ,						_SCREAMING_SNAKE_CASE )
           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   _SCREAMING_SNAKE_CASE     ( self      :    Union[str, Any]   ,						_SCREAMING_SNAKE_CASE      :    List[str]   ,						_SCREAMING_SNAKE_CASE      :    str   ,						_SCREAMING_SNAKE_CASE      :    int   ,						_SCREAMING_SNAKE_CASE      :    Optional[int]   ,						_SCREAMING_SNAKE_CASE      :    Optional[Any]   ,						_SCREAMING_SNAKE_CASE      :    Tuple   ,						_SCREAMING_SNAKE_CASE      :    List[Any]   ,						_SCREAMING_SNAKE_CASE      :    Union[str, Any] ):






           """simple docstring"""




           UpperCamelCase					       =  TFLayoutLMForMaskedLM(config=_SCREAMING_SNAKE_CASE )

           UpperCamelCase					       =  model(_SCREAMING_SNAKE_CASE   ,						_SCREAMING_SNAKE_CASE   ,						attention_mask=_SCREAMING_SNAKE_CASE   ,						token_type_ids=_SCREAMING_SNAKE_CASE   ,						labels=_SCREAMING_SNAKE_CASE )
           self.parent.assertEqual(result.logits.shape   ,						(self.batch_size, self.seq_length, self.vocab_size) )







     def   _SCREAMING_SNAKE_CASE     ( self      :    Optional[int]   ,						_SCREAMING_SNAKE_CASE      :    Any   ,						_SCREAMING_SNAKE_CASE      :    int   ,						_SCREAMING_SNAKE_CASE      :    Dict   ,						_SCREAMING_SNAKE_CASE      :    int   ,						_SCREAMING_SNAKE_CASE      :    List[Any]   ,						_SCREAMING_SNAKE_CASE      :    List[Any]   ,						_SCREAMING_SNAKE_CASE      :    Any   ,						_SCREAMING_SNAKE_CASE      :    List[Any] ):






           """simple docstring"""




           UpperCamelCase					       =  self.num_labels
           UpperCamelCase					       =  TFLayoutLMForSequenceClassification(config=_SCREAMING_SNAKE_CASE )

           UpperCamelCase					       =  model(_SCREAMING_SNAKE_CASE   ,						_SCREAMING_SNAKE_CASE   ,						attention_mask=_SCREAMING_SNAKE_CASE   ,						token_type_ids=_SCREAMING_SNAKE_CASE )
           self.parent.assertEqual(result.logits.shape   ,						(self.batch_size, self.num_labels) )







     def   _SCREAMING_SNAKE_CASE     ( self      :    Optional[Any]   ,						_SCREAMING_SNAKE_CASE      :    List[Any]   ,						_SCREAMING_SNAKE_CASE      :    Optional[Any]   ,						_SCREAMING_SNAKE_CASE      :    Union[str, Any]   ,						_SCREAMING_SNAKE_CASE      :    List[Any]   ,						_SCREAMING_SNAKE_CASE      :    str   ,						_SCREAMING_SNAKE_CASE      :    Optional[Any]   ,						_SCREAMING_SNAKE_CASE      :    Any   ,						_SCREAMING_SNAKE_CASE      :    Union[str, Any] ):






           """simple docstring"""




           UpperCamelCase					       =  self.num_labels
           UpperCamelCase					       =  TFLayoutLMForTokenClassification(config=_SCREAMING_SNAKE_CASE )

           UpperCamelCase					       =  model(_SCREAMING_SNAKE_CASE   ,						_SCREAMING_SNAKE_CASE   ,						attention_mask=_SCREAMING_SNAKE_CASE   ,						token_type_ids=_SCREAMING_SNAKE_CASE   ,						labels=_SCREAMING_SNAKE_CASE )
           self.parent.assertEqual(result.logits.shape   ,						(self.batch_size, self.seq_length, self.num_labels) )







     def   _SCREAMING_SNAKE_CASE     ( self      :    Optional[int]   ,						_SCREAMING_SNAKE_CASE      :    Tuple   ,						_SCREAMING_SNAKE_CASE      :    int   ,						_SCREAMING_SNAKE_CASE      :    Optional[Any]   ,						_SCREAMING_SNAKE_CASE      :    Tuple   ,						_SCREAMING_SNAKE_CASE      :    Any   ,						_SCREAMING_SNAKE_CASE      :    Optional[Any]   ,						_SCREAMING_SNAKE_CASE      :    List[Any]   ,						_SCREAMING_SNAKE_CASE      :    int ):






           """simple docstring"""




           UpperCamelCase					       =  TFLayoutLMForQuestionAnswering(config=_SCREAMING_SNAKE_CASE )

           UpperCamelCase					       =  model(_SCREAMING_SNAKE_CASE   ,						_SCREAMING_SNAKE_CASE   ,						attention_mask=_SCREAMING_SNAKE_CASE   ,						token_type_ids=_SCREAMING_SNAKE_CASE )
           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   _SCREAMING_SNAKE_CASE     ( self      :    Dict ):






           """simple docstring"""




           UpperCamelCase					       =  self.prepare_config_and_inputs()
           (
               (
               UpperCamelCase	
           )       ,  (
               UpperCamelCase	
           )       ,  (
               UpperCamelCase	
           )       ,  (
               UpperCamelCase	
           )       ,  (
               UpperCamelCase	
           )       ,  (
               UpperCamelCase	
           )       ,  (
               UpperCamelCase	
           )       ,  (
               UpperCamelCase	
           )       ,  	
           )					       =  config_and_inputs
           UpperCamelCase					       =  {
               'input_ids': input_ids,
               'bbox': bbox,
               'token_type_ids': token_type_ids,
               'attention_mask': input_mask,
           }
           return config, inputs_dict





@require_tf
class 					A__     (     __snake_case   ,    __snake_case   ,    unittest.TestCase ):

     '''simple docstring'''






     snake_case__					=					(
         (
             TFLayoutLMModel,
             TFLayoutLMForMaskedLM,
             TFLayoutLMForTokenClassification,
             TFLayoutLMForSequenceClassification,
             TFLayoutLMForQuestionAnswering,
         )
         if is_tf_available()
         else ()
     )
     snake_case__					=					(
         {
             'feature-extraction': TFLayoutLMModel,
             'fill-mask': TFLayoutLMForMaskedLM,
             'text-classification': TFLayoutLMForSequenceClassification,
             'token-classification': TFLayoutLMForTokenClassification,
             'zero-shot': TFLayoutLMForSequenceClassification,
         }
         if is_tf_available()
         else {}
     )
     snake_case__					=					False
     snake_case__					=					True
     snake_case__					=					10







     def   _SCREAMING_SNAKE_CASE     ( self      :    Optional[Any] ):






           """simple docstring"""




           UpperCamelCase					       =  TFLayoutLMModelTester(self )
           UpperCamelCase					       =  ConfigTester(self   ,						config_class=_SCREAMING_SNAKE_CASE   ,						hidden_size=37 )







     def   _SCREAMING_SNAKE_CASE     ( self      :    Dict ):






           """simple docstring"""




           self.config_tester.run_common_tests()







     def   _SCREAMING_SNAKE_CASE     ( self      :    List[str] ):






           """simple docstring"""




           UpperCamelCase					       =  self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_model(*_SCREAMING_SNAKE_CASE )







     def   _SCREAMING_SNAKE_CASE     ( self      :    int ):






           """simple docstring"""




           UpperCamelCase					       =  self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_masked_lm(*_SCREAMING_SNAKE_CASE )







     def   _SCREAMING_SNAKE_CASE     ( self      :    Any ):






           """simple docstring"""




           UpperCamelCase					       =  self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_sequence_classification(*_SCREAMING_SNAKE_CASE )







     def   _SCREAMING_SNAKE_CASE     ( self      :    Union[str, Any] ):






           """simple docstring"""




           UpperCamelCase					       =  self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_token_classification(*_SCREAMING_SNAKE_CASE )







     def   _SCREAMING_SNAKE_CASE     ( self      :    Any ):






           """simple docstring"""




           UpperCamelCase					       =  self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_question_answering(*_SCREAMING_SNAKE_CASE )







     @slow
     def   _SCREAMING_SNAKE_CASE     ( self      :    Tuple ):






           """simple docstring"""




           for model_name in TF_LAYOUTLM_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                 UpperCamelCase					       =  TFLayoutLMModel.from_pretrained(_SCREAMING_SNAKE_CASE )
                 self.assertIsNotNone(_SCREAMING_SNAKE_CASE )







     @unittest.skip('Onnx compliancy broke with TF 2.10' )
     def   _SCREAMING_SNAKE_CASE     ( self      :    List[Any] ):






           """simple docstring"""




           pass

def 		lowercase__  (				) ->			Optional[Any]:
      """simple docstring"""

      UpperCamelCase					       =  tf.convert_to_tensor([[1_01,10_19,10_14,10_16,10_37,1_28_49,47_47,10_04,1_42_46,22_78,54_39,45_24,50_02,29_30,21_93,29_30,43_41,32_08,10_05,10_55,21_71,28_48,1_13_00,35_31,1_02],[1_01,40_70,40_34,70_20,10_24,30_58,10_15,10_13,28_61,10_13,60_70,1_92_74,27_72,62_05,2_78_14,1_61_47,1_61_47,43_43,20_47,1_02_83,1_09_69,1_43_89,10_12,23_38,1_02]])  # noqa: E231
      UpperCamelCase					       =  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
      UpperCamelCase					       =  tf.convert_to_tensor([[[0,0,0,0],[4_23,2_37,4_40,2_51],[4_27,2_72,4_41,2_87],[4_19,1_15,4_37,1_29],[9_61,8_85,9_92,9_12],[2_56,38,3_30,58],[2_56,38,3_30,58],[3_36,42,3_53,57],[3_60,39,4_01,56],[3_60,39,4_01,56],[4_11,39,4_71,59],[4_79,41,5_28,59],[5_33,39,6_30,60],[67,1_13,1_34,1_31],[1_41,1_15,2_09,1_32],[68,1_49,1_33,1_66],[1_41,1_49,1_87,1_64],[1_95,1_48,2_87,1_65],[1_95,1_48,2_87,1_65],[1_95,1_48,2_87,1_65],[2_95,1_48,3_49,1_65],[4_41,1_49,4_92,1_66],[4_97,1_49,5_46,1_64],[64,2_01,1_25,2_18],[10_00,10_00,10_00,10_00]],[[0,0,0,0],[6_62,1_50,7_54,1_66],[6_65,1_99,7_42,2_11],[5_19,2_13,5_54,2_28],[5_19,2_13,5_54,2_28],[1_34,4_33,1_87,4_54],[1_30,4_67,2_04,4_80],[1_30,4_67,2_04,4_80],[1_30,4_67,2_04,4_80],[1_30,4_67,2_04,4_80],[1_30,4_67,2_04,4_80],[3_14,4_69,3_76,4_82],[5_04,6_84,5_82,7_06],[9_41,8_25,9_73,9_00],[9_41,8_25,9_73,9_00],[9_41,8_25,9_73,9_00],[9_41,8_25,9_73,9_00],[6_10,7_49,6_52,7_65],[1_30,6_59,1_68,6_72],[1_76,6_57,2_37,6_72],[2_38,6_57,3_12,6_72],[4_43,6_53,6_28,6_72],[4_43,6_53,6_28,6_72],[7_16,3_01,8_25,3_17],[10_00,10_00,10_00,10_00]]])  # noqa: E231
      UpperCamelCase					       =  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)
      UpperCamelCase					       =  tf.convert_to_tensor([[-1_00,10,10,10,9,1,-1_00,7,7,-1_00,7,7,4,2,5,2,8,8,-1_00,-1_00,5,0,3,2,-1_00],[-1_00,12,12,12,-1_00,12,10,-1_00,-1_00,-1_00,-1_00,10,12,9,-1_00,-1_00,-1_00,10,10,10,9,12,-1_00,10,-1_00]])  # noqa: E231
      # fmt: on

      return input_ids, attention_mask, bbox, token_type_ids, labels





@require_tf
class 					A__     (     unittest.TestCase ):

     '''simple docstring'''






     @slow
     def   _SCREAMING_SNAKE_CASE     ( self      :    Tuple ):






           """simple docstring"""




           UpperCamelCase					       =  TFLayoutLMModel.from_pretrained('microsoft/layoutlm-base-uncased' )

           UpperCamelCase       ,  UpperCamelCase       ,  UpperCamelCase       ,  UpperCamelCase       ,  UpperCamelCase					       =  prepare_layoutlm_batch_inputs()

           # forward pass
           UpperCamelCase					       =  model(input_ids=_SCREAMING_SNAKE_CASE   ,						bbox=_SCREAMING_SNAKE_CASE   ,						attention_mask=_SCREAMING_SNAKE_CASE   ,						token_type_ids=_SCREAMING_SNAKE_CASE )

           # test the sequence output on [0, :3, :3]
           UpperCamelCase					       =  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]   ,						_SCREAMING_SNAKE_CASE   ,						atol=1E-3 ) )

           # test the pooled output on [1, :3]
           UpperCamelCase					       =  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]   ,						_SCREAMING_SNAKE_CASE   ,						atol=1E-3 ) )







     @slow
     def   _SCREAMING_SNAKE_CASE     ( self      :    Optional[int] ):






           """simple docstring"""




           UpperCamelCase					       =  TFLayoutLMForSequenceClassification.from_pretrained('microsoft/layoutlm-base-uncased'   ,						num_labels=2 )

           UpperCamelCase       ,  UpperCamelCase       ,  UpperCamelCase       ,  UpperCamelCase       ,  UpperCamelCase					       =  prepare_layoutlm_batch_inputs()

           # forward pass
           UpperCamelCase					       =  model(
               input_ids=_SCREAMING_SNAKE_CASE   ,						bbox=_SCREAMING_SNAKE_CASE   ,						attention_mask=_SCREAMING_SNAKE_CASE   ,						token_type_ids=_SCREAMING_SNAKE_CASE   ,						labels=tf.convert_to_tensor([1, 1] )   ,						)

           # test whether we get a loss as a scalar
           UpperCamelCase					       =  outputs.loss
           UpperCamelCase					       =  (2,)
           self.assertEqual(loss.shape   ,						_SCREAMING_SNAKE_CASE )

           # test the shape of the logits
           UpperCamelCase					       =  outputs.logits
           UpperCamelCase					       =  (2, 2)
           self.assertEqual(logits.shape   ,						_SCREAMING_SNAKE_CASE )







     @slow
     def   _SCREAMING_SNAKE_CASE     ( self      :    List[Any] ):






           """simple docstring"""




           UpperCamelCase					       =  TFLayoutLMForTokenClassification.from_pretrained('microsoft/layoutlm-base-uncased'   ,						num_labels=13 )

           UpperCamelCase       ,  UpperCamelCase       ,  UpperCamelCase       ,  UpperCamelCase       ,  UpperCamelCase					       =  prepare_layoutlm_batch_inputs()

           # forward pass
           UpperCamelCase					       =  model(
               input_ids=_SCREAMING_SNAKE_CASE   ,						bbox=_SCREAMING_SNAKE_CASE   ,						attention_mask=_SCREAMING_SNAKE_CASE   ,						token_type_ids=_SCREAMING_SNAKE_CASE   ,						labels=_SCREAMING_SNAKE_CASE )

           # test the shape of the logits
           UpperCamelCase					       =  outputs.logits
           UpperCamelCase					       =  tf.convert_to_tensor((2, 25, 13) )
           self.assertEqual(logits.shape   ,						_SCREAMING_SNAKE_CASE )







     @slow
     def   _SCREAMING_SNAKE_CASE     ( self      :    List[Any] ):






           """simple docstring"""




           UpperCamelCase					       =  TFLayoutLMForQuestionAnswering.from_pretrained('microsoft/layoutlm-base-uncased' )

           UpperCamelCase       ,  UpperCamelCase       ,  UpperCamelCase       ,  UpperCamelCase       ,  UpperCamelCase					       =  prepare_layoutlm_batch_inputs()

           # forward pass
           UpperCamelCase					       =  model(input_ids=_SCREAMING_SNAKE_CASE   ,						bbox=_SCREAMING_SNAKE_CASE   ,						attention_mask=_SCREAMING_SNAKE_CASE   ,						token_type_ids=_SCREAMING_SNAKE_CASE )

           # test the shape of the logits
           UpperCamelCase					       =  tf.convert_to_tensor((2, 25) )
           self.assertEqual(outputs.start_logits.shape   ,						_SCREAMING_SNAKE_CASE )
           self.assertEqual(outputs.end_logits.shape   ,						_SCREAMING_SNAKE_CASE )







"""simple docstring"""



from google.protobuf import descriptor as _descriptor
from google.protobuf import descriptor_pool as _descriptor_pool
from google.protobuf import symbol_database as _symbol_database
from google.protobuf.internal import builder as _builder


# @@protoc_insertion_point(imports)

lowercase_							=							_symbol_database.Default()


lowercase_							=							_descriptor_pool.Default().AddSerializedFile(
    b'\n\x19sentencepiece_model.proto\x12\rsentencepiece"\x80\x0c\n\x0bTrainerSpec\x12\r\n\x05input\x18\x01 \x03(\t\x12\x14\n\x0cinput_format\x18\x07 \x01(\t\x12\x14\n\x0cmodel_prefix\x18\x02 \x01(\t\x12\x41\n\nmodel_type\x18\x03 \x01(\x0e\x32$.sentencepiece.TrainerSpec.ModelType:\x07UNIGRAM\x12\x18\n\nvocab_size\x18\x04 \x01(\x05:\x04\x38\x30\x30\x30\x12\x17\n\x0f\x61\x63\x63\x65pt_language\x18\x05 \x03(\t\x12 \n\x15self_test_sample_size\x18\x06 \x01(\x05:\x01\x30\x12*\n\x1b\x65nable_differential_privacy\x18\x32 \x01(\x08:\x05\x66\x61lse\x12+\n differential_privacy_noise_level\x18\x33 \x01(\x02:\x01\x30\x12\x32\n\'differential_privacy_clipping_threshold\x18\x34 \x01(\x04:\x01\x30\x12"\n\x12\x63haracter_coverage\x18\n \x01(\x02:\x06\x30.9995\x12\x1e\n\x13input_sentence_size\x18\x0b \x01(\x04:\x01\x30\x12$\n\x16shuffle_input_sentence\x18\x13 \x01(\x08:\x04true\x12 \n\x14mining_sentence_size\x18\x0c \x01(\x05\x42\x02\x18\x01\x12"\n\x16training_sentence_size\x18\r \x01(\x05\x42\x02\x18\x01\x12(\n\x17seed_sentencepiece_size\x18\x0e \x01(\x05:\x07\x31\x30\x30\x30\x30\x30\x30\x12\x1e\n\x10shrinking_factor\x18\x0f \x01(\x02:\x04\x30.75\x12!\n\x13max_sentence_length\x18\x12 \x01(\x05:\x04\x34\x31\x39\x32\x12\x17\n\x0bnum_threads\x18\x10 \x01(\x05:\x02\x31\x36\x12\x1d\n\x12num_sub_iterations\x18\x11 \x01(\x05:\x01\x32\x12$\n\x18max_sentencepiece_length\x18\x14 \x01(\x05:\x02\x31\x36\x12%\n\x17split_by_unicode_script\x18\x15 \x01(\x08:\x04true\x12\x1d\n\x0fsplit_by_number\x18\x17 \x01(\x08:\x04true\x12!\n\x13split_by_whitespace\x18\x16 \x01(\x08:\x04true\x12)\n\x1atreat_whitespace_as_suffix\x18\x18 \x01(\x08:\x05\x66\x61lse\x12+\n\x1c\x61llow_whitespace_only_pieces\x18\x1a \x01(\x08:\x05\x66\x61lse\x12\x1b\n\x0csplit_digits\x18\x19 \x01(\x08:\x05\x66\x61lse\x12#\n\x19pretokenization_delimiter\x18\x35 \x01(\t:\x00\x12\x17\n\x0f\x63ontrol_symbols\x18\x1e \x03(\t\x12\x1c\n\x14user_defined_symbols\x18\x1f \x03(\t\x12\x16\n\x0erequired_chars\x18$ \x01(\t\x12\x1c\n\rbyte_fallback\x18# \x01(\x08:\x05\x66\x61lse\x12+\n\x1dvocabulary_output_piece_score\x18  \x01(\x08:\x04true\x12\x1e\n\x10hard_vocab_limit\x18! \x01(\x08:\x04true\x12\x1c\n\ruse_all_vocab\x18" \x01(\x08:\x05\x66\x61lse\x12\x11\n\x06unk_id\x18( \x01(\x05:\x01\x30\x12\x11\n\x06\x62os_id\x18) \x01(\x05:\x01\x31\x12\x11\n\x06\x65os_id\x18* \x01(\x05:\x01\x32\x12\x12\n\x06pad_id\x18+ \x01(\x05:\x02-1\x12\x18\n\tunk_piece\x18- \x01(\t:\x05<unk>\x12\x16\n\tbos_piece\x18. \x01(\t:\x03<s>\x12\x17\n\teos_piece\x18/ \x01(\t:\x04</s>\x12\x18\n\tpad_piece\x18\x30 \x01(\t:\x05<pad>\x12\x1a\n\x0bunk_surface\x18, \x01(\t:\x05 \xe2\x81\x87 \x12+\n\x1ctrain_extremely_large_corpus\x18\x31 \x01(\x08:\x05\x66\x61lse"5\n\tModelType\x12\x0b\n\x07UNIGRAM\x10\x01\x12\x07\n\x03\x42PE\x10\x02\x12\x08\n\x04WORD\x10\x03\x12\x08\n\x04\x43HAR\x10\x04*\t\x08\xc8\x01\x10\x80\x80\x80\x80\x02"\xd1\x01\n\x0eNormalizerSpec\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x1c\n\x14precompiled_charsmap\x18\x02 \x01(\x0c\x12\x1e\n\x10\x61\x64\x64_dummy_prefix\x18\x03 \x01(\x08:\x04true\x12&\n\x18remove_extra_whitespaces\x18\x04 \x01(\x08:\x04true\x12 \n\x12\x65scape_whitespaces\x18\x05 \x01(\x08:\x04true\x12\x1e\n\x16normalization_rule_tsv\x18\x06 \x01(\t*\t\x08\xc8\x01\x10\x80\x80\x80\x80\x02"y\n\x0cSelfTestData\x12\x33\n\x07samples\x18\x01 \x03(\x0b\x32".sentencepiece.SelfTestData.Sample\x1a)\n\x06Sample\x12\r\n\x05input\x18\x01 \x01(\t\x12\x10\n\x08\x65xpected\x18\x02 \x01(\t*\t\x08\xc8\x01\x10\x80\x80\x80\x80\x02"\xfe\x03\n\nModelProto\x12\x37\n\x06pieces\x18\x01 \x03(\x0b\x32\'.sentencepiece.ModelProto.SentencePiece\x12\x30\n\x0ctrainer_spec\x18\x02 \x01(\x0b\x32\x1a.sentencepiece.TrainerSpec\x12\x36\n\x0fnormalizer_spec\x18\x03 \x01(\x0b\x32\x1d.sentencepiece.NormalizerSpec\x12\x33\n\x0eself_test_data\x18\x04 \x01(\x0b\x32\x1b.sentencepiece.SelfTestData\x12\x38\n\x11\x64\x65normalizer_spec\x18\x05 \x01(\x0b\x32\x1d.sentencepiece.NormalizerSpec\x1a\xd2\x01\n\rSentencePiece\x12\r\n\x05piece\x18\x01 \x01(\t\x12\r\n\x05score\x18\x02 \x01(\x02\x12\x42\n\x04type\x18\x03 \x01(\x0e\x32,.sentencepiece.ModelProto.SentencePiece.Type:\x06NORMAL"T\n\x04Type\x12\n\n\x06NORMAL\x10\x01\x12\x0b\n\x07UNKNOWN\x10\x02\x12\x0b\n\x07\x43ONTROL\x10\x03\x12\x10\n\x0cUSER_DEFINED\x10\x04\x12\x08\n\x04\x42YTE\x10\x06\x12\n\n\x06UNUSED\x10\x05*\t\x08\xc8\x01\x10\x80\x80\x80\x80\x02*\t\x08\xc8\x01\x10\x80\x80\x80\x80\x02\x42\x02H\x03'
)

lowercase_							=							globals()
_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'sentencepiece_model_pb2', _globals)
if _descriptor._USE_C_DESCRIPTORS is False:
		lowercase_							=							None
		lowercase_							=							b'H\003'
		# (generated by protobuf compiler, but `_TRAINERSPEC` is not defined)
		# _TRAINERSPEC.fields_by_name["mining_sentence_size"]._options = None
		# _TRAINERSPEC.fields_by_name["mining_sentence_size"]._serialized_options = b"\030\001"
		# _TRAINERSPEC.fields_by_name["training_sentence_size"]._options = None
		# _TRAINERSPEC.fields_by_name["training_sentence_size"]._serialized_options = b"\030\001"
		lowercase_							=							45
		lowercase_							=							15_81
		lowercase_							=							15_17
		lowercase_							=							15_70
		lowercase_							=							15_84
		lowercase_							=							17_93
		lowercase_							=							17_95
		lowercase_							=							19_16
		lowercase_							=							18_64
		lowercase_							=							19_05
		lowercase_							=							19_19
		lowercase_							=							24_29
		lowercase_							=							22_08
		lowercase_							=							24_18
		lowercase_							=							23_23
		lowercase_							=							24_07
# @@protoc_insertion_point(module_scope)