
"""simple docstring"""





from typing import Callable, Dict, Optional, Tuple

import torch
from torch import nn
from torch.distributions import (
    AffineTransform,
    Distribution,
    Independent,
    NegativeBinomial,
    Normal,
    StudentT,
    TransformedDistribution,
)



class __lowerCAmelCase				(					_lowercase      ):




			"""simple docstring"""







			def __init__(				self						:					Tuple       ,   _snake_case						:					Distribution       ,   _snake_case						:					int=None       ,   _snake_case						:					Dict=None       ,   _snake_case						:					Union[str, Any]=0	)      -> Tuple:







								"""simple docstring"""
								A_				 =						1.0 if scale is None else scale
								A_				 =						0.0 if loc is None else loc

								super().__init__(_snake_case       ,   [AffineTransform(loc=self.loc       ,   scale=self.scale       ,   event_dim=_snake_case	)]	)




			@property
			def      lowerCamelCase__     (				self						:					Dict	)      -> Union[str, Any]:







								"""simple docstring"""
								return self.base_dist.mean * self.scale + self.loc




			@property
			def      lowerCamelCase__     (				self						:					Any	)      -> Tuple:







								"""simple docstring"""
								return self.base_dist.variance * self.scale**2






			@property
			def      lowerCamelCase__     (				self						:					Union[str, Any]	)      -> Dict:







								"""simple docstring"""
								return self.variance.sqrt()





class __lowerCAmelCase				(					nn.Module      ):




			"""simple docstring"""







			def __init__(				self						:					Union[str, Any]       ,   _snake_case						:					int       ,   _snake_case						:					Dict[str, int]       ,   _snake_case						:					Callable[..., Tuple[torch.Tensor]]       ,   **_snake_case						:					List[Any]	)      -> None:







								"""simple docstring"""
								super().__init__(**_snake_case	)
								A_				 =						args_dim
								A_				 =						nn.ModuleList([nn.Linear(_snake_case       ,   _snake_case	) for dim in args_dim.values()]	)
								A_				 =						domain_map






			def      lowerCamelCase__     (				self						:					str       ,   _snake_case						:					torch.Tensor	)      -> Tuple[torch.Tensor]:







								"""simple docstring"""
								A_				 =						[proj(_snake_case	) for proj in self.proj]

								return self.domain_map(*_snake_case	)





class __lowerCAmelCase				(					nn.Module      ):




			"""simple docstring"""







			def __init__(				self						:					List[Any]       ,   _snake_case						:					Optional[Any]	)      -> List[Any]:







								"""simple docstring"""
								super().__init__()
								A_				 =						function






			def      lowerCamelCase__     (				self						:					Any       ,   _snake_case						:					List[Any]       ,   *_snake_case						:					List[Any]	)      -> Dict:







								"""simple docstring"""
								return self.function(_snake_case       ,   *_snake_case	)





class __lowerCAmelCase				:




			"""simple docstring"""







			snake_case	      =				42
			snake_case	      =				42
			snake_case	      =				42




			def __init__(				self						:					int       ,   _snake_case						:					int = 1	)      -> None:







								"""simple docstring"""
								A_				 =						dim
								A_				 =						{k: dim * self.args_dim[k] for k in self.args_dim}




			def      lowerCamelCase__     (				self						:					Optional[int]       ,   _snake_case						:					List[Any]	)      -> List[str]:







								"""simple docstring"""
								if self.dim == 1:
													return self.distribution_class(*_snake_case	)
								else:
													return Independent(self.distribution_class(*_snake_case	)       ,   1	)




			def      lowerCamelCase__     (				self						:					Union[str, Any]       ,   _snake_case						:					Tuple       ,   _snake_case						:					Optional[torch.Tensor] = None       ,   _snake_case						:					Optional[torch.Tensor] = None       ,   )      -> Distribution:







								"""simple docstring"""
								A_				 =						self._base_distribution(_snake_case	)
								if loc is None and scale is None:
													return distr
								else:
													return AffineTransformed(_snake_case       ,   loc=_snake_case       ,   scale=_snake_case       ,   event_dim=self.event_dim	)




			@property
			def      lowerCamelCase__     (				self						:					Optional[int]	)      -> Tuple:







								"""simple docstring"""
								return () if self.dim == 1 else (self.dim,)




			@property
			def      lowerCamelCase__     (				self						:					Union[str, Any]	)      -> int:







								"""simple docstring"""
								return len(self.event_shape	)




			@property
			def      lowerCamelCase__     (				self						:					int	)      -> float:







								"""simple docstring"""
								return 0.0




			def      lowerCamelCase__     (				self						:					List[str]       ,   _snake_case						:					int	)      -> nn.Module:







								"""simple docstring"""
								return ParameterProjection(
								    in_features=_snake_case       ,   args_dim=self.args_dim       ,   domain_map=LambdaLayer(self.domain_map	)       ,   )




			def      lowerCamelCase__     (				self						:					List[str]       ,   *_snake_case						:					torch.Tensor	)      -> Any:







								"""simple docstring"""
								raise NotImplementedError()






			@staticmethod
			def      lowerCamelCase__     (				_snake_case						:					torch.Tensor	)      -> torch.Tensor:







								"""simple docstring"""
								return (x + torch.sqrt(torch.square(_snake_case	) + 4.0	)) / 2.0





class __lowerCAmelCase				(					_lowercase      ):




			"""simple docstring"""







			snake_case	      =				{"df": 1, "loc": 1, "scale": 1}
			snake_case	      =				StudentT




			@classmethod
			def      lowerCamelCase__     (				cls						:					Dict       ,   _snake_case						:					torch.Tensor       ,   _snake_case						:					torch.Tensor       ,   _snake_case						:					torch.Tensor	)      -> List[Any]:







								"""simple docstring"""
								A_				 =						cls.squareplus(_snake_case	).clamp_min(torch.finfo(scale.dtype	).eps	)
								A_				 =						2.0 + cls.squareplus(_snake_case	)
								return df.squeeze(-1	), loc.squeeze(-1	), scale.squeeze(-1	)





class __lowerCAmelCase				(					_lowercase      ):




			"""simple docstring"""







			snake_case	      =				{"loc": 1, "scale": 1}
			snake_case	      =				Normal




			@classmethod
			def      lowerCamelCase__     (				cls						:					str       ,   _snake_case						:					torch.Tensor       ,   _snake_case						:					torch.Tensor	)      -> Tuple:







								"""simple docstring"""
								A_				 =						cls.squareplus(_snake_case	).clamp_min(torch.finfo(scale.dtype	).eps	)
								return loc.squeeze(-1	), scale.squeeze(-1	)





class __lowerCAmelCase				(					_lowercase      ):




			"""simple docstring"""







			snake_case	      =				{"total_count": 1, "logits": 1}
			snake_case	      =				NegativeBinomial




			@classmethod
			def      lowerCamelCase__     (				cls						:					List[str]       ,   _snake_case						:					torch.Tensor       ,   _snake_case						:					torch.Tensor	)      -> Union[str, Any]:







								"""simple docstring"""
								A_				 =						cls.squareplus(_snake_case	)
								return total_count.squeeze(-1	), logits.squeeze(-1	)




			def      lowerCamelCase__     (				self						:					Dict       ,   _snake_case						:					Union[str, Any]	)      -> Distribution:







								"""simple docstring"""
								A_ ,    A_				 =						distr_args
								if self.dim == 1:
													return self.distribution_class(total_count=_snake_case       ,   logits=_snake_case	)
								else:
													return Independent(self.distribution_class(total_count=_snake_case       ,   logits=_snake_case	)       ,   1	)






			def      lowerCamelCase__     (				self						:					Tuple       ,   _snake_case						:					Optional[int]       ,   _snake_case						:					Optional[torch.Tensor] = None       ,   _snake_case						:					Optional[torch.Tensor] = None	)      -> Distribution:







								"""simple docstring"""
								A_ ,    A_				 =						distr_args

								if scale is not None:
													# See scaling property of Gamma.
													logits += scale.log()

								return self._base_distribution((total_count, logits)	)






"""simple docstring"""





from ...configuration_utils import PretrainedConfig
from ...utils import logging


UpperCamelCase_					:						Tuple				= logging.get_logger(__name__)

UpperCamelCase_					:						Optional[int]				= {
    '''microsoft/markuplm-base''': '''https://huggingface.co/microsoft/markuplm-base/resolve/main/config.json''',
    '''microsoft/markuplm-large''': '''https://huggingface.co/microsoft/markuplm-large/resolve/main/config.json''',
}



class __lowerCAmelCase				(					_lowercase      ):




			"""simple docstring"""







			snake_case	      =				"markuplm"




			def __init__(				self						:					Optional[Any]       ,   _snake_case						:					Dict=30_522       ,   _snake_case						:					str=768       ,   _snake_case						:					Tuple=12       ,   _snake_case						:					Union[str, Any]=12       ,   _snake_case						:					Union[str, Any]=3_072       ,   _snake_case						:					List[str]="gelu"       ,   _snake_case						:					List[str]=0.1       ,   _snake_case						:					Optional[Any]=0.1       ,   _snake_case						:					Dict=512       ,   _snake_case						:					Union[str, Any]=2       ,   _snake_case						:					Tuple=0.0_2       ,   _snake_case						:					Tuple=1e-12       ,   _snake_case						:					Tuple=0       ,   _snake_case						:					Tuple=0       ,   _snake_case						:					Optional[Any]=2       ,   _snake_case						:					int=256       ,   _snake_case						:					Dict=1_024       ,   _snake_case						:					List[str]=216       ,   _snake_case						:					Optional[int]=1_001       ,   _snake_case						:					Union[str, Any]=32       ,   _snake_case						:					List[str]=50       ,   _snake_case						:					str="absolute"       ,   _snake_case						:					Optional[Any]=True       ,   _snake_case						:					str=None       ,   **_snake_case						:					Optional[Any]       ,   )      -> Optional[Any]:







								"""simple docstring"""
								super().__init__(
								    pad_token_id=_snake_case       ,   bos_token_id=_snake_case       ,   eos_token_id=_snake_case       ,   **_snake_case       ,   )
								A_				 =						vocab_size
								A_				 =						hidden_size
								A_				 =						num_hidden_layers
								A_				 =						num_attention_heads
								A_				 =						hidden_act
								A_				 =						intermediate_size
								A_				 =						hidden_dropout_prob
								A_				 =						attention_probs_dropout_prob
								A_				 =						max_position_embeddings
								A_				 =						type_vocab_size
								A_				 =						initializer_range
								A_				 =						layer_norm_eps
								A_				 =						position_embedding_type
								A_				 =						use_cache
								A_				 =						classifier_dropout
								# additional properties
								A_				 =						max_depth
								A_				 =						max_xpath_tag_unit_embeddings
								A_				 =						max_xpath_subs_unit_embeddings
								A_				 =						tag_pad_id
								A_				 =						subs_pad_id
								A_				 =						xpath_unit_hidden_size




