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,
      layers=None,
      **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
      """
      # embed positions
      positions = (
          self.embed_positions(prev_output_tokens)
          if self.embed_positions is not None
          else None
      )
  
      # embed tokens and positions
      x = self.embed_scale * self.embed_tokens(prev_output_tokens)
      if self.project_in_dim is not None:
          x = self.project_in_dim(x)
  
      if positions is not None:
          x += positions
      x = self.dropout_module(x)
  
      # B x T x C -> T x B x C
      x = x.transpose(0, 1)
      attn = None
      inner_states = [x]
  
      # decoder layers
      decoder_padding_mask = prev_output_tokens.eq(self.padding_idx)
      layers = self.layers if layers is None else layers
      early_exit = len(layers) if early_exit is None else early_exit
      for _, layer in enumerate(layers[:early_exit]):
          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
  import torch.nn.functional
  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 import TransformerDecoderLayer
  from fairseq.modules.transformer_sentence_encoder import init_bert_params
  from .levenshtein_utils import _apply_del_words, _apply_ins_masks, _apply_ins_words, _fill, _get_del_targets, _get_ins_targets, _skip, _skip_encoder_out
label_desc: Use image node_id 2 for calling the LevenshteinTransformerDecoder obj's underlying member method code with example usage: obj.extract_features(prev_output_tokens, encoder_out, early_exit, layers) and returns: x,  dict