

import copy
import os
from typing import Union

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


a__												=						logging.get_logger(__name__)

a__												=						{
    '''Salesforce/blip-vqa-base''': '''https://huggingface.co/Salesforce/blip-vqa-base/resolve/main/config.json''',
    '''Salesforce/blip-vqa-capfit-large''': (
        '''https://huggingface.co/Salesforce/blip-vqa-base-capfit/resolve/main/config.json'''
    ),
    '''Salesforce/blip-image-captioning-base''': (
        '''https://huggingface.co/Salesforce/blip-image-captioning-base/resolve/main/config.json'''
    ),
    '''Salesforce/blip-image-captioning-large''': (
        '''https://huggingface.co/Salesforce/blip-image-captioning-large/resolve/main/config.json'''
    ),
    '''Salesforce/blip-itm-base-coco''': '''https://huggingface.co/Salesforce/blip-itm-base-coco/resolve/main/config.json''',
    '''Salesforce/blip-itm-large-coco''': '''https://huggingface.co/Salesforce/blip-itm-large-coco/resolve/main/config.json''',
    '''Salesforce/blip-itm-base-flikr''': '''https://huggingface.co/Salesforce/blip-itm-base-flikr/resolve/main/config.json''',
    '''Salesforce/blip-itm-large-flikr''': (
        '''https://huggingface.co/Salesforce/blip-itm-large-flikr/resolve/main/config.json'''
    ),
}

class 							UpperCAmelCase_						(     __lowercase  ):
							"""simple docstring"""







							UpperCAmelCase__			:		List[Any]             =       "blip_text_model"


							def __init__(     self			,				_a=3_0_5_2_4			,				_a=7_6_8			,				_a=7_6_8			,				_a=3_0_7_2			,				_a=7_6_8			,				_a=1_2			,				_a=8			,				_a=5_1_2			,				_a="gelu"			,				_a=1e-1_2			,				_a=0.0			,				_a=0.0			,				_a=0.02			,				_a=3_0_5_2_2			,				_a=2			,				_a=0			,				_a=1_0_2			,				_a=True			,				_a=True			,				**_a			,				)       ->       Union[str, Any]:
												super().__init__(
												    pad_token_id=_a			,				bos_token_id=_a			,				eos_token_id=_a			,				sep_token_id=_a			,				**_a			,				)

												_a      :       Union[str, Any]   =						vocab_size
												_a      :       List[Any]   =						hidden_size
												_a      :       str   =						encoder_hidden_size
												_a      :       Any   =						intermediate_size
												_a      :       Tuple   =						projection_dim
												_a      :       List[str]   =						hidden_dropout_prob
												_a      :       int   =						num_hidden_layers
												_a      :       int   =						num_attention_heads
												_a      :       int   =						max_position_embeddings
												_a      :       Any   =						layer_norm_eps
												_a      :       Optional[int]   =						hidden_act
												_a      :       Union[str, Any]   =						initializer_range
												_a      :       Tuple   =						attention_probs_dropout_prob
												_a      :       Dict   =						is_decoder
												_a      :       Tuple   =						use_cache




							@classmethod
							def 							__lowercase							(     cls			,				_a			,				**_a			)       ->       "PretrainedConfig":
												cls._set_token_in_kwargs(_a			)

												_a ,   _a      :       Optional[int]   =						cls.get_config_dict(_a			,				**_a			)

												# get the text config dict if we are loading from BlipConfig
												if config_dict.get('''model_type'''			) == "blip":
																	_a      :       Optional[Any]   =						config_dict['''text_config''']

												if "model_type" in config_dict and hasattr(cls			,				'''model_type'''			) and config_dict["model_type"] != cls.model_type:
																	logger.warning(
																	    F"""You are using a model of type {config_dict['model_type']} to instantiate a model of type """
																	    F"""{cls.model_type}. This is not supported for all configurations of models and can yield errors."""			)

												return cls.from_dict(_a			,				**_a			)



class 							UpperCAmelCase_						(     __lowercase  ):
							"""simple docstring"""







							UpperCAmelCase__			:		List[Any]             =       "blip_vision_model"


							def __init__(     self			,				_a=7_6_8			,				_a=3_0_7_2			,				_a=5_1_2			,				_a=1_2			,				_a=1_2			,				_a=3_8_4			,				_a=1_6			,				_a="gelu"			,				_a=1e-5			,				_a=0.0			,				_a=1e-1_0			,				**_a			,				)       ->       Optional[Any]:
												super().__init__(**_a			)

												_a      :       str   =						hidden_size
												_a      :       List[str]   =						intermediate_size
												_a      :       Optional[int]   =						projection_dim
												_a      :       Dict   =						num_hidden_layers
												_a      :       Dict   =						num_attention_heads
												_a      :       Union[str, Any]   =						patch_size
												_a      :       List[Any]   =						image_size
												_a      :       Tuple   =						initializer_range
												_a      :       int   =						attention_dropout
												_a      :       Optional[Any]   =						layer_norm_eps
												_a      :       List[Any]   =						hidden_act




							@classmethod
							def 							__lowercase							(     cls			,				_a			,				**_a			)       ->       "PretrainedConfig":
												cls._set_token_in_kwargs(_a			)

												_a ,   _a      :       Union[str, Any]   =						cls.get_config_dict(_a			,				**_a			)

												# get the vision config dict if we are loading from BlipConfig
												if config_dict.get('''model_type'''			) == "blip":
																	_a      :       str   =						config_dict['''vision_config''']

												if "model_type" in config_dict and hasattr(cls			,				'''model_type'''			) and config_dict["model_type"] != cls.model_type:
																	logger.warning(
																	    F"""You are using a model of type {config_dict['model_type']} to instantiate a model of type """
																	    F"""{cls.model_type}. This is not supported for all configurations of models and can yield errors."""			)

												return cls.from_dict(_a			,				**_a			)



class 							UpperCAmelCase_						(     __lowercase  ):
							"""simple docstring"""







							UpperCAmelCase__			:		str             =       "blip"
							UpperCAmelCase__			:		str             =       True


							def __init__(     self			,				_a=None			,				_a=None			,				_a=5_1_2			,				_a=2.6592			,				_a=2_5_6			,				**_a			,				)       ->       str:
												super().__init__(**_a			)

												if text_config is None:
																	_a      :       List[str]   =						{}
																	logger.info('''`text_config` is `None`. Initializing the `BlipTextConfig` with default values.'''			)

												if vision_config is None:
																	_a      :       str   =						{}
																	logger.info('''`vision_config` is `None`. Initializing the `BlipVisionConfig` with default values.'''			)

												_a      :       Optional[Any]   =						BlipTextConfig(**_a			)
												_a      :       Optional[int]   =						BlipVisionConfig(**_a			)

												_a      :       str   =						self.vision_config.hidden_size

												_a      :       Union[str, Any]   =						projection_dim
												_a      :       str   =						logit_scale_init_value
												_a      :       str   =						1.0
												_a      :       int   =						0.02
												_a      :       Optional[int]   =						image_text_hidden_size


							@classmethod
							def 							__lowercase							(     cls			,				_a			,				_a			,				**_a			)       ->       Optional[Any]:
												return cls(text_config=text_config.to_dict()			,				vision_config=vision_config.to_dict()			,				**_a			)




							def 							__lowercase							(     self			)       ->       Optional[int]:
												_a      :       Tuple   =						copy.deepcopy(self.__dict__			)
												_a      :       str   =						self.text_config.to_dict()
												_a      :       List[str]   =						self.vision_config.to_dict()
												_a      :       List[Any]   =						self.__class__.model_type
												return output






from scipy.stats import spearmanr

import datasets


a__												=						'''
The Spearman rank-order correlation coefficient is a measure of the
relationship between two datasets. Like other correlation coefficients,
this one varies between -1 and +1 with 0 implying no correlation.
Positive correlations imply that as data in dataset x increases, so
does data in dataset y. Negative correlations imply that as x increases,
y decreases. Correlations of -1 or +1 imply an exact monotonic relationship.

Unlike the Pearson correlation, the Spearman correlation does not
assume that both datasets are normally distributed.

The p-value roughly indicates the probability of an uncorrelated system
producing datasets that have a Spearman correlation at least as extreme
as the one computed from these datasets. The p-values are not entirely
reliable but are probably reasonable for datasets larger than 500 or so.
'''

a__												=						'''
Args:
    predictions (`List[float]`): Predicted labels, as returned by a model.
    references (`List[float]`): Ground truth labels.
    return_pvalue (`bool`): If `True`, returns the p-value. If `False`, returns
            only the spearmanr score. Defaults to `False`.
Returns:
    spearmanr (`float`): Spearman correlation coefficient.
    p-value (`float`): p-value. **Note**: is only returned if `return_pvalue=True` is input.
Examples:
    Example 1:
        >>> spearmanr_metric = datasets.load_metric("spearmanr")
        >>> results = spearmanr_metric.compute(references=[1, 2, 3, 4, 5], predictions=[10, 9, 2.5, 6, 4])
        >>> print(results)
        {\'spearmanr\': -0.7}

    Example 2:
        >>> spearmanr_metric = datasets.load_metric("spearmanr")
        >>> results = spearmanr_metric.compute(references=[1, 2, 3, 4, 5],
        ...                                     predictions=[10, 9, 2.5, 6, 4],
        ...                                     return_pvalue=True)
        >>> print(results[\'spearmanr\'])
        -0.7
        >>> print(round(results[\'spearmanr_pvalue\'], 2))
        0.19
'''

a__												=						R'''\
@book{kokoska2000crc,
  title={CRC standard probability and statistics tables and formulae},
  author={Kokoska, Stephen and Zwillinger, Daniel},
  year={2000},
  publisher={Crc Press}
}
@article{2020SciPy-NMeth,
  author  = {Virtanen, Pauli and Gommers, Ralf and Oliphant, Travis E. and
            Haberland, Matt and Reddy, Tyler and Cournapeau, David and
            Burovski, Evgeni and Peterson, Pearu and Weckesser, Warren and
            Bright, Jonathan and {van der Walt}, St{\'e}fan J. and
            Brett, Matthew and Wilson, Joshua and Millman, K. Jarrod and
            Mayorov, Nikolay and Nelson, Andrew R. J. and Jones, Eric and
            Kern, Robert and Larson, Eric and Carey, C J and
            Polat, {\.I}lhan and Feng, Yu and Moore, Eric W. and
            {VanderPlas}, Jake and Laxalde, Denis and Perktold, Josef and
            Cimrman, Robert and Henriksen, Ian and Quintero, E. A. and
            Harris, Charles R. and Archibald, Anne M. and
            Ribeiro, Ant{\^o}nio H. and Pedregosa, Fabian and
            {van Mulbregt}, Paul and {SciPy 1.0 Contributors}},
  title   = {{{SciPy} 1.0: Fundamental Algorithms for Scientific
            Computing in Python}},
  journal = {Nature Methods},
  year    = {2020},
  volume  = {17},
  pages   = {261--272},
  adsurl  = {https://rdcu.be/b08Wh},
  doi     = {10.1038/s41592-019-0686-2},
}
'''

@datasets.utils.file_utils.add_start_docstrings(_DESCRIPTION							,			_KWARGS_DESCRIPTION  )
class 							UpperCAmelCase_						(     datasets.Metric  ):
							"""simple docstring"""







							def 							__lowercase							(     self			)       ->       int:
												return datasets.MetricInfo(
												    description=_DESCRIPTION			,				citation=_CITATION			,				inputs_description=_KWARGS_DESCRIPTION			,				features=datasets.Features(
												        {
												            '''predictions''': datasets.Value('''float'''			),
												            '''references''': datasets.Value('''float'''			),
												        }			)			,				reference_urls=['''https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.spearmanr.html''']			,				)




							def 							__lowercase							(     self			,				_a			,				_a			,				_a=False			)       ->       str:
												_a      :       int   =						spearmanr(_a			,				_a			)
												if return_pvalue:
																	return {"spearmanr": results[0], "spearmanr_pvalue": results[1]}
												else:
																	return {"spearmanr": results[0]}



