docstr: Similar to *forward* but only return features.
  
  Inputs:
      prev_output_tokens: Tensor(B, T)
      encoder_out: a dictionary of hidden states and masks
  
  Returns:
      tuple:
          - the decoder's features of shape `(batch, tgt_len, embed_dim)`
          - a dictionary with any model-specific outputs
      the LevenshteinTransformer decoder has full-attention to all generated tokens
docstr_tok: ["Similar","to","*","forward","*","but","only","return","features",".","Inputs",":","prev_output_tokens",":","Tensor","(","B",",","T",")","encoder_out",":","a","dictionary","of","hidden","states","and","masks","Returns",":","tuple",":","-","the","decoder","'s","features","of","shape","`","(","batch",",","tgt_len",",","embed_dim",")","`","-","a","dictionary","with","any","model-specific","outputs","the","LevenshteinTransformer","decoder","has","full-attention","to","all","generated","tokens"]
code: def extract_features(
      self,
      prev_output_tokens,
      encoder_out=None,
      early_exit=None,
      embedding_copy=False,
      **unused,
  ):
      """
      Similar to *forward* but only return features.
  
      Inputs:
          prev_output_tokens: Tensor(B, T)
          encoder_out: a dictionary of hidden states and masks
  
      Returns:
          tuple:
              - the decoder's features of shape `(batch, tgt_len, embed_dim)`
              - a dictionary with any model-specific outputs
          the LevenshteinTransformer decoder has full-attention to all generated tokens
      """
      # embedding
      if embedding_copy:
          src_embd = encoder_out["encoder_embedding"][0]
          if len(encoder_out["encoder_padding_mask"]) > 0:
              src_mask = encoder_out["encoder_padding_mask"][0]
          else:
              src_mask = None
          src_mask = (
              ~src_mask
              if src_mask is not None
              else prev_output_tokens.new_ones(
                  *src_embd.size()[:2]
              ).bool()
          )
  
          x, decoder_padding_mask = self.forward_embedding(
              prev_output_tokens,
              self.forward_copying_source(
                  src_embd,
                  src_mask,
                  prev_output_tokens.ne(self.padding_idx),
              ),
          )
  
      else:
          x, decoder_padding_mask = self.forward_embedding(
              prev_output_tokens
          )
  
      # B x T x C -> T x B x C
      x = x.transpose(0, 1)
      attn = None
      inner_states = [x]
  
      # decoder layers
      for i, layer in enumerate(self.layers):
          # early exit from the decoder.
          if (early_exit is not None) and (i >= early_exit):
              break
  
          x, attn, _ = layer(
              x,
              encoder_out["encoder_out"][0]
              if (
                  encoder_out is not None
                  and len(encoder_out["encoder_out"]) > 0
              )
              else None,
              encoder_out["encoder_padding_mask"][0]
              if (
                  encoder_out is not None
                  and len(encoder_out["encoder_padding_mask"]) > 0
              )
              else None,
              self_attn_mask=None,
              self_attn_padding_mask=decoder_padding_mask,
          )
          inner_states.append(x)
  
      if self.layer_norm:
          x = self.layer_norm(x)
  
      # T x B x C -> B x T x C
      x = x.transpose(0, 1)
  
      if self.project_out_dim is not None:
          x = self.project_out_dim(x)
  
      return x, {"attn": attn, "inner_states": inner_states}
  
imports: import torch
  import torch.nn.functional
  from fairseq import utils
  from fairseq.iterative_refinement_generator import DecoderOut
  from fairseq.models import register_model, register_model_architecture
  from fairseq.models.nat import FairseqNATDecoder, FairseqNATModel, ensemble_decoder
  from fairseq.models.transformer import Embedding
  from fairseq.modules.transformer_sentence_encoder import init_bert_params
label_desc: Use image node_id 4 for calling the NATransformerDecoder obj's underlying member method code with example usage: obj.extract_features(prev_output_tokens, encoder_out, early_exit, embedding_copy) and returns: x,  dict