



import copy
import os
from typing import Union

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


_a:    int 							=			logging.get_logger(__name__)

_a:    Optional[int] 							=			{
    """BridgeTower/bridgetower-base""": """https://huggingface.co/BridgeTower/bridgetower-base/blob/main/config.json""",
    """BridgeTower/bridgetower-base-itm-mlm""": (
        """https://huggingface.co/BridgeTower/bridgetower-base-itm-mlm/blob/main/config.json"""
    ),
}

class 						__UpperCamelCase    (					snake_case__						):
	SCREAMING_SNAKE_CASE__    				=     'bridgetower_vision_model'




	def __init__(		self	:						Union[str, Any]		,	lowerCAmelCase	:						Union[str, Any]=768		,	lowerCAmelCase	:						Optional[int]=12		,	lowerCAmelCase	:						Dict=3		,	lowerCAmelCase	:						Any=16		,	lowerCAmelCase	:						List[str]=288		,	lowerCAmelCase	:						Any=1		,	lowerCAmelCase	:						Optional[int]=1e-05		,	lowerCAmelCase	:						Dict=False		,	lowerCAmelCase	:						Any=True		,	lowerCAmelCase	:						Union[str, Any]=False		,	**lowerCAmelCase	:						List[Any]		,	):


		'''simple docstring'''







		super().__init__(**lowercase_							)
		UpperCAmelCase_       				=			hidden_size
		UpperCAmelCase_       				=			num_hidden_layers
		UpperCAmelCase_       				=			num_channels
		UpperCAmelCase_       				=			patch_size
		UpperCAmelCase_       				=			image_size
		UpperCAmelCase_       				=			initializer_factor
		UpperCAmelCase_       				=			layer_norm_eps
		UpperCAmelCase_       				=			stop_gradient
		UpperCAmelCase_       				=			share_layernorm
		UpperCAmelCase_       				=			remove_last_layer




	@classmethod
	def       __A					(		cls	:						Any		,	lowerCAmelCase	:						int		,	**lowerCAmelCase	:						Any							):


		'''simple docstring'''







		UpperCAmelCase_       				=			cls.get_config_dict(lowercase_		,	**lowercase_							)

		if config_dict.get("model_type"							) == "bridgetower":
			UpperCAmelCase_       				=			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(lowercase_		,	**lowercase_							)


class 						__UpperCamelCase    (					snake_case__						):
	SCREAMING_SNAKE_CASE__    				=     'bridgetower_text_model'




	def __init__(		self	:						List[Any]		,	lowerCAmelCase	:						List[str]=50_265		,	lowerCAmelCase	:						Optional[int]=768		,	lowerCAmelCase	:						Optional[int]=12		,	lowerCAmelCase	:						List[str]=12		,	lowerCAmelCase	:						int=1		,	lowerCAmelCase	:						Union[str, Any]=3_072		,	lowerCAmelCase	:						Optional[Any]="gelu"		,	lowerCAmelCase	:						List[Any]=0.1		,	lowerCAmelCase	:						Any=0.1		,	lowerCAmelCase	:						List[Any]=514		,	lowerCAmelCase	:						Optional[Any]=1		,	lowerCAmelCase	:						str=1e-05		,	lowerCAmelCase	:						List[Any]=1		,	lowerCAmelCase	:						str=0		,	lowerCAmelCase	:						Dict=2		,	lowerCAmelCase	:						str="absolute"		,	lowerCAmelCase	:						Dict=True		,	**lowerCAmelCase	:						Optional[Any]		,	):


		'''simple docstring'''







		super().__init__(**lowercase_							)

		UpperCAmelCase_       				=			vocab_size
		UpperCAmelCase_       				=			hidden_size
		UpperCAmelCase_       				=			num_hidden_layers
		UpperCAmelCase_       				=			num_attention_heads
		UpperCAmelCase_       				=			hidden_act
		UpperCAmelCase_       				=			initializer_factor
		UpperCAmelCase_       				=			intermediate_size
		UpperCAmelCase_       				=			hidden_dropout_prob
		UpperCAmelCase_       				=			attention_probs_dropout_prob
		UpperCAmelCase_       				=			max_position_embeddings
		UpperCAmelCase_       				=			type_vocab_size
		UpperCAmelCase_       				=			layer_norm_eps
		UpperCAmelCase_       				=			position_embedding_type
		UpperCAmelCase_       				=			use_cache
		UpperCAmelCase_       				=			pad_token_id
		UpperCAmelCase_       				=			bos_token_id
		UpperCAmelCase_       				=			eos_token_id




	@classmethod
	def       __A					(		cls	:						List[str]		,	lowerCAmelCase	:						Tuple		,	**lowerCAmelCase	:						List[str]							):


		'''simple docstring'''







		UpperCAmelCase_       				=			cls.get_config_dict(lowercase_		,	**lowercase_							)

		if config_dict.get("model_type"							) == "bridgetower":
			UpperCAmelCase_       				=			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(lowercase_		,	**lowercase_							)


class 						__UpperCamelCase    (					snake_case__						):
	SCREAMING_SNAKE_CASE__    				=     'bridgetower'




	def __init__(		self	:						int		,	lowerCAmelCase	:						Optional[Any]=True		,	lowerCAmelCase	:						Tuple="gelu"		,	lowerCAmelCase	:						List[Any]=768		,	lowerCAmelCase	:						int=1		,	lowerCAmelCase	:						Dict=1e-05		,	lowerCAmelCase	:						List[str]=False		,	lowerCAmelCase	:						Union[str, Any]="add"		,	lowerCAmelCase	:						Optional[int]=12		,	lowerCAmelCase	:						Optional[Any]=6		,	lowerCAmelCase	:						Union[str, Any]=False		,	lowerCAmelCase	:						Tuple=False		,	lowerCAmelCase	:						str=None		,	lowerCAmelCase	:						List[str]=None		,	**lowerCAmelCase	:						List[str]		,	):


		'''simple docstring'''







		UpperCAmelCase_       				=			kwargs.pop("text_config_dict"		,	lowercase_							)
		UpperCAmelCase_       				=			kwargs.pop("vision_config_dict"		,	lowercase_							)

		super().__init__(**lowercase_							)
		UpperCAmelCase_       				=			share_cross_modal_transformer_layers
		UpperCAmelCase_       				=			hidden_act
		UpperCAmelCase_       				=			hidden_size
		UpperCAmelCase_       				=			initializer_factor
		UpperCAmelCase_       				=			layer_norm_eps
		UpperCAmelCase_       				=			share_link_tower_layers
		UpperCAmelCase_       				=			link_tower_type
		UpperCAmelCase_       				=			num_attention_heads
		UpperCAmelCase_       				=			num_hidden_layers
		UpperCAmelCase_       				=			tie_word_embeddings
		UpperCAmelCase_       				=			init_layernorm_from_vision_encoder

		if text_config is None:
			UpperCAmelCase_       				=			{}
			logger.info("`text_config` is `None`. Initializing the `BridgeTowerTextConfig` with default values."							)

		if vision_config is None:
			UpperCAmelCase_       				=			{}
			logger.info("`vision_config` is `None`. Initializing the `BridgeTowerVisionConfig` with default values."							)

		UpperCAmelCase_       				=			BridgeTowerTextConfig(**lowercase_							)
		UpperCAmelCase_       				=			BridgeTowerVisionConfig(**lowercase_							)




	@classmethod
	def       __A					(		cls	:						Any		,	lowerCAmelCase	:						Optional[Any]		,	lowerCAmelCase	:						Dict		,	**lowerCAmelCase	:						str							):


		'''simple docstring'''







		return cls(text_config=text_config.to_dict()		,	vision_config=vision_config.to_dict()		,	**lowercase_							)




	def       __A					(		self	:						Optional[int]							):


		'''simple docstring'''







		UpperCAmelCase_       				=			copy.deepcopy(self.__dict__							)
		UpperCAmelCase_       				=			self.text_config.to_dict()
		UpperCAmelCase_       				=			self.vision_config.to_dict()
		UpperCAmelCase_       				=			self.__class__.model_type
		return output


from sklearn.metrics import mean_squared_error

import datasets


_a:    Any 							=			"""\
@article{scikit-learn,
 title={Scikit-learn: Machine Learning in {P}ython},
 author={Pedregosa, F. and Varoquaux, G. and Gramfort, A. and Michel, V.
         and Thirion, B. and Grisel, O. and Blondel, M. and Prettenhofer, P.
         and Weiss, R. and Dubourg, V. and Vanderplas, J. and Passos, A. and
         Cournapeau, D. and Brucher, M. and Perrot, M. and Duchesnay, E.},
 journal={Journal of Machine Learning Research},
 volume={12},
 pages={2825--2830},
 year={2011}
}
"""

_a:    List[Any] 							=			"""\
Mean Squared Error(MSE) is the average of the square of difference between the predicted
and actual values.
"""


_a:    List[str] 							=			"""
Args:
    predictions: array-like of shape (n_samples,) or (n_samples, n_outputs)
        Estimated target values.
    references: array-like of shape (n_samples,) or (n_samples, n_outputs)
        Ground truth (correct) target values.
    sample_weight: array-like of shape (n_samples,), default=None
        Sample weights.
    multioutput: {\"raw_values\", \"uniform_average\"} or array-like of shape (n_outputs,), default=\"uniform_average\"
        Defines aggregating of multiple output values. Array-like value defines weights used to average errors.

        \"raw_values\" : Returns a full set of errors in case of multioutput input.

        \"uniform_average\" : Errors of all outputs are averaged with uniform weight.

    squared : bool, default=True
        If True returns MSE value, if False returns RMSE (Root Mean Squared Error) value.

Returns:
    mse : mean squared error.
Examples:

    >>> mse_metric = datasets.load_metric(\"mse\")
    >>> predictions = [2.5, 0.0, 2, 8]
    >>> references = [3, -0.5, 2, 7]
    >>> results = mse_metric.compute(predictions=predictions, references=references)
    >>> print(results)
    {'mse': 0.375}
    >>> rmse_result = mse_metric.compute(predictions=predictions, references=references, squared=False)
    >>> print(rmse_result)
    {'mse': 0.6123724356957945}

    If you're using multi-dimensional lists, then set the config as follows :

    >>> mse_metric = datasets.load_metric(\"mse\", \"multilist\")
    >>> predictions = [[0.5, 1], [-1, 1], [7, -6]]
    >>> references = [[0, 2], [-1, 2], [8, -5]]
    >>> results = mse_metric.compute(predictions=predictions, references=references)
    >>> print(results)
    {'mse': 0.7083333333333334}
    >>> results = mse_metric.compute(predictions=predictions, references=references, multioutput='raw_values')
    >>> print(results) # doctest: +NORMALIZE_WHITESPACE
    {'mse': array([0.41666667, 1. ])}
"""

@datasets.utils.file_utils.add_start_docstrings(_DESCRIPTION     ,     _KWARGS_DESCRIPTION						)
class 						__UpperCamelCase    (					datasets.Metric						):




	def       __A					(		self	:						List[str]							):


		'''simple docstring'''







		return datasets.MetricInfo(
		    description=_DESCRIPTION		,	citation=_CITATION		,	inputs_description=_KWARGS_DESCRIPTION		,	features=datasets.Features(self._get_feature_types()							)		,	reference_urls=[
		        "https://scikit-learn.org/stable/modules/generated/sklearn.metrics.mean_squared_error.html"
		    ]		,	)




	def       __A					(		self	:						Optional[Any]							):


		'''simple docstring'''







		if self.config_name == "multilist":
			return {
			    "predictions": datasets.Sequence(datasets.Value("float"							)							),
			    "references": datasets.Sequence(datasets.Value("float"							)							),
			}
		else:
			return {
			    "predictions": datasets.Value("float"							),
			    "references": datasets.Value("float"							),
			}




	def       __A					(		self	:						Tuple		,	lowerCAmelCase	:						int		,	lowerCAmelCase	:						Dict		,	lowerCAmelCase	:						str=None		,	lowerCAmelCase	:						str="uniform_average"		,	lowerCAmelCase	:						Any=True							):


		'''simple docstring'''







		UpperCAmelCase_       				=			mean_squared_error(
		    lowerCAmelCase		,	lowerCAmelCase		,	sample_weight=lowerCAmelCase		,	multioutput=lowerCAmelCase		,	squared=lowerCAmelCase							)

		return {"mse": mse}