




from typing import List, Optional, Union

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






class  __magic_name__						(  __UpperCAmelCase):
				'''simple docstring'''







				SCREAMING_SNAKE_CASE__					:							int	      =					["""image_processor""", """tokenizer"""]
				SCREAMING_SNAKE_CASE__					:							Any	      =					"""BlipImageProcessor"""
				SCREAMING_SNAKE_CASE__					:							Union[str, Any]	      =					"""AutoTokenizer"""


				def __init__(							self:   int		,					_lowerCamelCase:   int		,					_lowerCamelCase:   Any		)     ->   Optional[int]:
											SCREAMING_SNAKE_CASE_   	=    False
											super().__init__(UpperCAmelCase_		,					UpperCAmelCase_		)
											SCREAMING_SNAKE_CASE_   	=    self.image_processor


				def __call__(							self:   Optional[int]		,					_lowerCamelCase:   Dict = None		,					_lowerCamelCase:   Dict = None		,					_lowerCamelCase:   Tuple = True		,					_lowerCamelCase:   List[str] = False		,					_lowerCamelCase:   int = None		,					_lowerCamelCase:   List[str] = None		,					_lowerCamelCase:   int = 0		,					_lowerCamelCase:   int = None		,					_lowerCamelCase:   Any = None		,					_lowerCamelCase:   Any = False		,					_lowerCamelCase:   Union[str, Any] = False		,					_lowerCamelCase:   Union[str, Any] = False		,					_lowerCamelCase:   str = False		,					_lowerCamelCase:   Tuple = False		,					_lowerCamelCase:   Tuple = True		,					_lowerCamelCase:   Optional[Any] = None		,					**_lowerCamelCase:   str		,					)     ->   Any:
											if images is None and text is None:
																		raise ValueError('''You have to specify either images or text.'''		)

											# Get only text
											if images is None:
																		SCREAMING_SNAKE_CASE_   	=    self.tokenizer
																		SCREAMING_SNAKE_CASE_   	=    self.tokenizer(
																		    text=UpperCAmelCase_		,					add_special_tokens=UpperCAmelCase_		,					padding=UpperCAmelCase_		,					truncation=UpperCAmelCase_		,					max_length=UpperCAmelCase_		,					stride=UpperCAmelCase_		,					pad_to_multiple_of=UpperCAmelCase_		,					return_attention_mask=UpperCAmelCase_		,					return_overflowing_tokens=UpperCAmelCase_		,					return_special_tokens_mask=UpperCAmelCase_		,					return_offsets_mapping=UpperCAmelCase_		,					return_token_type_ids=UpperCAmelCase_		,					return_length=UpperCAmelCase_		,					verbose=UpperCAmelCase_		,					return_tensors=UpperCAmelCase_		,					**UpperCAmelCase_		,					)
																		return text_encoding

											# add pixel_values
											SCREAMING_SNAKE_CASE_   	=    self.image_processor(UpperCAmelCase_		,					return_tensors=UpperCAmelCase_		)

											if text is not None:
																		SCREAMING_SNAKE_CASE_   	=    self.tokenizer(
																		    text=UpperCAmelCase_		,					add_special_tokens=UpperCAmelCase_		,					padding=UpperCAmelCase_		,					truncation=UpperCAmelCase_		,					max_length=UpperCAmelCase_		,					stride=UpperCAmelCase_		,					pad_to_multiple_of=UpperCAmelCase_		,					return_attention_mask=UpperCAmelCase_		,					return_overflowing_tokens=UpperCAmelCase_		,					return_special_tokens_mask=UpperCAmelCase_		,					return_offsets_mapping=UpperCAmelCase_		,					return_token_type_ids=UpperCAmelCase_		,					return_length=UpperCAmelCase_		,					verbose=UpperCAmelCase_		,					return_tensors=UpperCAmelCase_		,					**UpperCAmelCase_		,					)
											else:
																		SCREAMING_SNAKE_CASE_   	=    None

											if text_encoding is not None:
																		encoding_image_processor.update(UpperCAmelCase_		)

											return encoding_image_processor


				def     _A							(							self:   List[str]		,					*_lowerCamelCase:   List[Any]		,					**_lowerCamelCase:   Optional[int]		)     ->   Dict:
											return self.tokenizer.batch_decode(*UpperCAmelCase_		,					**UpperCAmelCase_		)


				def     _A							(							self:   Any		,					*_lowerCamelCase:   Optional[Any]		,					**_lowerCamelCase:   Optional[Any]		)     ->   int:
											return self.tokenizer.decode(*UpperCAmelCase_		,					**UpperCAmelCase_		)





				@property
				# Copied from transformers.models.blip.processing_blip.BlipProcessor.model_input_names
				def     _A							(							self:   List[str]		)     ->   Tuple:
											SCREAMING_SNAKE_CASE_   	=    self.tokenizer.model_input_names
											SCREAMING_SNAKE_CASE_   	=    self.image_processor.model_input_names
											return list(dict.fromkeys(tokenizer_input_names + image_processor_input_names		)		)








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


__SCREAMING_SNAKE_CASE 						=logging.get_logger(__name__)

__SCREAMING_SNAKE_CASE 						={
    """google/realm-cc-news-pretrained-embedder""": (
        """https://huggingface.co/google/realm-cc-news-pretrained-embedder/resolve/main/config.json"""
    ),
    """google/realm-cc-news-pretrained-encoder""": (
        """https://huggingface.co/google/realm-cc-news-pretrained-encoder/resolve/main/config.json"""
    ),
    """google/realm-cc-news-pretrained-scorer""": (
        """https://huggingface.co/google/realm-cc-news-pretrained-scorer/resolve/main/config.json"""
    ),
    """google/realm-cc-news-pretrained-openqa""": (
        """https://huggingface.co/google/realm-cc-news-pretrained-openqa/aresolve/main/config.json"""
    ),
    """google/realm-orqa-nq-openqa""": """https://huggingface.co/google/realm-orqa-nq-openqa/resolve/main/config.json""",
    """google/realm-orqa-nq-reader""": """https://huggingface.co/google/realm-orqa-nq-reader/resolve/main/config.json""",
    """google/realm-orqa-wq-openqa""": """https://huggingface.co/google/realm-orqa-wq-openqa/resolve/main/config.json""",
    """google/realm-orqa-wq-reader""": """https://huggingface.co/google/realm-orqa-wq-reader/resolve/main/config.json""",
    # See all REALM models at https://huggingface.co/models?filter=realm
}






class  __magic_name__						(  __UpperCAmelCase):
				'''simple docstring'''







				SCREAMING_SNAKE_CASE__					:							int	      =					"realm"


				def __init__(							self:   Tuple		,					_lowerCamelCase:   Union[str, Any]=3_05_22		,					_lowerCamelCase:   Tuple=7_68		,					_lowerCamelCase:   str=1_28		,					_lowerCamelCase:   str=12		,					_lowerCamelCase:   int=12		,					_lowerCamelCase:   Union[str, Any]=8		,					_lowerCamelCase:   Optional[Any]=30_72		,					_lowerCamelCase:   str="gelu_new"		,					_lowerCamelCase:   str=0.1		,					_lowerCamelCase:   Union[str, Any]=0.1		,					_lowerCamelCase:   Optional[int]=5_12		,					_lowerCamelCase:   Union[str, Any]=2		,					_lowerCamelCase:   int=0.02		,					_lowerCamelCase:   Tuple=1E-12		,					_lowerCamelCase:   List[Any]=2_56		,					_lowerCamelCase:   Any=10		,					_lowerCamelCase:   Optional[Any]=1E-3		,					_lowerCamelCase:   Any=5		,					_lowerCamelCase:   List[str]=3_20		,					_lowerCamelCase:   List[str]=13_35_37_18		,					_lowerCamelCase:   str=50_00		,					_lowerCamelCase:   str=1		,					_lowerCamelCase:   str=0		,					_lowerCamelCase:   Dict=2		,					**_lowerCamelCase:   Tuple		,					):
											super().__init__(pad_token_id=_lowerCamelCase		,					bos_token_id=_lowerCamelCase		,					eos_token_id=_lowerCamelCase		,					**_lowerCamelCase		)

											# Common config
											SCREAMING_SNAKE_CASE_   	=    vocab_size
											SCREAMING_SNAKE_CASE_   	=    max_position_embeddings
											SCREAMING_SNAKE_CASE_   	=    hidden_size
											SCREAMING_SNAKE_CASE_   	=    retriever_proj_size
											SCREAMING_SNAKE_CASE_   	=    num_hidden_layers
											SCREAMING_SNAKE_CASE_   	=    num_attention_heads
											SCREAMING_SNAKE_CASE_   	=    num_candidates
											SCREAMING_SNAKE_CASE_   	=    intermediate_size
											SCREAMING_SNAKE_CASE_   	=    hidden_act
											SCREAMING_SNAKE_CASE_   	=    hidden_dropout_prob
											SCREAMING_SNAKE_CASE_   	=    attention_probs_dropout_prob
											SCREAMING_SNAKE_CASE_   	=    initializer_range
											SCREAMING_SNAKE_CASE_   	=    type_vocab_size
											SCREAMING_SNAKE_CASE_   	=    layer_norm_eps

											# Reader config
											SCREAMING_SNAKE_CASE_   	=    span_hidden_size
											SCREAMING_SNAKE_CASE_   	=    max_span_width
											SCREAMING_SNAKE_CASE_   	=    reader_layer_norm_eps
											SCREAMING_SNAKE_CASE_   	=    reader_beam_size
											SCREAMING_SNAKE_CASE_   	=    reader_seq_len

											# Retrieval config
											SCREAMING_SNAKE_CASE_   	=    num_block_records
											SCREAMING_SNAKE_CASE_   	=    searcher_beam_size


