


'''simple docstring'''



from typing import List, Union

from ..utils import (
    add_end_docstrings,
    is_tf_available,
    is_torch_available,
    is_vision_available,
    logging,
    requires_backends,
)
from .base import PIPELINE_INIT_ARGS, Pipeline


if is_vision_available():
					from PIL import Image

					from ..image_utils import load_image

if is_tf_available():
					import tensorflow as tf

					from ..models.auto.modeling_tf_auto import TF_MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING
					from ..tf_utils import stable_softmax

if is_torch_available():
					from ..models.auto.modeling_auto import MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING

_lowercase    :    int			     =  logging.get_logger(__name__)






@add_end_docstrings(_UpperCamelCase )
class  UpperCamelCase__(     _UpperCamelCase ):




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

										"""simple docstring"""




										super().__init__(*__a   ,					**__a   )
										requires_backends(self   ,					'''vision'''   )
										self.check_model_type(
										    TF_MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING
										    if self.framework == '''tf'''
										    else MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING   )




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

										"""simple docstring"""




										UpperCAmelCase         =			{}
										if top_k is not None:
																UpperCAmelCase         =			top_k
										return {}, {}, postprocess_params




				def __call__(	self    :				List[Any]   ,					lowerCAmelCase    :				Union[str, List[str], "Image.Image", List["Image.Image"]]   ,					**lowerCAmelCase    :				str   )->  Any:

										"""simple docstring"""




										return super().__call__(__a   ,					**__a   )




				def   a__(	self    :				Any   ,					lowerCAmelCase    :				Dict   )->  List[Any]:

										"""simple docstring"""




										UpperCAmelCase         =			load_image(__a   )
										UpperCAmelCase         =			self.image_processor(images=__a   ,					return_tensors=self.framework   )
										return model_inputs




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

										"""simple docstring"""




										UpperCAmelCase         =			self.model(**__a   )
										return model_outputs





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

										"""simple docstring"""




										if top_k > self.model.config.num_labels:
																UpperCAmelCase         =			self.model.config.num_labels

										if self.framework == "pt":
																UpperCAmelCase         =			model_outputs.logits.softmax(-1   )[0]
																UpperCAmelCase         =			probs.topk(__a   )
										elif self.framework == "tf":
																UpperCAmelCase         =			stable_softmax(model_outputs.logits   ,					axis=-1   )[0]
																UpperCAmelCase         =			tf.math.top_k(__a   ,					k=__a   )
																UpperCAmelCase         =			topk.values.numpy(), topk.indices.numpy()
										else:
																raise ValueError(F"""Unsupported framework: {self.framework}"""   )

										UpperCAmelCase         =			scores.tolist()
										UpperCAmelCase         =			ids.tolist()
										return [{"score": score, "label": self.model.config.idalabel[_id]} for score, _id in zip(__a   ,					__a   )]









'''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





