code: def embedding_matrix(
      vocab: List[str],
      embedding_size: int,
      representation: str = "dense",
      embeddings_trainable: bool = True,
      pretrained_embeddings: Optional[str] = None,
      force_embedding_size: bool = False,
      embedding_initializer: Optional[Union[str, Dict]] = None,
  ) -> Tuple[nn.Module, int]:
      """Returns initialized torch.nn.Embedding module and embedding size."""
  
      vocab_size = len(vocab)
      if representation == "dense":
          if pretrained_embeddings:
              embeddings_matrix = load_pretrained_embeddings(
                  pretrained_embeddings, vocab
              )
              if embeddings_matrix.shape[-1] != embedding_size:
                  if not force_embedding_size:
                      embedding_size = embeddings_matrix.shape[-1]
                      logger.info(
                          f"Setting embedding size to be equal to {embeddings_matrix.shape[-1]}."
                      )
                  else:
                      raise ValueError(
                          f"The size of the pretrained embeddings is "
                          f"{embeddings_matrix.shape[-1]}, but the specified "
                          f"embedding_size is {embedding_size}. Please change "
                          f"the embedding_size accordingly."
                      )
              embedding_initializer_obj = torch.tensor(
                  embeddings_matrix, dtype=torch.float32
              )
  
          else:
              if (
                  vocab_size < embedding_size
                  and not force_embedding_size
              ):
                  logger.info(
                      f"  embedding_size ({embedding_size}) is greater than "
                      f"vocab_size ({vocab_size}). Setting embedding size to be "
                      f"equal to vocab_size."
                  )
                  embedding_size = vocab_size
  
              if embedding_initializer is not None:
                  embedding_initializer_obj_ref = get_initializer(
                      embedding_initializer
                  )
              else:
                  embedding_initializer_obj_ref = get_initializer(
                      {TYPE: "uniform", "a": -1.0, "b": 1.0}
                  )
              embedding_initializer_obj = embedding_initializer_obj_ref(
                  [vocab_size, embedding_size]
              )
  
          embeddings = embedding_initializer_obj
  
      elif representation == "sparse":
          embedding_size = vocab_size
          embeddings = get_initializer("identity")(
              [vocab_size, embedding_size]
          )
          embeddings.requires_grad = False
      else:
          raise Exception(
              f"Embedding representation {representation} not supported."
          )
  
      embeddings = nn.Embedding.from_pretrained(
          embeddings, freeze=not embeddings_trainable
      )
      return embeddings, embedding_size
  
imports: import logging
  from typing import Dict, List, Optional, Tuple, Union
  import torch
  from torch import nn
  from ludwig.constants import TYPE
  from ludwig.modules.initializer_modules import get_initializer
  from ludwig.utils.data_utils import load_pretrained_embeddings
  from ludwig.utils.torch_utils import get_torch_device, LudwigModule
label_desc: Use image node_id 1 for calling a global function with example usage: embedding_matrix(vocab, embedding_size, representation, embeddings_trainable, pretrained_embeddings, force_embedding_size, embedding_initializer) and returns: embeddings,  embedding_size