


import torch
from transformers import PreTrainedModel, XLMRobertaConfig, XLMRobertaModel







class 							lowerCamelCase__						(				UpperCAmelCase   ):






			"""simple docstring"""






			_UpperCamelCase		:       Union[str, Any] 			=		'M-CLIP'




			def __init__(				self   ,    snake_case=1024   ,    snake_case=768   ,    **snake_case  ):

						'''simple docstring'''


						UpperCamelCase__       =							transformerDimSize
						UpperCamelCase__       =							imageDimSize
						super().__init__(**snake_case  )







class 							lowerCamelCase__						(				UpperCAmelCase   ):






			"""simple docstring"""






			_UpperCamelCase		:       Optional[int] 			=		MCLIPConfig




			def __init__(				self   ,    snake_case   ,    *snake_case   ,    **snake_case  ):

						'''simple docstring'''


						super().__init__(snake_case   ,    *snake_case   ,    **snake_case  )
						UpperCamelCase__       =							XLMRobertaModel(snake_case  )
						UpperCamelCase__       =							torch.nn.Linear(
						    in_features=config.transformerDimensions   ,    out_features=config.numDims  )







			def 					snake_case__					(				self   ,    snake_case   ,    snake_case  ):

						'''simple docstring'''


						UpperCamelCase__       =							self.transformer(input_ids=snake_case   ,    attention_mask=snake_case  )[0]
						UpperCamelCase__       =							(embs * attention_mask.unsqueeze(2  )).sum(dim=1  ) / attention_mask.sum(dim=1  )[:, None]
						return self.LinearTransformation(snake_case  ), embs






from typing import Callable, Optional

from .. import Features
from ..packaged_modules.generator.generator import Generator
from .abc import AbstractDatasetInputStream







class 							lowerCamelCase__						(				UpperCAmelCase   ):






			"""simple docstring"""






			def __init__(				self   ,    snake_case   ,    snake_case = None   ,    snake_case = None   ,    snake_case = False   ,    snake_case = False   ,    snake_case = None   ,    snake_case = None   ,    **snake_case   ,    ):

						'''simple docstring'''


						super().__init__(
						    features=snake_case   ,    cache_dir=snake_case   ,    keep_in_memory=snake_case   ,    streaming=snake_case   ,    num_proc=snake_case   ,    **snake_case   ,    )
						UpperCamelCase__       =							Generator(
						    cache_dir=snake_case   ,    features=snake_case   ,    generator=snake_case   ,    gen_kwargs=snake_case   ,    **snake_case   ,    )







			def 					snake_case__					(				self  ):

						'''simple docstring'''


						if self.streaming:
									UpperCamelCase__       =							self.builder.as_streaming_dataset(split="train"  )
						# Build regular (map-style) dataset
						else:
									UpperCamelCase__       =							None
									UpperCamelCase__       =							None
									UpperCamelCase__       =							None
									UpperCamelCase__       =							None

									self.builder.download_and_prepare(
									    download_config=snake_case   ,    download_mode=snake_case   ,    verification_mode=snake_case   ,    base_path=snake_case   ,    num_proc=self.num_proc   ,    )
									UpperCamelCase__       =							self.builder.as_dataset(
									    split="train"   ,    verification_mode=snake_case   ,    in_memory=self.keep_in_memory  )
						return dataset


