


'''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  UpperCamelCase__(     __lowerCamelCase ):
				__magic_name__       :   Union[str, Any]							= ["image_processor", "tokenizer"]
				__magic_name__       :   int							= "OwlViTImageProcessor"
				__magic_name__       :   str							= ("CLIPTokenizer", "CLIPTokenizerFast")




				def __init__(	self    :				Optional[int]   ,					lowerCAmelCase    :				str=None   ,					lowerCAmelCase    :				List[str]=None   ,					**lowerCAmelCase    :				List[Any]   )->  str:

										"""simple docstring"""




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

										UpperCAmelCase         =			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__(UpperCAmelCase_   ,					UpperCAmelCase_   )




				def __call__(	self    :				Tuple   ,					lowerCAmelCase    :				Optional[int]=None   ,					lowerCAmelCase    :				str=None   ,					lowerCAmelCase    :				int=None   ,					lowerCAmelCase    :				Optional[Any]="max_length"   ,					lowerCAmelCase    :				str="np"   ,					**lowerCAmelCase    :				Optional[Any]   )->  int:

										"""simple docstring"""




										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(UpperCAmelCase_   ,					UpperCAmelCase_   ) or (isinstance(UpperCAmelCase_   ,					UpperCAmelCase_   ) and not isinstance(text[0]   ,					UpperCAmelCase_   )):
																						UpperCAmelCase         =			[self.tokenizer(UpperCAmelCase_   ,					padding=UpperCAmelCase_   ,					return_tensors=UpperCAmelCase_   ,					**UpperCAmelCase_   )]

																elif isinstance(UpperCAmelCase_   ,					UpperCAmelCase_   ) and isinstance(text[0]   ,					UpperCAmelCase_   ):
																						UpperCAmelCase         =			[]

																						# Maximum number of queries across batch
																						UpperCAmelCase         =			max([len(UpperCAmelCase_   ) for t in text]   )

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

																												UpperCAmelCase         =			self.tokenizer(UpperCAmelCase_   ,					padding=UpperCAmelCase_   ,					return_tensors=UpperCAmelCase_   ,					**UpperCAmelCase_   )
																												encodings.append(UpperCAmelCase_   )
																else:
																						raise TypeError('''Input text should be a string, a list of strings or a nested list of strings'''   )

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

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

																						UpperCAmelCase         =			jnp.concatenate([encoding['''input_ids'''] for encoding in encodings]   ,					axis=0   )
																						UpperCAmelCase         =			jnp.concatenate([encoding['''attention_mask'''] for encoding in encodings]   ,					axis=0   )

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

																						UpperCAmelCase         =			torch.cat([encoding['''input_ids'''] for encoding in encodings]   ,					dim=0   )
																						UpperCAmelCase         =			torch.cat([encoding['''attention_mask'''] for encoding in encodings]   ,					dim=0   )

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

																						UpperCAmelCase         =			tf.stack([encoding['''input_ids'''] for encoding in encodings]   ,					axis=0   )
																						UpperCAmelCase         =			tf.stack([encoding['''attention_mask'''] for encoding in encodings]   ,					axis=0   )

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

																UpperCAmelCase         =			BatchEncoding()
																UpperCAmelCase         =			input_ids
																UpperCAmelCase         =			attention_mask

										if query_images is not None:
																UpperCAmelCase         =			BatchEncoding()
																UpperCAmelCase         =			self.image_processor(
																    UpperCAmelCase_   ,					return_tensors=UpperCAmelCase_   ,					**UpperCAmelCase_   ).pixel_values
																UpperCAmelCase         =			query_pixel_values

										if images is not None:
																UpperCAmelCase         =			self.image_processor(UpperCAmelCase_   ,					return_tensors=UpperCAmelCase_   ,					**UpperCAmelCase_   )

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




				def   a__(	self    :				Dict   ,					*lowerCAmelCase    :				Optional[int]   ,					**lowerCAmelCase    :				Union[str, Any]   )->  int:

										"""simple docstring"""




										return self.image_processor.post_process(*UpperCAmelCase_   ,					**UpperCAmelCase_   )




				def   a__(	self    :				int   ,					*lowerCAmelCase    :				List[Any]   ,					**lowerCAmelCase    :				Optional[Any]   )->  Optional[Any]:

										"""simple docstring"""




										return self.image_processor.post_process_object_detection(*UpperCAmelCase_   ,					**UpperCAmelCase_   )




				def   a__(	self    :				Optional[int]   ,					*lowerCAmelCase    :				str   ,					**lowerCAmelCase    :				int   )->  Dict:

										"""simple docstring"""




										return self.image_processor.post_process_image_guided_detection(*UpperCAmelCase_   ,					**UpperCAmelCase_   )




				def   a__(	self    :				int   ,					*lowerCAmelCase    :				Union[str, Any]   ,					**lowerCAmelCase    :				Dict   )->  Dict:

										"""simple docstring"""




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




				def   a__(	self    :				Optional[Any]   ,					*lowerCAmelCase    :				int   ,					**lowerCAmelCase    :				str   )->  Optional[Any]:

										"""simple docstring"""




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




				@property
				def   a__(	self    :				str   )->  Optional[Any]:

										"""simple docstring"""




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





				@property
				def   a__(	self    :				List[Any]   )->  Optional[Any]:

										"""simple docstring"""




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









'''simple docstring'''



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


_lowercase    :    Any			     =  logging.get_logger(__name__)

_lowercase    :    Dict			     =  {
    """facebook/dpr-ctx_encoder-single-nq-base""": (
        """https://huggingface.co/facebook/dpr-ctx_encoder-single-nq-base/resolve/main/config.json"""
    ),
    """facebook/dpr-question_encoder-single-nq-base""": (
        """https://huggingface.co/facebook/dpr-question_encoder-single-nq-base/resolve/main/config.json"""
    ),
    """facebook/dpr-reader-single-nq-base""": (
        """https://huggingface.co/facebook/dpr-reader-single-nq-base/resolve/main/config.json"""
    ),
    """facebook/dpr-ctx_encoder-multiset-base""": (
        """https://huggingface.co/facebook/dpr-ctx_encoder-multiset-base/resolve/main/config.json"""
    ),
    """facebook/dpr-question_encoder-multiset-base""": (
        """https://huggingface.co/facebook/dpr-question_encoder-multiset-base/resolve/main/config.json"""
    ),
    """facebook/dpr-reader-multiset-base""": (
        """https://huggingface.co/facebook/dpr-reader-multiset-base/resolve/main/config.json"""
    ),
}






class  UpperCamelCase__(     lowerCAmelCase ):
				__magic_name__       :   Optional[int]							= "dpr"




				def __init__(	self    :				Dict   ,					lowerCAmelCase    :				Any=30522   ,					lowerCAmelCase    :				List[str]=768   ,					lowerCAmelCase    :				Union[str, Any]=12   ,					lowerCAmelCase    :				Tuple=12   ,					lowerCAmelCase    :				Optional[int]=3072   ,					lowerCAmelCase    :				Optional[int]="gelu"   ,					lowerCAmelCase    :				Optional[Any]=0.1   ,					lowerCAmelCase    :				Any=0.1   ,					lowerCAmelCase    :				Optional[Any]=512   ,					lowerCAmelCase    :				List[Any]=2   ,					lowerCAmelCase    :				Tuple=0.02   ,					lowerCAmelCase    :				str=1E-12   ,					lowerCAmelCase    :				Optional[Any]=0   ,					lowerCAmelCase    :				Tuple="absolute"   ,					lowerCAmelCase    :				int = 0   ,					**lowerCAmelCase    :				Union[str, Any]   ,					)->  Optional[int]:

										"""simple docstring"""




										super().__init__(pad_token_id=lowerCAmelCase   ,					**lowerCAmelCase   )

										UpperCAmelCase         =			vocab_size
										UpperCAmelCase         =			hidden_size
										UpperCAmelCase         =			num_hidden_layers
										UpperCAmelCase         =			num_attention_heads
										UpperCAmelCase         =			hidden_act
										UpperCAmelCase         =			intermediate_size
										UpperCAmelCase         =			hidden_dropout_prob
										UpperCAmelCase         =			attention_probs_dropout_prob
										UpperCAmelCase         =			max_position_embeddings
										UpperCAmelCase         =			type_vocab_size
										UpperCAmelCase         =			initializer_range
										UpperCAmelCase         =			layer_norm_eps
										UpperCAmelCase         =			projection_dim
										UpperCAmelCase         =			position_embedding_type





