


"""simple docstring"""







import torch
from transformers import PreTrainedModel, XLMRobertaConfig, XLMRobertaModel




class 				UpperCamelCase_			(				_UpperCAmelCase):
	snake_case__       :						List[str]					      =    "M-CLIP"




	def __init__(				self    :       Optional[Any]    ,    UpperCAmelCase__    :       Union[str, Any]=1_0_2_4    ,    UpperCAmelCase__    :       Optional[int]=7_6_8    ,    **UpperCAmelCase__    :       List[str]     ) ->			List[Any]:
						__SCREAMING_SNAKE_CASE		     =       transformerDimSize
						__SCREAMING_SNAKE_CASE		     =       imageDimSize
						super().__init__(**lowerCamelCase_     )




class 				UpperCamelCase_			(				_UpperCAmelCase):
	snake_case__       :						List[Any]					      =    MCLIPConfig




	def __init__(				self    :       Optional[int]    ,    UpperCAmelCase__    :       List[Any]    ,    *UpperCAmelCase__    :       str    ,    **UpperCAmelCase__    :       str     ) ->			Union[str, Any]:
						super().__init__(lowerCamelCase_    ,    *lowerCamelCase_    ,    **lowerCamelCase_     )
						__SCREAMING_SNAKE_CASE		     =       XLMRobertaModel(lowerCamelCase_     )
						__SCREAMING_SNAKE_CASE		     =       torch.nn.Linear(
						    in_features=config.transformerDimensions    ,    out_features=config.numDims     )




	def 						UpperCAmelCase_   (				self    :       int    ,    UpperCAmelCase__    :       Any    ,    UpperCAmelCase__    :       Dict     ) ->			Optional[Any]:
						__SCREAMING_SNAKE_CASE		     =       self.transformer(input_ids=lowerCamelCase_    ,    attention_mask=lowerCamelCase_     )[0]
						__SCREAMING_SNAKE_CASE		     =       (embs * attention_mask.unsqueeze(2     )).sum(dim=1     ) / attention_mask.sum(dim=1     )[:, None]
						return self.LinearTransformation(lowerCamelCase_     ), embs




"""simple docstring"""







from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_sentencepiece_available


a__       :							List[str]        =  {}


try:
		if not is_sentencepiece_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		a__       :							int        =  ['''MLukeTokenizer''']

if TYPE_CHECKING:
		try:
				if not is_sentencepiece_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .tokenization_mluke import MLukeTokenizer


else:
		import sys

		a__       :							Optional[Any]        =  _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)
