
'''simple docstring'''





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


SCREAMING_SNAKE_CASE     =       logging.get_logger(__name__)

SCREAMING_SNAKE_CASE     =       {
    '''unc-nlp/lxmert-base-uncased''': '''https://huggingface.co/unc-nlp/lxmert-base-uncased/resolve/main/config.json''',
}






class 							UpperCAmelCase_							(    A				):

 '''simple docstring'''
 lowercase_					:    List[Any]				=							"lxmert"
 lowercase_					:    Union[str, Any]				=							{}







 def __init__(					self		:  List[str]			,				snake_case__		:  Any=3_05_22			,				snake_case__		:  Dict=7_68			,				snake_case__		:  List[str]=12			,				snake_case__		:  Tuple=95_00			,				snake_case__		:  Optional[Any]=16_00			,				snake_case__		:  Union[str, Any]=4_00			,				snake_case__		:  Union[str, Any]=30_72			,				snake_case__		:  Tuple="gelu"			,				snake_case__		:  Tuple=0.1			,				snake_case__		:  int=0.1			,				snake_case__		:  str=5_12			,				snake_case__		:  Dict=2			,				snake_case__		:  Union[str, Any]=0.02			,				snake_case__		:  List[Any]=1e-12			,				snake_case__		:  Any=9			,				snake_case__		:  str=5			,				snake_case__		:  Any=5			,				snake_case__		:  Optional[Any]=20_48			,				snake_case__		:  str=4			,				snake_case__		:  str=6.67			,				snake_case__		:  List[Any]=True			,				snake_case__		:  Optional[Any]=True			,				snake_case__		:  Any=True			,				snake_case__		:  str=True			,				snake_case__		:  List[Any]=True			,				snake_case__		:  int=True			,				snake_case__		:  Dict=True			,				**snake_case__		:  str			,				):



   '''simple docstring'''




   UpperCAmelCase__      :					Union[str, Any]				       =							vocab_size
   UpperCAmelCase__      :					Tuple				       =							hidden_size
   UpperCAmelCase__      :					int				       =							num_attention_heads
   UpperCAmelCase__      :					int				       =							hidden_act
   UpperCAmelCase__      :					Optional[int]				       =							intermediate_size
   UpperCAmelCase__      :					Optional[int]				       =							hidden_dropout_prob
   UpperCAmelCase__      :					Any				       =							attention_probs_dropout_prob
   UpperCAmelCase__      :					Optional[int]				       =							max_position_embeddings
   UpperCAmelCase__      :					Dict				       =							type_vocab_size
   UpperCAmelCase__      :					Union[str, Any]				       =							initializer_range
   UpperCAmelCase__      :					List[Any]				       =							layer_norm_eps
   UpperCAmelCase__      :					Dict				       =							num_qa_labels
   UpperCAmelCase__      :					Any				       =							num_object_labels
   UpperCAmelCase__      :					Optional[int]				       =							num_attr_labels
   UpperCAmelCase__      :					Union[str, Any]				       =							l_layers
   UpperCAmelCase__      :					Any				       =							x_layers
   UpperCAmelCase__      :					Optional[int]				       =							r_layers
   UpperCAmelCase__      :					Any				       =							visual_feat_dim
   UpperCAmelCase__      :					Any				       =							visual_pos_dim
   UpperCAmelCase__      :					List[str]				       =							visual_loss_normalizer
   UpperCAmelCase__      :					Optional[Any]				       =							task_matched
   UpperCAmelCase__      :					int				       =							task_mask_lm
   UpperCAmelCase__      :					str				       =							task_obj_predict
   UpperCAmelCase__      :					Tuple				       =							task_qa
   UpperCAmelCase__      :					Tuple				       =							visual_obj_loss
   UpperCAmelCase__      :					List[Any]				       =							visual_attr_loss
   UpperCAmelCase__      :					Union[str, Any]				       =							visual_feat_loss
   UpperCAmelCase__      :					Dict				       =							{"vision": r_layers, "cross_encoder": x_layers, "language": l_layers}
   super().__init__(**lowercase__ )






import warnings
from typing import List, Optional, Union

from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding, PaddingStrategy, PreTokenizedInput, TextInput, TruncationStrategy
from ...utils import TensorType





class        lowerCAmelCase__  (					__magic_name__			):



       '''simple docstring'''







       lowercase_						=    ["""image_processor""", """tokenizer"""]
       lowercase_						=    """LayoutLMv2ImageProcessor"""
       lowercase_						=    ("""LayoutXLMTokenizer""", """LayoutXLMTokenizerFast""")

       def __init__(							self ,   lowercase__=None ,   lowercase__=None ,   **lowercase__     ):







             '''simple docstring'''



             if "feature_extractor" in kwargs:
                   warnings.warn(
                       '''The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor`'''
                       ''' instead.''' ,   lowercase__ ,   )
                   __A    =kwargs.pop('''feature_extractor'''     )

             __A    =image_processor if image_processor is not None else feature_extractor
             if image_processor is None:
                   raise ValueError('''You need to specify an `image_processor`.'''     )
             if tokenizer is None:
                   raise ValueError('''You need to specify a `tokenizer`.'''     )

             super().__init__(lowercase__ ,   lowercase__     )

       def __call__(							self ,   lowercase__ ,   lowercase__ = None ,   lowercase__ = None ,   lowercase__ = None ,   lowercase__ = None ,   lowercase__ = True ,   lowercase__ = False ,   lowercase__ = None ,   lowercase__ = None ,   lowercase__ = 0 ,   lowercase__ = None ,   lowercase__ = None ,   lowercase__ = None ,   lowercase__ = False ,   lowercase__ = False ,   lowercase__ = False ,   lowercase__ = False ,   lowercase__ = True ,   lowercase__ = None ,   **lowercase__ ,   ):







             '''simple docstring'''



             if self.image_processor.apply_ocr and (boxes is not None):
                   raise ValueError(
                       '''You cannot provide bounding boxes '''
                       '''if you initialized the image processor with apply_ocr set to True.'''     )

             if self.image_processor.apply_ocr and (word_labels is not None):
                   raise ValueError(
                       '''You cannot provide word labels if you initialized the image processor with apply_ocr set to True.'''     )

             if return_overflowing_tokens is True and return_offsets_mapping is False:
                   raise ValueError('''You cannot return overflowing tokens without returning the offsets mapping.'''     )

             # first, apply the image processor
             __A    =self.image_processor(images=lowercase__ ,   return_tensors=lowercase__     )

             # second, apply the tokenizer
             if text is not None and self.image_processor.apply_ocr and text_pair is None:
                   if isinstance(lowercase__ ,   lowercase__     ):
                         __A    =[text]  # add batch dimension (as the image processor always adds a batch dimension)
                   __A    =features['''words''']

             __A    =self.tokenizer(
                 text=text if text is not None else features['''words'''] ,   text_pair=text_pair if text_pair is not None else None ,   boxes=boxes if boxes is not None else features['''boxes'''] ,   word_labels=lowercase__ ,   add_special_tokens=lowercase__ ,   padding=lowercase__ ,   truncation=lowercase__ ,   max_length=lowercase__ ,   stride=lowercase__ ,   pad_to_multiple_of=lowercase__ ,   return_token_type_ids=lowercase__ ,   return_attention_mask=lowercase__ ,   return_overflowing_tokens=lowercase__ ,   return_special_tokens_mask=lowercase__ ,   return_offsets_mapping=lowercase__ ,   return_length=lowercase__ ,   verbose=lowercase__ ,   return_tensors=lowercase__ ,   **lowercase__ ,   )

             # add pixel values
             __A    =features.pop('''pixel_values'''     )
             if return_overflowing_tokens is True:
                   __A    =self.get_overflowing_images(lowercase__ ,   encoded_inputs['''overflow_to_sample_mapping''']     )
             __A    =images

             return encoded_inputs

       def     __UpperCamelCase     (							self ,   lowercase__ ,   lowercase__     ):







             '''simple docstring'''



             __A    =[]
             for sample_idx in overflow_to_sample_mapping:
                   images_with_overflow.append(images[sample_idx]     )

             if len(lowercase__     ) != len(lowercase__     ):
                   raise ValueError(
                       '''Expected length of images to be the same as the length of `overflow_to_sample_mapping`, but got'''
                       f''' {len(lowercase__     )} and {len(lowercase__     )}'''     )

             return images_with_overflow

       def     __UpperCamelCase     (							self ,   *lowercase__ ,   **lowercase__     ):







             '''simple docstring'''



             return self.tokenizer.batch_decode(*lowercase__ ,   **lowercase__     )

       def     __UpperCamelCase     (							self ,   *lowercase__ ,   **lowercase__     ):







             '''simple docstring'''



             return self.tokenizer.decode(*lowercase__ ,   **lowercase__     )

       @property
       def     __UpperCamelCase     (							self     ):







             '''simple docstring'''



             return ["input_ids", "bbox", "attention_mask", "image"]

       @property
       def     __UpperCamelCase     (							self     ):







             '''simple docstring'''



             warnings.warn(
                 '''`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead.''' ,   lowercase__ ,   )
             return self.image_processor_class


       @property
       def     __UpperCamelCase     (							self     ):







             '''simple docstring'''



             warnings.warn(
                 '''`feature_extractor` is deprecated and will be removed in v5. Use `image_processor` instead.''' ,   lowercase__ ,   )
             return self.image_processor


