docstr: Projection based on embedding's weight. For example, embedding map vocab_size to embed_size, than projection map embed_size back to vocab_size.
  Args:
      x (:obj:`torch.Tensor` of shape ``(batch, seq_len, dim_model)``): Input of projection
      ext_table (:obj:`torch.Tensor` of shape ``(ext_table_size, dim_model)``): Ext vocab table.
  Returns:
      :obj:`torch.Tensor` of shape ``(batch, seq_len, vocab_size + ext_table_size)``: The projection output.
docstr_tok: ["Projection","based","on","embedding","'s","weight",".","For","example",",","embedding","map","vocab_size","to","embed_size",",","than","projection","map","embed_size","back","to","vocab_size",".","Args",":","x","(",":","obj",":","`","torch.Tensor","`","of","shape","``","(","batch",",","seq_len",",","dim_model",")","``",")",":","Input","of","projection","ext_table","(",":","obj",":","`","torch.Tensor","`","of","shape","``","(","ext_table_size",",","dim_model",")","``",")",":","Ext","vocab","table",".","Returns",":",":","obj",":","`","torch.Tensor","`","of","shape","``","(","batch",",","seq_len",",","vocab_size","+","ext_table_size",")","``",":","The","projection","output","."]
code: def projection(
      self, x: torch.Tensor, ext_table: Optional[torch.Tensor] = None
  ):
      """
      Projection based on embedding's weight. For example, embedding map vocab_size to embed_size, than projection map embed_size back to vocab_size.
      Args:
          x (:obj:`torch.Tensor` of shape ``(batch, seq_len, dim_model)``): Input of projection
          ext_table (:obj:`torch.Tensor` of shape ``(ext_table_size, dim_model)``): Ext vocab table.
      Returns:
          :obj:`torch.Tensor` of shape ``(batch, seq_len, vocab_size + ext_table_size)``: The projection output.
      """  # noqa: E501
      logits = F.linear(x / math.sqrt(self.dim_model), self.weight)
      if ext_table is not None:
          logits_ext = F.linear(x, ext_table)
          logits = torch.cat([logits, logits_ext], dim=-1)
      return logits
  
file_path: DeepKE/example/llm/CPM-Bee/src/cpm_live/layers/embedding.py
imports: from typing import Optional
  import torch
  import bmtrain
  import math
  import torch.nn.functional
  from .position_embedding import RotaryEmbedding
label_desc: Use image node_id 3 for calling the EmbeddingExt obj's underlying member method code with example usage: obj.projection(x, ext_table) and returns: logits