code: def extract_features(
      self,
      prev_outputs,
      encoder_out=None,
      incremental_state=None,
      target_lengths=None,
      speaker=None,
      **kwargs,
  ):
      alignment_layer = self.n_transformer_layers - 1
      self_attn_padding_mask = lengths_to_padding_mask(target_lengths)
      positions = self.embed_positions(
          self_attn_padding_mask, incremental_state=incremental_state
      )
  
      if incremental_state is not None:
          prev_outputs = prev_outputs[:, -1:, :]
          self_attn_padding_mask = self_attn_padding_mask[:, -1:]
          if positions is not None:
              positions = positions[:, -1:]
  
      x = self.prenet(prev_outputs)
      x += self.pos_emb_alpha * positions
      x = self.dropout_module(x)
  
      # B x T x C -> T x B x C
      x = x.transpose(0, 1)
  
      if not self_attn_padding_mask.any():
          self_attn_padding_mask = None
  
      attn: Optional[torch.Tensor] = None
      inner_states: List[Optional[torch.Tensor]] = [x]
      for idx, transformer_layer in enumerate(self.transformer_layers):
          if incremental_state is None:
              self_attn_mask = self.buffered_future_mask(x)
          else:
              self_attn_mask = None
  
          x, layer_attn, _ = transformer_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,
              incremental_state,
              self_attn_mask=self_attn_mask,
              self_attn_padding_mask=self_attn_padding_mask,
              need_attn=bool((idx == alignment_layer)),
              need_head_weights=bool((idx == alignment_layer)),
          )
          inner_states.append(x)
          if layer_attn is not None and idx == alignment_layer:
              attn = layer_attn.float().to(x)
  
      if attn is not None:
          # average probabilities over heads, transpose to
          # (B, src_len, tgt_len)
          attn = attn.mean(dim=0).transpose(2, 1)
  
      if self.layer_norm is not None:
          x = self.layer_norm(x)
  
      # T x B x C -> B x T x C
      x = x.transpose(0, 1)
  
      return x, {"attn": attn, "inner_states": inner_states}
  
imports: import logging
  from typing import List, Optional
  import torch
  from torch import nn
  from fairseq import utils
  from fairseq.data.data_utils import lengths_to_padding_mask
  from fairseq.models import FairseqEncoder, FairseqEncoderDecoderModel, FairseqIncrementalDecoder, register_model, register_model_architecture
  from fairseq.models.text_to_speech.hub_interface import TTSHubInterface
  from fairseq.models.text_to_speech.tacotron2 import Postnet, Prenet
  from fairseq.modules import FairseqDropout, LayerNorm, PositionalEmbedding, TransformerDecoderLayer, TransformerEncoderLayer
label_desc: Use image node_id 2 for calling the TTSTransformerDecoder obj's underlying member method code with example usage: obj.extract_features(prev_outputs, encoder_out, incremental_state, target_lengths, speaker) and returns: x,  dict