



"""simple docstring"""
import warnings
from typing import List

import numpy as np

from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding
from ...utils import is_flax_available, is_tf_available, is_torch_available




class 			snake_case_						(						a_				):
       __lowerCAmelCase    					=					["image_processor", "tokenizer"]
       __lowerCAmelCase    					=					"OwlViTImageProcessor"
       __lowerCAmelCase    					=					("CLIPTokenizer", "CLIPTokenizerFast")






       def __init__(   self			,     a_=None			,     a_=None			,     **a_      ):
         a_     :      Tuple 						=     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_			,     )
           a_     :      Dict 						=     kwargs.pop("feature_extractor"      )

         a_     :      Optional[int] 						=     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_      )






       def __call__(   self			,     a_=None			,     a_=None			,     a_=None			,     a_="max_length"			,     a_="np"			,     **a_      ):

         if text is None and query_images is None and images is None:
           raise ValueError(
               "You have to specify at least one text or query image or image. All three cannot be none."      )

         if text is not None:
           if isinstance(a_			,     a_      ) or (isinstance(a_			,     a_      ) and not isinstance(text[0]			,     a_      )):
             a_     :      int 						=     [self.tokenizer(a_			,     padding=a_			,     return_tensors=a_			,     **a_      )]

           elif isinstance(a_			,     a_      ) and isinstance(text[0]			,     a_      ):
             a_     :      Tuple 						=     []

             # Maximum number of queries across batch
             a_     :      Union[str, Any] 						=     max([len(a_      ) for t in text]      )

             # Pad all batch samples to max number of text queries
             for t in text:
               if len(a_      ) != max_num_queries:
                 a_     :      Any 						=     t + [" "] * (max_num_queries - len(a_      ))

               a_     :      Optional[Any] 						=     self.tokenizer(a_			,     padding=a_			,     return_tensors=a_			,     **a_      )
               encodings.append(a_      )
           else:
             raise TypeError("Input text should be a string, a list of strings or a nested list of strings"      )

           if return_tensors == "np":
             a_     :      Dict 						=     np.concatenate([encoding["input_ids"] for encoding in encodings]			,     axis=0      )
             a_     :      Tuple 						=     np.concatenate([encoding["attention_mask"] for encoding in encodings]			,     axis=0      )

           elif return_tensors == "jax" and is_flax_available():
             import jax.numpy as jnp

             a_     :      int 						=     jnp.concatenate([encoding["input_ids"] for encoding in encodings]			,     axis=0      )
             a_     :      int 						=     jnp.concatenate([encoding["attention_mask"] for encoding in encodings]			,     axis=0      )

           elif return_tensors == "pt" and is_torch_available():
             import torch

             a_     :      List[str] 						=     torch.cat([encoding["input_ids"] for encoding in encodings]			,     dim=0      )
             a_     :      int 						=     torch.cat([encoding["attention_mask"] for encoding in encodings]			,     dim=0      )

           elif return_tensors == "tf" and is_tf_available():
             import tensorflow as tf

             a_     :      Optional[int] 						=     tf.stack([encoding["input_ids"] for encoding in encodings]			,     axis=0      )
             a_     :      int 						=     tf.stack([encoding["attention_mask"] for encoding in encodings]			,     axis=0      )

           else:
             raise ValueError("Target return tensor type could not be returned"      )

           a_     :      Any 						=     BatchEncoding()
           a_     :      Optional[Any] 						=     input_ids
           a_     :      Tuple 						=     attention_mask

         if query_images is not None:
           a_     :      List[str] 						=     BatchEncoding()
           a_     :      Union[str, Any] 						=     self.image_processor(
               a_			,     return_tensors=a_			,     **a_      ).pixel_values
           a_     :      Tuple 						=     query_pixel_values

         if images is not None:
           a_     :      str 						=     self.image_processor(a_			,     return_tensors=a_			,     **a_      )

         if text is not None and images is not None:
           a_     :      Tuple 						=     image_features.pixel_values
           return encoding
         elif query_images is not None and images is not None:
           a_     :      int 						=     image_features.pixel_values
           return encoding
         elif text is not None or query_images is not None:
           return encoding
         else:
           return BatchEncoding(data=dict(**a_      )			,     tensor_type=a_      )






       def snake_case_  (   self			,     *a_			,     **a_      ):
         return self.image_processor.post_process(*a_			,     **a_      )






       def snake_case_  (   self			,     *a_			,     **a_      ):
         return self.image_processor.post_process_object_detection(*a_			,     **a_      )






       def snake_case_  (   self			,     *a_			,     **a_      ):
         return self.image_processor.post_process_image_guided_detection(*a_			,     **a_      )






       def snake_case_  (   self			,     *a_			,     **a_      ):
         return self.tokenizer.batch_decode(*a_			,     **a_      )






       def snake_case_  (   self			,     *a_			,     **a_      ):
         return self.tokenizer.decode(*a_			,     **a_      )






       @property
       def snake_case_  (   self      ):
         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 snake_case_  (   self      ):
         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


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 			snake_case_						(						a_				):
							__lowerCAmelCase    					=					"realm"






							def __init__(   self			,     a_=3_0_5_2_2			,     a_=7_6_8			,     a_=1_2_8			,     a_=1_2			,     a_=1_2			,     a_=8			,     a_=3_0_7_2			,     a_="gelu_new"			,     a_=0.1			,     a_=0.1			,     a_=5_1_2			,     a_=2			,     a_=0.02			,     a_=1e-12			,     a_=2_5_6			,     a_=1_0			,     a_=1e-3			,     a_=5			,     a_=3_2_0			,     a_=1_3_3_5_3_7_1_8			,     a_=5_0_0_0			,     a_=1			,     a_=0			,     a_=2			,     **a_			,     ):
									super().__init__(pad_token_id=a_			,     bos_token_id=a_			,     eos_token_id=a_			,     **a_      )

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

									# Reader config
									a_     :      str 						=     span_hidden_size
									a_     :      Union[str, Any] 						=     max_span_width
									a_     :      Tuple 						=     reader_layer_norm_eps
									a_     :      List[Any] 						=     reader_beam_size
									a_     :      str 						=     reader_seq_len

									# Retrieval config
									a_     :      str 						=     num_block_records
									a_     :      int 						=     searcher_beam_size