docstr: Generate the representation given the inputs.
  
  This is used for pre-training or fine-tuning a BART model.
  In BART, the pooled output is the embedding of the last token.
  
  Parameters
  ----------
  sequence
      - layout = 'NT'
          Shape (batch_size, sequence_length, units)
      - layout = 'TN'
          Shape (sequence_length, batch_size, units)
  
  valid_length
      Valid length of each sequence
      Shape (batch_size,)
  
  Returns
  -------
  outputs
      Shape (batch_size, units)
docstr_tok: ["Generate","the","representation","given","the","inputs",".","This","is","used","for","pre-training","or","fine-tuning","a","BART","model",".","In","BART",",","the","pooled","output","is","the","embedding","of","the","last","token",".","Parameters","--","--","--","--","--","sequence","-","layout","=","'NT'","Shape","(","batch_size",",","sequence_length",",","units",")","-","layout","=","'TN'","Shape","(","sequence_length",",","batch_size",",","units",")","valid_length","Valid","length","of","each","sequence","Shape","(","batch_size",",",")","Returns","--","--","--","-","outputs","Shape","(","batch_size",",","units",")"]
code: def apply_pooling(self, sequence, valid_length):
      """Generate the representation given the inputs.
  
      This is used for pre-training or fine-tuning a BART model.
      In BART, the pooled output is the embedding of the last token.
  
      Parameters
      ----------
      sequence
          - layout = 'NT'
              Shape (batch_size, sequence_length, units)
          - layout = 'TN'
              Shape (sequence_length, batch_size, units)
  
      valid_length
          Valid length of each sequence
          Shape (batch_size,)
  
      Returns
      -------
      outputs
          Shape (batch_size, units)
      """
      if self._layout == "NT":
          batch_indices = mx.npx.arange_like(sequence, axis=0).astype(
              mx.np.int32
          )
          outputs = sequence[batch_indices, valid_length - 1]
      elif self._layout == "TN":
          batch_indices = mx.npx.arange_like(sequence, axis=1).astype(
              mx.np.int32
          )
          outputs = sequence[valid_length - 1, batch_indices]
      else:
          raise NotImplementedError
      if self.classifier_activation:
          return self.pooler(outputs)
      else:
          return outputs
  
imports: import os
  from typing import Tuple, List
  import mxnet
  from mxnet import use_np
  from mxnet.gluon import nn
  from .base import BACKBONE_REGISTRY
  from .transformer import TransformerModel
  from ..base import get_model_zoo_home_dir, get_repo_model_zoo_url, get_model_zoo_checksum_dir
  from ..utils.misc import download, load_checksum_stats
  from ..utils.config import CfgNode
  from ..utils.registry import Registry
  from ..data.tokenizers import HuggingFaceByteBPETokenizer
label_desc: Use image node_id 3 for calling the BartModel obj's underlying member method code with example usage: obj.apply_pooling(sequence, valid_length) and returns: self, outputs