class_docstr: Style token layer module.
  
  This module is style token layer introduced in `Style Tokens: Unsupervised Style
  Modeling, Control and Transfer in End-to-End Speech Synthesis`.
  
  .. _`Style Tokens: Unsupervised Style Modeling, Control and Transfer in End-to-End
      Speech Synthesis`: https://arxiv.org/abs/1803.09017
  
  Args:
      ref_embed_dim (int, optional): Dimension of the input reference embedding.
      gst_tokens (int, optional): The number of GST embeddings.
      gst_token_dim (int, optional): Dimension of each GST embedding.
      gst_heads (int, optional): The number of heads in GST multihead attention.
      dropout_rate (float, optional): Dropout rate in multi-head attention.
class_docstr_tok: ["Style","token","layer","module",".","This","module","is","style","token","layer","introduced","in","`","Style","Tokens",":","Unsupervised","Style","Modeling",",","Control","and","Transfer","in","End-to-End","Speech","Synthesis","`",".","..","_","`","Style","Tokens",":","Unsupervised","Style","Modeling",",","Control","and","Transfer","in","End-to-End","Speech","Synthesis","`",":","https",":","\/\/arxiv.org\/abs\/1803.09017","Args",":","ref_embed_dim","(","int",",","optional",")",":","Dimension","of","the","input","reference","embedding",".","gst_tokens","(","int",",","optional",")",":","The","number","of","GST","embeddings",".","gst_token_dim","(","int",",","optional",")",":","Dimension","of","each","GST","embedding",".","gst_heads","(","int",",","optional",")",":","The","number","of","heads","in","GST","multihead","attention",".","dropout_rate","(","float",",","optional",")",":","Dropout","rate","in","multi-head","attention","."]
docstr: Calculate forward propagation.
  
  Args:
      ref_embs (Tensor): Reference embeddings (B, ref_embed_dim).
  
  Returns:
      Tensor: Style token embeddings (B, gst_token_dim).
docstr_tok: ["Calculate","forward","propagation",".","Args",":","ref_embs","(","Tensor",")",":","Reference","embeddings","(","B",",","ref_embed_dim",")",".","Returns",":","Tensor",":","Style","token","embeddings","(","B",",","gst_token_dim",")","."]
code: def forward(self, ref_embs: torch.Tensor) -> torch.Tensor:
      """Calculate forward propagation.
  
      Args:
          ref_embs (Tensor): Reference embeddings (B, ref_embed_dim).
  
      Returns:
          Tensor: Style token embeddings (B, gst_token_dim).
  
      """
      batch_size = ref_embs.size(0)
      # (num_tokens, token_dim) -> (batch_size, num_tokens, token_dim)
      gst_embs = (
          torch.tanh(self.gst_embs)
          .unsqueeze(0)
          .expand(batch_size, -1, -1)
      )
      # NOTE(kan-bayashi): Shoule we apply Tanh?
      ref_embs = ref_embs.unsqueeze(1)  # (batch_size, 1 ,ref_embed_dim)
      style_embs = self.mha(ref_embs, gst_embs, gst_embs, None)
  
      return style_embs.squeeze(1)
  
file_path: espnet/espnet2/tts/gst/style_encoder.py
imports: from typing import Sequence
  import torch
  from typeguard import check_argument_types
  from espnet.nets.pytorch_backend.transformer.attention import MultiHeadedAttention
label_desc: Use image node_id 2 for calling the StyleTokenLayer obj's underlying member method code with example usage: obj.forward(ref_embs) and returns: style_embs