code: 
  
  
  from collections import OrderedDict
  from typing import Any, List, Mapping, Optional
  
  from ... import PretrainedConfig, PreTrainedTokenizer
  from ...onnx import OnnxConfig, PatchingSpec
  from ...utils import TensorType, is_torch_available, logging
  
  
  __a   				=      logging.get_logger(__name__)
  
  __a   				=      {
      'microsoft/layoutlm-base-uncased': (
          'https://huggingface.co/microsoft/layoutlm-base-uncased/resolve/main/config.json'
      ),
      'microsoft/layoutlm-large-uncased': (
          'https://huggingface.co/microsoft/layoutlm-large-uncased/resolve/main/config.json'
      ),
  }
  
  
  
  
  
  
  
  class 				__SCREAMING_SNAKE_CASE   (			UpperCAmelCase_   ):
  						A				:							Tuple    							=     'layoutlm'
  
  
  						def __init__(							self							,						SCREAMING_SNAKE_CASE__=30522							,						SCREAMING_SNAKE_CASE__=768							,						SCREAMING_SNAKE_CASE__=12							,						SCREAMING_SNAKE_CASE__=12							,						SCREAMING_SNAKE_CASE__=3072							,						SCREAMING_SNAKE_CASE__="gelu"							,						SCREAMING_SNAKE_CASE__=0.1							,						SCREAMING_SNAKE_CASE__=0.1							,						SCREAMING_SNAKE_CASE__=512							,						SCREAMING_SNAKE_CASE__=2							,						SCREAMING_SNAKE_CASE__=0.02							,						SCREAMING_SNAKE_CASE__=1E-12							,						SCREAMING_SNAKE_CASE__=0							,						SCREAMING_SNAKE_CASE__="absolute"							,						SCREAMING_SNAKE_CASE__=True							,						SCREAMING_SNAKE_CASE__=1024							,						**SCREAMING_SNAKE_CASE__							,						):
  												super().__init__(pad_token_id=SCREAMING_SNAKE_CASE__							,						**SCREAMING_SNAKE_CASE__		)
  												lowercase			:   List[Any]					   =		vocab_size
  												lowercase			:   Optional[int]					   =		hidden_size
  												lowercase			:   Optional[Any]					   =		num_hidden_layers
  												lowercase			:   Union[str, Any]					   =		num_attention_heads
  												lowercase			:   int					   =		hidden_act
  												lowercase			:   Dict					   =		intermediate_size
  												lowercase			:   Union[str, Any]					   =		hidden_dropout_prob
  												lowercase			:   Tuple					   =		attention_probs_dropout_prob
  												lowercase			:   Optional[int]					   =		max_position_embeddings
  												lowercase			:   Optional[int]					   =		type_vocab_size
  												lowercase			:   int					   =		initializer_range
  												lowercase			:   Union[str, Any]					   =		layer_norm_eps
  												lowercase			:   int					   =		position_embedding_type
  												lowercase			:   List[str]					   =		use_cache
  												lowercase			:   Dict					   =		max_ad_position_embeddings
  
  
  
  
  
  
  
  class 				__SCREAMING_SNAKE_CASE   (			UpperCAmelCase_   ):
  
  
  						def __init__(							self							,						SCREAMING_SNAKE_CASE__							,						SCREAMING_SNAKE_CASE__ = "default"							,						SCREAMING_SNAKE_CASE__ = None							,						):
  												super().__init__(SCREAMING_SNAKE_CASE__							,						task=SCREAMING_SNAKE_CASE__							,						patching_specs=SCREAMING_SNAKE_CASE__		)
  												lowercase			:   Optional[Any]					   =		config.max_ad_position_embeddings - 1
  
  
  						@property
  						def        __lowerCamelCase			(							self		):
  												return OrderedDict(
  												    [
  												        ('''input_ids''', {0: '''batch''', 1: '''sequence'''}),
  												        ('''bbox''', {0: '''batch''', 1: '''sequence'''}),
  												        ('''attention_mask''', {0: '''batch''', 1: '''sequence'''}),
  												        ('''token_type_ids''', {0: '''batch''', 1: '''sequence'''}),
  												    ]		)
  
  
  
  
  
  
  						def        __lowerCamelCase			(							self							,						SCREAMING_SNAKE_CASE__							,						SCREAMING_SNAKE_CASE__ = -1							,						SCREAMING_SNAKE_CASE__ = -1							,						SCREAMING_SNAKE_CASE__ = False							,						SCREAMING_SNAKE_CASE__ = None							,						):
  												lowercase			:   Optional[int]					   =		super().generate_dummy_inputs(
  												    SCREAMING_SNAKE_CASE__							,						batch_size=SCREAMING_SNAKE_CASE__							,						seq_length=SCREAMING_SNAKE_CASE__							,						is_pair=SCREAMING_SNAKE_CASE__							,						framework=SCREAMING_SNAKE_CASE__		)
  
  												# Generate a dummy bbox
  												lowercase			:   Dict					   =		[48, 84, 73, 128]
  
  												if not framework == TensorType.PYTORCH:
  																		raise NotImplementedError('''Exporting LayoutLM to ONNX is currently only supported for PyTorch.'''		)
  
  												if not is_torch_available():
  																		raise ValueError('''Cannot generate dummy inputs without PyTorch installed.'''		)
  												import torch
  
  												lowercase   ,			lowercase			:   Union[str, Any]					   =		input_dict['''input_ids'''].shape
  												lowercase			:   Any					   =		torch.tensor([*[box] * seq_length]		).tile(SCREAMING_SNAKE_CASE__							,						1							,						1		)
  												return input_dict
  
  
style_context: 
  
  
  import numpy as np
  
  
  
  
  def 			__lowercase	(						_UpperCamelCase,    _UpperCamelCase     )    ->Dict:
  
  
  
  
  
  
  
        """simple docstring"""
  
        lowercase			:   Optional[Any]					   =		np.array(_UpperCamelCase     )
        lowercase			:   Dict					   =		np.array(_UpperCamelCase     )
  
        lowercase			:   List[Any]					   =		abs(predict - actual     )
        lowercase			:   int					   =		difference.mean()
  
        return score
  
  
  
  
  def 			__lowercase	(						_UpperCamelCase,    _UpperCamelCase     )    ->List[Any]:
  
  
  
  
  
  
  
        """simple docstring"""
  
        lowercase			:   Tuple					   =		np.array(_UpperCamelCase     )
        lowercase			:   str					   =		np.array(_UpperCamelCase     )
  
        lowercase			:   List[str]					   =		predict - actual
        lowercase			:   Tuple					   =		np.square(_UpperCamelCase     )
  
        lowercase			:   Union[str, Any]					   =		square_diff.mean()
        return score
  
  
  
  
  def 			__lowercase	(						_UpperCamelCase,    _UpperCamelCase     )    ->str:
  
  
  
  
  
  
  
        """simple docstring"""
  
        lowercase			:   Union[str, Any]					   =		np.array(_UpperCamelCase     )
        lowercase			:   Optional[Any]					   =		np.array(_UpperCamelCase     )
  
        lowercase			:   Tuple					   =		predict - actual
        lowercase			:   Dict					   =		np.square(_UpperCamelCase     )
        lowercase			:   Union[str, Any]					   =		square_diff.mean()
        lowercase			:   Union[str, Any]					   =		np.sqrt(_UpperCamelCase     )
        return score
  
  
  
  
  def 			__lowercase	(						_UpperCamelCase,    _UpperCamelCase     )    ->List[Any]:
  
  
  
  
  
  
  
        """simple docstring"""
  
        lowercase			:   List[str]					   =		np.array(_UpperCamelCase     )
        lowercase			:   List[Any]					   =		np.array(_UpperCamelCase     )
  
        lowercase			:   Dict					   =		np.log(predict + 1     )
        lowercase			:   List[str]					   =		np.log(actual + 1     )
  
        lowercase			:   int					   =		log_predict - log_actual
        lowercase			:   Tuple					   =		np.square(_UpperCamelCase     )
        lowercase			:   List[Any]					   =		square_diff.mean()
  
        lowercase			:   int					   =		np.sqrt(_UpperCamelCase     )
  
        return score
  
  
  
  
  def 			__lowercase	(						_UpperCamelCase,    _UpperCamelCase     )    ->List[str]:
  
  
  
  
  
  
  
        """simple docstring"""
  
        lowercase			:   List[Any]					   =		np.array(_UpperCamelCase     )
        lowercase			:   Optional[int]					   =		np.array(_UpperCamelCase     )
  
        lowercase			:   Optional[int]					   =		predict - actual
        lowercase			:   Optional[int]					   =		np.sum(_UpperCamelCase     ) / len(_UpperCamelCase     )
        lowercase			:   Dict					   =		np.sum(_UpperCamelCase     ) / len(_UpperCamelCase     )
        # print(numerator, denumerator)
        lowercase			:   int					   =		float(_UpperCamelCase     ) / denumerator * 100
  
        return score
  
  
  
  
  def 			__lowercase	(						_UpperCamelCase,    _UpperCamelCase     )    ->List[Any]:
  
  
  
  
  
  
  
        """simple docstring"""
  
        return np.mean(np.array(_UpperCamelCase     ) == np.array(_UpperCamelCase     )     )
  
  