class_docstr: Transformer Ranker Agent.
  
  Implementation of a TorchRankerAgent, where the model is a Transformer
docstr: Override so that we can add memories to the Batch object.
docstr_tok: ["Override","so","that","we","can","add","memories","to","the","Batch","object","."]
code: def batchify(self, obs_batch, sort=False):
      """
      Override so that we can add memories to the Batch object.
      """
      batch = super().batchify(obs_batch, sort)
      if self.opt["use_memories"]:
          valid_obs = [
              (i, ex)
              for i, ex in enumerate(obs_batch)
              if self.is_valid(ex)
          ]
          valid_inds, exs = zip(*valid_obs)
          mems = None
          if any("memory_vecs" in ex for ex in exs):
              mems = [ex.get("memory_vecs", None) for ex in exs]
          batch.memory_vecs = mems
      return batch
  
imports: from typing import Optional
  from parlai.core.params import ParlaiParser
  from parlai.core.opt import Opt
  from parlai.core.agents import Agent
  from parlai.utils.torch import padded_3d
  from parlai.core.torch_classifier_agent import TorchClassifierAgent
  from parlai.core.torch_ranker_agent import TorchRankerAgent
  from parlai.core.torch_generator_agent import TorchGeneratorAgent
  from parlai.utils.misc import recursive_getattr, warn_once
  from parlai.utils.logging import logging
  from parlai.utils.fsdp import should_use_fsdp
  from .modules import TransformerMemNetModel, TransformerGeneratorModel, TransformerLinearWrapper
  import torch
label_desc: Use image node_id 4 for calling the TransformerRankerAgent obj's underlying member method code with example usage: obj.batchify(obs_batch, sort) and returns: batch