




"""simple docstring"""
from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


_SCREAMING_SNAKE_CASE						 =     {
    """configuration_layoutlm""": ["""LAYOUTLM_PRETRAINED_CONFIG_ARCHIVE_MAP""", """LayoutLMConfig""", """LayoutLMOnnxConfig"""],
    """tokenization_layoutlm""": ["""LayoutLMTokenizer"""],
}

try:
    if not is_tokenizers_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    _SCREAMING_SNAKE_CASE						 =     ["""LayoutLMTokenizerFast"""]

try:
    if not is_torch_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    _SCREAMING_SNAKE_CASE						 =     [
        """LAYOUTLM_PRETRAINED_MODEL_ARCHIVE_LIST""",
        """LayoutLMForMaskedLM""",
        """LayoutLMForSequenceClassification""",
        """LayoutLMForTokenClassification""",
        """LayoutLMForQuestionAnswering""",
        """LayoutLMModel""",
        """LayoutLMPreTrainedModel""",
    ]

try:
    if not is_tf_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    _SCREAMING_SNAKE_CASE						 =     [
        """TF_LAYOUTLM_PRETRAINED_MODEL_ARCHIVE_LIST""",
        """TFLayoutLMForMaskedLM""",
        """TFLayoutLMForSequenceClassification""",
        """TFLayoutLMForTokenClassification""",
        """TFLayoutLMForQuestionAnswering""",
        """TFLayoutLMMainLayer""",
        """TFLayoutLMModel""",
        """TFLayoutLMPreTrainedModel""",
    ]


if TYPE_CHECKING:
    from .configuration_layoutlm import LAYOUTLM_PRETRAINED_CONFIG_ARCHIVE_MAP, LayoutLMConfig, LayoutLMOnnxConfig
    from .tokenization_layoutlm import LayoutLMTokenizer

    try:
        if not is_tokenizers_available():
            raise OptionalDependencyNotAvailable()
    except OptionalDependencyNotAvailable:
        pass
    else:
        from .tokenization_layoutlm_fast import LayoutLMTokenizerFast

    try:
        if not is_torch_available():
            raise OptionalDependencyNotAvailable()
    except OptionalDependencyNotAvailable:
        pass
    else:
        from .modeling_layoutlm import (
            LAYOUTLM_PRETRAINED_MODEL_ARCHIVE_LIST,
            LayoutLMForMaskedLM,
            LayoutLMForQuestionAnswering,
            LayoutLMForSequenceClassification,
            LayoutLMForTokenClassification,
            LayoutLMModel,
            LayoutLMPreTrainedModel,
        )
    try:
        if not is_tf_available():
            raise OptionalDependencyNotAvailable()
    except OptionalDependencyNotAvailable:
        pass
    else:
        from .modeling_tf_layoutlm import (
            TF_LAYOUTLM_PRETRAINED_MODEL_ARCHIVE_LIST,
            TFLayoutLMForMaskedLM,
            TFLayoutLMForQuestionAnswering,
            TFLayoutLMForSequenceClassification,
            TFLayoutLMForTokenClassification,
            TFLayoutLMMainLayer,
            TFLayoutLMModel,
            TFLayoutLMPreTrainedModel,
        )

else:
    import sys

    _SCREAMING_SNAKE_CASE						 =     _LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)









"""simple docstring"""
# Lint as: python3

import hashlib
from typing import Union






def 				__lowerCAmelCase					(					__lowerCAmelCase			:		Union[str, int, bytes]						)    ->       bytes:
 if isinstance(__lowerCAmelCase  ,	__lowerCAmelCase						):
  # Data already in bytes, returns as it as
  return hash_data
 elif isinstance(__lowerCAmelCase  ,	__lowerCAmelCase						):
  # We keep the data as it as for it ot be later encoded to UTF-8
  # However replace `\\` with `/` for Windows compatibility
  _UpperCamelCase      :	int					      =  hash_data.replace("\\"  ,	"/"						)
 elif isinstance(__lowerCAmelCase  ,	__lowerCAmelCase						):
  _UpperCamelCase      :	Union[str, Any]					      =  str(__lowerCAmelCase						)
 else:
  # If data is not of the required type, raise error
  raise InvalidKeyError(__lowerCAmelCase						)

 return hash_data.encode("utf-8"						)







class  _SCREAMING_SNAKE_CASE       (     SCREAMING_SNAKE_CASE__				):



 '''simple docstring'''





 def __init__(self					,     lowerCAmelCase__   ):

  '''simple docstring'''







  _UpperCamelCase      :	int					      =  "\nFAILURE TO GENERATE DATASET: Invalid key type detected"
  _UpperCamelCase      :	Tuple					      =  F"\nFound Key {hash_data} of type {type(lowerCAmelCase__   )}"
  _UpperCamelCase      :	str					      =  "\nKeys should be either str, int or bytes type"
  super().__init__(F"{self.prefix}{self.err_msg}{self.suffix}"   )







class  _SCREAMING_SNAKE_CASE       (     SCREAMING_SNAKE_CASE__				):



 '''simple docstring'''





 def __init__(self					,     lowerCAmelCase__					,     lowerCAmelCase__					,     lowerCAmelCase__=""   ):

  '''simple docstring'''







  _UpperCamelCase      :	Optional[int]					      =  key
  _UpperCamelCase      :	Tuple					      =  duplicate_key_indices
  _UpperCamelCase      :	int					      =  fix_msg
  _UpperCamelCase      :	List[Any]					      =  "Found multiple examples generated with the same key"
  if len(lowerCAmelCase__   ) <= 20:
   _UpperCamelCase      :	Optional[Any]					      =  F"\nThe examples at index {', '.join(lowerCAmelCase__   )} have the key {key}"
  else:
   _UpperCamelCase      :	Union[str, Any]					      =  F"\nThe examples at index {', '.join(duplicate_key_indices[:20]   )}... ({len(lowerCAmelCase__   ) - 20} more) have the key {key}"
  _UpperCamelCase      :	List[Any]					      =  "\n" + fix_msg if fix_msg else ""
  super().__init__(F"{self.prefix}{self.err_msg}{self.suffix}"   )







class  _SCREAMING_SNAKE_CASE       :



 '''simple docstring'''





 def __init__(self					,     lowerCAmelCase__   ):

  '''simple docstring'''







  _UpperCamelCase      :	Union[str, Any]					      =  hashlib.mda(_as_bytes(lowerCAmelCase__   )   )






 def lowercase_      (self					,     lowerCAmelCase__   ):

  '''simple docstring'''







  _UpperCamelCase      :	Any					      =  self._split_mda.copy()
  _UpperCamelCase      :	List[str]					      =  _as_bytes(lowerCAmelCase__   )
  mda.update(lowerCAmelCase__   )
  # Convert to integer with hexadecimal conversion
  return int(mda.hexdigest()					,     16   )



