


"""simple docstring"""


import re
import warnings
from contextlib import contextmanager

from ...processing_utils import ProcessorMixin


class 			A__	(						__lowercase):


     """simple docstring"""
     snake_case__	:					Tuple													=['''image_processor''', '''tokenizer''']
     snake_case__	:					Optional[Any]													='''AutoImageProcessor'''
     snake_case__	:					List[str]													='''AutoTokenizer'''

     def __init__(	self:						str     ,		__a:						str=None     ,		__a:						Optional[Any]=None     ,		**__a:						Union[str, Any]	)->    Tuple:
           lowerCamelCase					:					int        =	None
           if "feature_extractor" in kwargs:
                 warnings.warn(
                     """The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor`"""
                     """ instead."""     ,		__a     ,		)
                 lowerCamelCase					:					str        =	kwargs.pop("""feature_extractor"""	)

           lowerCamelCase					:					List[Any]        =	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__(__a     ,		__a	)
           lowerCamelCase					:					Any        =	self.image_processor
           lowerCamelCase					:					Any        =	False

     def __call__(	self:						Dict     ,		*__a:						Optional[Any]     ,		**__a:						int	)->    Optional[Any]:
           # For backward compatibility
           if self._in_target_context_manager:
                 return self.current_processor(*__a     ,		**__a	)

           lowerCamelCase					:					List[Any]        =	kwargs.pop("""images"""     ,		__a	)
           lowerCamelCase					:					List[str]        =	kwargs.pop("""text"""     ,		__a	)
           if len(__a	) > 0:
                 lowerCamelCase					:					Any        =	args[0]
                 lowerCamelCase					:					List[Any]        =	args[1:]

           if images is None and text is None:
                 raise ValueError("""You need to specify either an `images` or `text` input to process."""	)

           if images is not None:
                 lowerCamelCase					:					str        =	self.image_processor(__a     ,		*__a     ,		**__a	)
           if text is not None:
                 lowerCamelCase					:					Union[str, Any]        =	self.tokenizer(__a     ,		**__a	)

           if text is None:
                 return inputs
           elif images is None:
                 return encodings
           else:
                 lowerCamelCase					:					List[Any]        =	encodings["""input_ids"""]
                 return inputs

     def 		a__						(	self:						List[str]     ,		*__a:						Tuple     ,		**__a:						Optional[int]	)->    Union[str, Any]:
           return self.tokenizer.batch_decode(*__a     ,		**__a	)

     def 		a__						(	self:						Union[str, Any]     ,		*__a:						int     ,		**__a:						int	)->    Union[str, Any]:
           return self.tokenizer.decode(*__a     ,		**__a	)

     @contextmanager
     def 		a__						(	self:						Dict	)->    int:
           warnings.warn(
               """`as_target_processor` is deprecated and will be removed in v5 of Transformers. You can process your """
               """labels by using the argument `text` of the regular `__call__` method (either in the same call as """
               """your images inputs, or in a separate call."""	)
           lowerCamelCase					:					List[str]        =	True
           lowerCamelCase					:					int        =	self.tokenizer
           yield
           lowerCamelCase					:					str        =	self.image_processor
           lowerCamelCase					:					Union[str, Any]        =	False

     def 		a__						(	self:						int     ,		__a:						List[str]     ,		__a:						List[Any]=False     ,		__a:						Optional[int]=None	)->    Union[str, Any]:
           if added_vocab is None:
                 lowerCamelCase					:					Optional[Any]        =	self.tokenizer.get_added_vocab()

           lowerCamelCase					:					Dict        =	{}

           while tokens:
                 lowerCamelCase					:					Union[str, Any]        =	re.search(r"""<s_(.*?)>"""     ,		__a     ,		re.IGNORECASE	)
                 if start_token is None:
                       break
                 lowerCamelCase					:					List[Any]        =	start_token.group(1	)
                 lowerCamelCase					:					Optional[int]        =	re.search(rf'</s_{key}>'     ,		__a     ,		re.IGNORECASE	)
                 lowerCamelCase					:					int        =	start_token.group()
                 if end_token is None:
                       lowerCamelCase					:					Any        =	tokens.replace(__a     ,		""""""	)
                 else:
                       lowerCamelCase					:					Any        =	end_token.group()
                       lowerCamelCase					:					Tuple        =	re.escape(__a	)
                       lowerCamelCase					:					Optional[Any]        =	re.escape(__a	)
                       lowerCamelCase					:					Dict        =	re.search(f'{start_token_escaped}(.*?){end_token_escaped}'     ,		__a     ,		re.IGNORECASE	)
                       if content is not None:
                             lowerCamelCase					:					List[str]        =	content.group(1	).strip()
                             if r"<s_" in content and r"</s_" in content:  # non-leaf node
                                   lowerCamelCase					:					Any        =	self.tokenajson(__a     ,		is_inner_value=__a     ,		added_vocab=__a	)
                                   if value:
                                         if len(__a	) == 1:
                                               lowerCamelCase					:					str        =	value[0]
                                         lowerCamelCase					:					List[Any]        =	value
                             else:  # leaf nodes
                                   lowerCamelCase					:					List[Any]        =	[]
                                   for leaf in content.split(r"""<sep/>"""	):
                                         lowerCamelCase					:					Optional[Any]        =	leaf.strip()
                                         if leaf in added_vocab and leaf[0] == "<" and leaf[-2:] == "/>":
                                               lowerCamelCase					:					Optional[Any]        =	leaf[1:-2]  # for categorical special tokens
                                         output[key].append(__a	)
                                   if len(output[key]	) == 1:
                                         lowerCamelCase					:					Optional[Any]        =	output[key][0]

                       lowerCamelCase					:					Tuple        =	tokens[tokens.find(__a	) + len(__a	) :].strip()
                       if tokens[:6] == r"<sep/>":  # non-leaf nodes
                             return [output] + self.tokenajson(tokens[6:]     ,		is_inner_value=__a     ,		added_vocab=__a	)

           if len(__a	):
                 return [output] if is_inner_value else output
           else:
                 return [] if is_inner_value else {"text_sequence": tokens}

     @property
     def 		a__						(	self:						List[str]	)->    Union[str, Any]:
           warnings.warn(
               """`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead."""     ,		__a     ,		)
           return self.image_processor_class







     @property
     def 		a__						(	self:						Dict	)->    Union[str, Any]:
           warnings.warn(
               """`feature_extractor` is deprecated and will be removed in v5. Use `image_processor` instead."""     ,		__a     ,		)
           return self.image_processor








"""simple docstring"""


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


__lowerCamelCase      :Optional[int]	    =		logging.get_logger(__name__)

__lowerCamelCase      :List[str]	    =		{
    '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 			A__	(						__lowercase):


     """simple docstring"""
     snake_case__	:					Optional[Any]													='''realm'''

     def __init__(	self:						Union[str, Any]     ,		__a:						List[Any]=30_522     ,		__a:						List[Any]=768     ,		__a:						List[Any]=128     ,		__a:						Union[str, Any]=12     ,		__a:						Union[str, Any]=12     ,		__a:						Optional[Any]=8     ,		__a:						Dict=3_072     ,		__a:						List[Any]="gelu_new"     ,		__a:						List[Any]=0.1     ,		__a:						Tuple=0.1     ,		__a:						Optional[Any]=512     ,		__a:						Optional[int]=2     ,		__a:						str=0.02     ,		__a:						int=1e-1_2     ,		__a:						Optional[Any]=256     ,		__a:						Any=10     ,		__a:						Dict=1e-3     ,		__a:						Optional[Any]=5     ,		__a:						Dict=320     ,		__a:						Tuple=13_353_718     ,		__a:						List[Any]=5_000     ,		__a:						Dict=1     ,		__a:						int=0     ,		__a:						Dict=2     ,		**__a:						List[str]     ,		)->    Any:
           super().__init__(pad_token_id=__a     ,		bos_token_id=__a     ,		eos_token_id=__a     ,		**__a	)

           # Common config
           lowerCamelCase					:					Optional[Any]        =	vocab_size
           lowerCamelCase					:					str        =	max_position_embeddings
           lowerCamelCase					:					Dict        =	hidden_size
           lowerCamelCase					:					Dict        =	retriever_proj_size
           lowerCamelCase					:					Optional[Any]        =	num_hidden_layers
           lowerCamelCase					:					List[str]        =	num_attention_heads
           lowerCamelCase					:					Tuple        =	num_candidates
           lowerCamelCase					:					int        =	intermediate_size
           lowerCamelCase					:					Dict        =	hidden_act
           lowerCamelCase					:					List[str]        =	hidden_dropout_prob
           lowerCamelCase					:					Dict        =	attention_probs_dropout_prob
           lowerCamelCase					:					Optional[int]        =	initializer_range
           lowerCamelCase					:					Dict        =	type_vocab_size
           lowerCamelCase					:					Optional[Any]        =	layer_norm_eps

           # Reader config
           lowerCamelCase					:					List[str]        =	span_hidden_size
           lowerCamelCase					:					Dict        =	max_span_width
           lowerCamelCase					:					Optional[Any]        =	reader_layer_norm_eps
           lowerCamelCase					:					Optional[int]        =	reader_beam_size
           lowerCamelCase					:					List[Any]        =	reader_seq_len

           # Retrieval config
           lowerCamelCase					:					int        =	num_block_records
           lowerCamelCase					:					Dict        =	searcher_beam_size




