class_docstr: Classical embeddings generator
class_docstr_tok: ["Classical","embeddings","generator"]
docstr: This is an embedding module for an entire set of features
  
  Parameters
  ----------
  input_dim : int
      Number of features coming as input (number of columns)
  cat_dims : list of int
      Number of modalities for each categorial features
      If the list is empty, no embeddings will be done
  cat_idxs : list of int
      Positional index for each categorical features in inputs
  cat_emb_dim : list of int
      Embedding dimension for each categorical features
      If int, the same embedding dimension will be used for all categorical features
  group_matrix : torch matrix
      Original group matrix before embeddings
docstr_tok: ["This","is","an","embedding","module","for","an","entire","set","of","features","Parameters","--","--","--","--","--","input_dim",":","int","Number","of","features","coming","as","input","(","number","of","columns",")","cat_dims",":","list","of","int","Number","of","modalities","for","each","categorial","features","If","the","list","is","empty",",","no","embeddings","will","be","done","cat_idxs",":","list","of","int","Positional","index","for","each","categorical","features","in","inputs","cat_emb_dim",":","list","of","int","Embedding","dimension","for","each","categorical","features","If","int",",","the","same","embedding","dimension","will","be","used","for","all","categorical","features","group_matrix",":","torch","matrix","Original","group","matrix","before","embeddings"]
code: def __init__(
      self, input_dim, cat_dims, cat_idxs, cat_emb_dims, group_matrix
  ):
      """This is an embedding module for an entire set of features
  
      Parameters
      ----------
      input_dim : int
          Number of features coming as input (number of columns)
      cat_dims : list of int
          Number of modalities for each categorial features
          If the list is empty, no embeddings will be done
      cat_idxs : list of int
          Positional index for each categorical features in inputs
      cat_emb_dim : list of int
          Embedding dimension for each categorical features
          If int, the same embedding dimension will be used for all categorical features
      group_matrix : torch matrix
          Original group matrix before embeddings
      """
      super(EmbeddingGenerator, self).__init__()
  
      if cat_dims == [] and cat_idxs == []:
          self.skip_embedding = True
          self.post_embed_dim = input_dim
          self.embedding_group_matrix = group_matrix.to(
              group_matrix.device
          )
          return
      else:
          self.skip_embedding = False
  
      self.post_embed_dim = int(
          input_dim + np.sum(cat_emb_dims) - len(cat_emb_dims)
      )
  
      self.embeddings = torch.nn.ModuleList()
  
      for cat_dim, emb_dim in zip(cat_dims, cat_emb_dims):
          self.embeddings.append(torch.nn.Embedding(cat_dim, emb_dim))
  
      # record continuous indices
      self.continuous_idx = torch.ones(input_dim, dtype=torch.bool)
      self.continuous_idx[cat_idxs] = 0
  
      # update group matrix
      n_groups = group_matrix.shape[0]
      self.embedding_group_matrix = torch.empty(
          (n_groups, self.post_embed_dim), device=group_matrix.device
      )
      for group_idx in range(n_groups):
          post_emb_idx = 0
          cat_feat_counter = 0
          for init_feat_idx in range(input_dim):
              if self.continuous_idx[init_feat_idx] == 1:
                  # this means that no embedding is applied to this column
                  self.embedding_group_matrix[
                      group_idx, post_emb_idx
                  ] = group_matrix[
                      group_idx, init_feat_idx
                  ]  # noqa
                  post_emb_idx += 1
              else:
                  # this is a categorical feature which creates multiple embeddings
                  n_embeddings = cat_emb_dims[cat_feat_counter]
                  self.embedding_group_matrix[
                      group_idx,
                      post_emb_idx : post_emb_idx + n_embeddings,
                  ] = (
                      group_matrix[group_idx, init_feat_idx]
                      / n_embeddings
                  )  # noqa
                  post_emb_idx += n_embeddings
                  cat_feat_counter += 1
  
imports: import torch
  from torch.nn import Linear, BatchNorm1d, ReLU
  import numpy
  from pytorch_tabnet import sparsemax
label_desc: Use image node_id 1 to create a new EmbeddingGenerator object from inherited base classes: torch.nn with example: obj = EmbeddingGenerator(input_dim, cat_dims, cat_idxs, cat_emb_dims, group_matrix)