class_docstr: Encoder for Masked Language Modelling.
class_docstr_tok: ["Encoder","for","Masked","Language","Modelling","."]
docstr: Forward pass for Masked LM encoder. This first computes the token
  embedding using the token embedding matrix, position embeddings (if
  specified) and segment embeddings (if specified).
  
  Here we assume that the sentence representation corresponds to the
  output of the classification_token (see bert_task or cross_lingual_lm
  task for more details).
  Args:
      - src_tokens: B x T matrix representing sentences
      - segment_labels: B x T matrix representing segment label for tokens
  Returns:
      - a tuple of the following:
          - logits for predictions in format B x T x C to be used in
            softmax afterwards
          - a dictionary of additional data, where 'pooled_output' contains
            the representation for classification_token and 'inner_states'
            is a list of internal model states used to compute the
            predictions (similar in ELMO). 'sentence_logits'
            is the prediction logit for NSP task and is only computed if
            this is specified in the input arguments.
docstr_tok: ["Forward","pass","for","Masked","LM","encoder",".","This","first","computes","the","token","embedding","using","the","token","embedding","matrix",",","position","embeddings","(","if","specified",")","and","segment","embeddings","(","if","specified",")",".","Here","we","assume","that","the","sentence","representation","corresponds","to","the","output","of","the","classification_token","(","see","bert_task","or","cross_lingual_lm","task","for","more","details",")",".","Args",":","-","src_tokens",":","B","x","T","matrix","representing","sentences","-","segment_labels",":","B","x","T","matrix","representing","segment","label","for","tokens","Returns",":","-","a","tuple","of","the","following",":","-","logits","for","predictions","in","format","B","x","T","x","C","to","be","used","in","softmax","afterwards","-","a","dictionary","of","additional","data",",","where","'pooled_output","'","contains","the","representation","for","classification_token","and","'inner_states'","is","a","list","of","internal","model","states","used","to","compute","the","predictions","(","similar","in","ELMO",")",".","'sentence_logits'","is","the","prediction","logit","for","NSP","task","and","is","only","computed","if","this","is","specified","in","the","input","arguments","."]
code: def forward(
      self,
      src_tokens,
      segment_labels=None,
      masked_tokens=None,
      **unused,
  ):
      """
      Forward pass for Masked LM encoder. This first computes the token
      embedding using the token embedding matrix, position embeddings (if
      specified) and segment embeddings (if specified).
  
      Here we assume that the sentence representation corresponds to the
      output of the classification_token (see bert_task or cross_lingual_lm
      task for more details).
      Args:
          - src_tokens: B x T matrix representing sentences
          - segment_labels: B x T matrix representing segment label for tokens
      Returns:
          - a tuple of the following:
              - logits for predictions in format B x T x C to be used in
                softmax afterwards
              - a dictionary of additional data, where 'pooled_output' contains
                the representation for classification_token and 'inner_states'
                is a list of internal model states used to compute the
                predictions (similar in ELMO). 'sentence_logits'
                is the prediction logit for NSP task and is only computed if
                this is specified in the input arguments.
      """
  
      inner_states, sentence_rep = self.sentence_encoder(
          src_tokens,
          segment_labels=segment_labels,
      )
  
      x = inner_states[-1].transpose(0, 1)
      # project masked tokens only
      if masked_tokens is not None:
          x = x[masked_tokens, :]
      x = self.layer_norm(
          self.activation_fn(self.lm_head_transform_weight(x))
      )
  
      pooled_output = self.pooler_activation(
          self.masked_lm_pooler(sentence_rep)
      )
  
      # project back to size of vocabulary
      if self.share_input_output_embed and hasattr(
          self.sentence_encoder.embed_tokens, "weight"
      ):
          x = F.linear(x, self.sentence_encoder.embed_tokens.weight)
      elif self.embed_out is not None:
          x = self.embed_out(x)
      if self.lm_output_learned_bias is not None:
          x = x + self.lm_output_learned_bias
      sentence_logits = None
      if self.sentence_projection_layer:
          sentence_logits = self.sentence_projection_layer(
              pooled_output
          )
  
      return x, {
          "inner_states": inner_states,
          "pooled_output": pooled_output,
          "sentence_logits": sentence_logits,
      }
  
imports: import logging
  import torch
  import torch.nn
  import torch.nn.functional
  from fairseq import utils
  from fairseq.models import FairseqEncoder, FairseqEncoderModel, register_model, register_model_architecture
  from fairseq.modules import LayerNorm, SinusoidalPositionalEmbedding, TransformerSentenceEncoder
  from fairseq.modules.transformer_sentence_encoder import init_bert_params
  from fairseq.utils import safe_hasattr
label_desc: Use image node_id 2 for calling the MaskedLMEncoder obj's underlying member method code with example usage: obj.forward(src_tokens, segment_labels, masked_tokens) and returns: x,  dict