


'''simple docstring'''







import random







def _UpperCamelCase       (     __A      ,			__A      ,			__A = False    )							->		dict:


      '''simple docstring'''



      UpperCamelCase__										=				{i: [] for i in range(__A    )}

      # if probability is greater or equal than 1, then generate a complete graph
      if probability >= 1:
            return complete_graph(__A    )
      # if probability is lower or equal than 0, then return a graph without edges
      if probability <= 0:
            return graph

      # for each couple of nodes, add an edge from u to v
      # if the number randomly generated is greater than probability probability
      for i in range(__A    ):
            for j in range(i + 1      ,			__A    ):
                  if random.random() < probability:
                        graph[i].append(__A    )
                        if not directed:
                              # if the graph is undirected, add an edge in from j to i, either
                              graph[j].append(__A    )
      return graph







def _UpperCamelCase       (     __A    )							->		dict:


      '''simple docstring'''



      return {
          i: [j for j in range(__A    ) if i != j] for i in range(__A    )
      }


if __name__ == "__main__":
  import doctest

  doctest.testmod()









import torch
from transformers import PreTrainedModel, XLMRobertaConfig, XLMRobertaModel
class 	UpperCAmelCase_					(					UpperCamelCase    ):

   '''simple docstring'''




   __A :      Optional[int]     		=		"M-CLIP"






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






     """simple docstring"""





     lowerCamelCase :					str    =				transformerDimSize
     lowerCamelCase :					Any    =				imageDimSize
     super().__init__(**__A )



class 	UpperCAmelCase_					(					UpperCamelCase    ):

   '''simple docstring'''




   __A :      Tuple     		=		MCLIPConfig






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






     """simple docstring"""





     super().__init__(__A						,				*__A						,				**__A )
     lowerCamelCase :					Tuple    =				XLMRobertaModel(__A )
     lowerCamelCase :					Optional[Any]    =				torch.nn.Linear(
         in_features=config.transformerDimensions						,				out_features=config.numDims )






   def _snake_case    (		self						,				__A						,				__A ):






     """simple docstring"""





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



