




'''simple docstring'''


from typing import Optional, Tuple

import jax
import jax.numpy as jnp
from flax import linen as nn
from flax.core.frozen_dict import FrozenDict
from transformers import CLIPConfig, FlaxPreTrainedModel
from transformers.models.clip.modeling_flax_clip import FlaxCLIPVisionModule
def  SCREAMING_SNAKE_CASE(					__lowercase						,							__lowercase						,							__lowercase=1E-12     )       ->      Union[str, Any]:
     A:						Any						=						jnp.divide(emb_a.T						,							jnp.clip(jnp.linalg.norm(__lowercase						,							axis=1     )						,							a_min=__lowercase     )     ).T
     A:						Tuple						=						jnp.divide(emb_a.T						,							jnp.clip(jnp.linalg.norm(__lowercase						,							axis=1     )						,							a_min=__lowercase     )     ).T
     return jnp.matmul(__lowercase						,							norm_emb_a.T     )






class 		lowerCAmelCase_     (    nn.Module				):







  '''simple docstring'''

  UpperCamelCase_       :	Tuple				       =							42
  UpperCamelCase_       :	Tuple				       =							jnp.floataa



  def  _snake_case			(      self							:				Union[str, Any]     )       ->						List[str]:







       '''simple docstring'''



       A:						Dict						=						FlaxCLIPVisionModule(self.config.vision_config     )
       A:						List[Any]						=						nn.Dense(self.config.projection_dim ,   use_bias=_lowerCAmelCase ,   dtype=self.dtype     )

       A:						List[str]						=						self.param('''concept_embeds''' ,   jax.nn.initializers.ones ,   (17, self.config.projection_dim)     )
       A:						List[str]						=						self.param(
           '''special_care_embeds''' ,   jax.nn.initializers.ones ,   (3, self.config.projection_dim)     )

       A:						int						=						self.param('''concept_embeds_weights''' ,   jax.nn.initializers.ones ,   (17,)     )
       A:						Optional[Any]						=						self.param('''special_care_embeds_weights''' ,   jax.nn.initializers.ones ,   (3,)     )




  def __call__(      self							:				Optional[Any] ,   SCREAMING_SNAKE_CASE_							:				Optional[Any]     )       ->						Dict:







       '''simple docstring'''



       A:						List[str]						=						self.vision_model(_lowerCAmelCase     )[1]
       A:						Dict						=						self.visual_projection(_lowerCAmelCase     )

       A:						Optional[Any]						=						jax_cosine_distance(_lowerCAmelCase ,   self.special_care_embeds     )
       A:						int						=						jax_cosine_distance(_lowerCAmelCase ,   self.concept_embeds     )

       # increase this value to create a stronger `nfsw` filter
       # at the cost of increasing the possibility of filtering benign image inputs
       A:						List[Any]						=						0.0

       A:						Optional[Any]						=						special_cos_dist - self.special_care_embeds_weights[None, :] + adjustment
       A:						str						=						jnp.round(_lowerCAmelCase ,   3     )
       A:						Optional[Any]						=						jnp.any(special_scores > 0 ,   axis=1 ,   keepdims=_lowerCAmelCase     )
       # Use a lower threshold if an image has any special care concept
       A:						str						=						is_special_care * 0.01

       A:						Union[str, Any]						=						cos_dist - self.concept_embeds_weights[None, :] + special_adjustment
       A:						Any						=						jnp.round(_lowerCAmelCase ,   3     )
       A:						List[str]						=						jnp.any(concept_scores > 0 ,   axis=1     )

       return has_nsfw_concepts






class 		lowerCAmelCase_     (    UpperCAmelCase_				):







  '''simple docstring'''

  UpperCamelCase_       :	Union[str, Any]				       =							CLIPConfig
  UpperCamelCase_       :	int				       =							"""clip_input"""
  UpperCamelCase_       :	Optional[Any]				       =							FlaxStableDiffusionSafetyCheckerModule



  def __init__(      self							:				Tuple ,   SCREAMING_SNAKE_CASE_							:				CLIPConfig ,   SCREAMING_SNAKE_CASE_							:				Optional[Tuple] = None ,   SCREAMING_SNAKE_CASE_							:				int = 0 ,   SCREAMING_SNAKE_CASE_							:				jnp.dtype = jnp.floataa ,   SCREAMING_SNAKE_CASE_							:				bool = True ,   **SCREAMING_SNAKE_CASE_							:				Tuple ,   )       ->						Optional[int]:







       '''simple docstring'''



       if input_shape is None:
            A:						Union[str, Any]						=						(1, 2_24, 2_24, 3)
       A:						Tuple						=						self.module_class(config=_lowerCAmelCase ,   dtype=_lowerCAmelCase ,   **_lowerCAmelCase     )
       super().__init__(_lowerCAmelCase ,   _lowerCAmelCase ,   input_shape=_lowerCAmelCase ,   seed=_lowerCAmelCase ,   dtype=_lowerCAmelCase ,   _do_init=_do_init     )



  def  _snake_case			(      self							:				Optional[Any] ,   SCREAMING_SNAKE_CASE_							:				jax.random.KeyArray ,   SCREAMING_SNAKE_CASE_							:				Tuple ,   SCREAMING_SNAKE_CASE_							:				FrozenDict = None     )       ->						Union[str, Any]:







       '''simple docstring'''



       A:						Tuple						=						jax.random.normal(_lowerCAmelCase ,   _lowerCAmelCase     )

       A:						Union[str, Any]						=						jax.random.split(_lowerCAmelCase     )
       A:						Tuple						=						{"params": params_rng, "dropout": dropout_rng}

       A:						List[str]						=						self.module.init(_lowerCAmelCase ,   _lowerCAmelCase     )["params"]

       return random_params




  def __call__(      self							:				Dict ,   SCREAMING_SNAKE_CASE_							:				int ,   SCREAMING_SNAKE_CASE_							:				dict = None ,   )       ->						Dict:







       '''simple docstring'''



       A:						Optional[int]						=						jnp.transpose(_lowerCAmelCase ,   (0, 2, 3, 1)     )

       return self.module.apply(
           {'''params''': params or self.params} ,   jnp.array(_lowerCAmelCase ,   dtype=jnp.floataa     ) ,   rngs={} ,   )












import os
from math import logaa



def 					UpperCAmelCase__     (   lowerCamelCase = "base_exp.txt"      ):
  lowercase			:float							=  0
  lowercase			:str							=  0
  for i, line in enumerate(open(os.path.join(os.path.dirname(lowerCamelCase      ),	lowerCamelCase      )      )      ):
    lowercase		,			lowercase			:str							=  list(map(lowerCamelCase,	line.split(","      )      )      )
    if x * logaa(lowerCamelCase      ) > largest:
      lowercase			:Optional[Any]							=  x * logaa(lowerCamelCase      )
      lowercase			:Any							=  i + 1
  return result


if __name__ == "__main__":
     print(solution())



