class_docstr: Embeds categorical and continuous features into a 2D tensor.
class_docstr_tok: ["Embeds","categorical","and","continuous","features","into","a","2D","tensor","."]
docstr: Args:
      continuous_dim: number of continuous features
      categorical_cardinality: list of cardinalities of categorical features
      embedding_dim: embedding dimension
      shared_embedding_strategy: strategy to use for shared embeddings
      frac_shared_embed: fraction of embeddings to share
      embedding_bias: whether to use bias in embedding layers
      batch_norm_continuous_input: whether to use batch norm on continuous features
      embedding_dropout: dropout to apply to embeddings
      initialization: initialization strategy to use for embedding layers
docstr_tok: ["Args",":","continuous_dim",":","number","of","continuous","features","categorical_cardinality",":","list","of","cardinalities","of","categorical","features","embedding_dim",":","embedding","dimension","shared_embedding_strategy",":","strategy","to","use","for","shared","embeddings","frac_shared_embed",":","fraction","of","embeddings","to","share","embedding_bias",":","whether","to","use","bias","in","embedding","layers","batch_norm_continuous_input",":","whether","to","use","batch","norm","on","continuous","features","embedding_dropout",":","dropout","to","apply","to","embeddings","initialization",":","initialization","strategy","to","use","for","embedding","layers"]
code: def __init__(
      self,
      continuous_dim: int,
      categorical_cardinality: List[int],
      embedding_dim: int,
      shared_embedding_strategy: Optional[str] = None,
      frac_shared_embed: float = 0.25,
      embedding_bias: bool = False,
      batch_norm_continuous_input: bool = False,
      virtual_batch_size: Optional[int] = None,
      embedding_dropout: float = 0.0,
      initialization: Optional[str] = None,
  ):
      """
      Args:
          continuous_dim: number of continuous features
          categorical_cardinality: list of cardinalities of categorical features
          embedding_dim: embedding dimension
          shared_embedding_strategy: strategy to use for shared embeddings
          frac_shared_embed: fraction of embeddings to share
          embedding_bias: whether to use bias in embedding layers
          batch_norm_continuous_input: whether to use batch norm on continuous features
          embedding_dropout: dropout to apply to embeddings
          initialization: initialization strategy to use for embedding layers
      """
      super().__init__()
      self.continuous_dim = continuous_dim
      self.categorical_cardinality = categorical_cardinality
      self.embedding_dim = embedding_dim
      self.batch_norm_continuous_input = batch_norm_continuous_input
      self.shared_embedding_strategy = shared_embedding_strategy
      self.frac_shared_embed = frac_shared_embed
      self.embedding_bias = embedding_bias
      self.initialization = initialization
      d_sqrt_inv = 1 / math.sqrt(embedding_dim)
      if initialization is not None:
          assert initialization in [
              "kaiming_uniform",
              "kaiming_normal",
          ], "initialization should be either of `kaiming` or `uniform`"
          self._do_kaiming_initialization = True
          self._initialize_kaiming = partial(
              _initialize_kaiming,
              initialization=initialization,
              d_sqrt_inv=d_sqrt_inv,
          )
      else:
          self._do_kaiming_initialization = False
  
      # cat Embedding layers
      if self.shared_embedding_strategy is not None:
          self.cat_embedding_layers = nn.ModuleList(
              [
                  SharedEmbeddings(
                      c,
                      self.embedding_dim,
                      add_shared_embed=(
                          self.shared_embedding_strategy == "add"
                      ),
                      frac_shared_embed=self.frac_shared_embed,
                  )
                  for c in categorical_cardinality
              ]
          )
          if self._do_kaiming_initialization:
              for embedding_layer in self.cat_embedding_layers:
                  self._initialize_kaiming(embedding_layer.embed.weight)
                  self._initialize_kaiming(embedding_layer.shared_embed)
      else:
          self.cat_embedding_layers = nn.ModuleList(
              [
                  nn.Embedding(c, self.embedding_dim)
                  for c in categorical_cardinality
              ]
          )
          if self._do_kaiming_initialization:
              for embedding_layer in self.cat_embedding_layers:
                  self._initialize_kaiming(embedding_layer.weight)
      if embedding_bias:
          self.cat_embedding_bias = nn.Parameter(
              torch.Tensor(
                  len(self.categorical_cardinality), self.embedding_dim
              )
          )
          if self._do_kaiming_initialization:
              self._initialize_kaiming(self.cat_embedding_bias)
      # Continuous Embedding Layer
      self.cont_embedding_layer = nn.Embedding(
          self.continuous_dim, self.embedding_dim
      )
      if self._do_kaiming_initialization:
          self._initialize_kaiming(self.cont_embedding_layer.weight)
      if embedding_bias:
          self.cont_embedding_bias = nn.Parameter(
              torch.Tensor(self.continuous_dim, self.embedding_dim)
          )
          if self._do_kaiming_initialization:
              self._initialize_kaiming(self.cont_embedding_bias)
      if batch_norm_continuous_input:
          self.normalizing_batch_norm = BatchNorm1d(
              continuous_dim, virtual_batch_size
          )
      if embedding_dropout > 0:
          self.embd_dropout = nn.Dropout(embedding_dropout)
      else:
          self.embd_dropout = None
  
imports: import math
  from functools import partial
  from typing import Any, Dict, List, Optional, Tuple
  import torch
  from torch import nn
  from pytorch_tabular.models.common.layers.batch_norm import BatchNorm1d
  from pytorch_tabular.utils import _initialize_kaiming
label_desc: Use image node_id 1 to create a new Embedding2dLayer object from inherited base classes: nn with example: obj = Embedding2dLayer(continuous_dim, categorical_cardinality, embedding_dim, shared_embedding_strategy, frac_shared_embed, embedding_bias, batch_norm_continuous_input, virtual_batch_size, embedding_dropout, initialization)