class_docstr: Embedding class that can take any number of image or text modalities, each can
  have their input id, position id and segment id. We generate embeddings of
  dimension config.hidden_size for each and then first add the three embeddings
  for each modality to have a modality specific embedding. We then concat the
  modality specific embeddings to have a joint embedding.
class_docstr_tok: ["Embedding","class","that","can","take","any","number","of","image","or","text","modalities",",","each","can","have","their","input","id",",","position","id","and","segment","id",".","We","generate","embeddings","of","dimension","config.hidden_size","for","each","and","then","first","add","the","three","embeddings","for","each","modality","to","have","a","modality","specific","embedding",".","We","then","concat","the","modality","specific","embeddings","to","have","a","joint","embedding","."]
code: def init_weights(self, transformer: Type[nn.Module]):
      for idx, modality in enumerate(self.model_config.modalities):
          if modality.type == "text":
              self.token_embeddings[
                  idx
              ] = transformer.embeddings.word_embeddings
              self.layer_norms[idx] = transformer.embeddings.LayerNorm
  
          self.pos_embeddings[idx].weight = nn.Parameter(
              deepcopy(
                  transformer.embeddings.position_embeddings.weight.data
              ),
              requires_grad=True,
          )
  
      # Token Type or Segment Embeddings
      if hasattr(transformer.embeddings, "token_type_embeddings"):
          token_vocab_size = self.transformer_config.type_vocab_size
          self.token_type_embeddings.weight.data[
              :token_vocab_size
          ].copy_(transformer.embeddings.token_type_embeddings.weight)
          for idx in range(
              token_vocab_size, len(self.model_config.modalities)
          ):
              self.token_type_embeddings.weight.data[idx].copy_(
                  transformer.embeddings.token_type_embeddings.weight.data.mean(
                      dim=0
                  )
              )
              # Add random normal noise
              self.token_type_embeddings.weight.data[
                  idx
              ] += torch.normal(
                  self.model_config.token_noise_mean,
                  self.model_config.token_noise_std,
                  size=self.token_type_embeddings.weight.data[
                      idx
                  ].size(),
              )
  
imports: from copy import deepcopy
  from typing import Any, Dict, List, Type
  import torch
  from mmf.common.registry import registry
  from mmf.models.transformers.base import BaseTransformer, BaseTransformerBackend
  from mmf.modules.hf_layers import BertModelJit, replace_with_jit
  from omegaconf import OmegaConf
  from torch import nn, Tensor
label_desc: Use image node_id 3 for calling the HuggingfaceEmbeddings obj's underlying member method code with example usage: obj.init_weights(transformer) without return types