class_docstr: Clip based content filtering model for NSFW.
class_docstr_tok: ["Clip","based","content","filtering","model","for","NSFW","."]
code: def __init__(
      self,
      model_cfg: DictConfig,
      model_parallel_config,
      padded_vocab_size: int,
      tokenizer: Optional,
  ):
      super(ContentFilteringModel, self).__init__()
      self.cfg = model_cfg
      self.config = model_parallel_config
      self.tokenizer = tokenizer
  
      self.concept_list = self._load_concept_list(model_cfg.concepts)
      self.concept_count = len(self.concept_list)
  
      self.vision_encoder = CLIPVisionTransformer(
          model_cfg.vision,
          model_parallel_config,
          pre_process=True,
          post_process=True,
      )
  
      if "text" in model_cfg and model_cfg.text is not None:
          self.text_encoder = CLIPTextTransformer(
              model_cfg.text,
              model_parallel_config,
              padded_vocab_size,
              pre_process=True,
              post_process=True,
          )
      else:
          self.text_encoder = None
  
      self.mlp_similarity_model = nn.Sequential(
          nn.Linear(model_cfg.output_dim * 2, model_cfg.sim_hidden_dim),
          nn.ReLU(),
          nn.Linear(model_cfg.sim_hidden_dim, 1),
      )
  
      self.nn_classifier = nn.Sequential(
          nn.Linear(
              self.concept_count * 2 + model_cfg.output_dim,
              model_cfg.cls_hidden_dim,
          ),
          nn.ReLU(),
          nn.Linear(model_cfg.cls_hidden_dim, 1),
      )
  
      self.register_buffer(
          "concepts",
          torch.zeros(self.concept_count, model_cfg.output_dim),
      )
  
imports: import functools
  import itertools
  from typing import List, Optional, Union
  import torch
  import torch.nn
  import torch.nn.functional
  from apex.transformer.pipeline_parallel.utils import get_num_microbatches
  from megatron.core import parallel_state
  from megatron.core.pipeline_parallel.schedules import get_forward_backward_func
  from omegaconf.dictconfig import DictConfig
  from pytorch_lightning.accelerators import CPUAccelerator
  from pytorch_lightning.trainer.trainer import Trainer
  from nemo.collections.multimodal.data.clip.clip_dataset import tokenize
  from nemo.collections.multimodal.data.nsfw.nsfw_dataset import build_dataset
  from nemo.collections.multimodal.models.vision_language_foundation.clip.megatron_clip_models import CLIPTextTransformer, CLIPVisionTransformer
  from nemo.collections.nlp.models.language_modeling.megatron_base_model import MegatronBaseModel
  from nemo.collections.nlp.modules.common.megatron.build_model import build_model
  from nemo.collections.nlp.modules.common.megatron.module import Float16Module, MegatronModule
  from nemo.collections.nlp.parts.utils_funcs import get_last_rank, torch_dtype_from_precision
  from nemo.core.classes.common import PretrainedModelInfo
  from nemo.utils import logging
label_desc: Use image node_id 1 to create a new ContentFilteringModel object from inherited base classes: MegatronModule with example: obj = ContentFilteringModel(model_cfg, model_parallel_config, padded_vocab_size, tokenizer)