class_docstr: Implementation for a Bi-directional Luna based Sentence Encoder used
  in masked pre-trained language models.
  This first computes the token embedding using the token embedding matrix,
  position embeddings (if specified) and segment embeddings
  (if specified). After applying the specified number of
  TransformerEncoderLayers, it outputs all the internal states of the
  encoder as well as the final representation associated with the first
  token (usually CLS token).
  Input:
      - tokens: B x T matrix representing sentences
      - segment_labels: B x T matrix representing segment label for tokens
  Output:
      - a tuple of the following:
          - a list of internal model states used to compute the
            predictions where each tensor has shape T x B x C
          - sentence representation associated with first input token
            in format B x C.
class_docstr_tok: ["Implementation","for","a","Bi-directional","Luna","based","Sentence","Encoder","used","in","masked","pre-trained","language","models",".","This","first","computes","the","token","embedding","using","the","token","embedding","matrix",",","position","embeddings","(","if","specified",")","and","segment","embeddings","(","if","specified",")",".","After","applying","the","specified","number","of","TransformerEncoderLayers",",","it","outputs","all","the","internal","states","of","the","encoder","as","well","as","the","final","representation","associated","with","the","first","token","(","usually","CLS","token",")",".","Input",":","-","tokens",":","B","x","T","matrix","representing","sentences","-","segment_labels",":","B","x","T","matrix","representing","segment","label","for","tokens","Output",":","-","a","tuple","of","the","following",":","-","a","list","of","internal","model","states","used","to","compute","the","predictions","where","each","tensor","has","shape","T","x","B","x","C","-","sentence","representation","associated","with","first","input","token","in","format","B","x","C","."]
code: def build_luna_sentence_encoder_layer(
      self,
      embedding_dim,
      ffn_embedding_dim,
      num_attention_heads,
      num_projected_attention_heads,
      dropout,
      attention_dropout,
      activation_dropout,
      activation_fn,
      normalize_before,
      tie_kv,
      export,
      q_noise,
      qn_block_size,
  ):
      return LunaSentenceEncoderLayer(
          embedding_dim=embedding_dim,
          ffn_embedding_dim=ffn_embedding_dim,
          num_attention_heads=num_attention_heads,
          num_projected_attention_heads=num_projected_attention_heads,
          dropout=dropout,
          attention_dropout=attention_dropout,
          activation_dropout=activation_dropout,
          activation_fn=activation_fn,
          normalize_before=normalize_before,
          tie_kv=tie_kv,
          export=export,
          q_noise=q_noise,
          qn_block_size=qn_block_size,
      )
  
imports: import math
  from typing import Callable, Optional
  import torch
  from fairseq import utils
  from fairseq.modules import LayerDropModuleList, LayerNorm, PositionalEmbedding
  from fairseq.modules.fairseq_dropout import FairseqDropout
  from pytext.utils.usage import log_class_usage
  from torch import nn
  from torch.nn import Parameter
  from .None import LunarMultiheadAttention
label_desc: Use image node_id 3 for calling the LunaSentenceEncoder obj's underlying member method code with example usage: obj.build_luna_sentence_encoder_layer(embedding_dim, ffn_embedding_dim, num_attention_heads, num_projected_attention_heads, dropout, attention_dropout, activation_dropout, activation_fn, normalize_before, tie_kv, export, q_noise, qn_block_size) and returns: LunaSentenceEncoderLayer