docstr: Add action and attribute supervision for batches.
  
  Store history vec as context_vec.
docstr_tok: ["Add","action","and","attribute","supervision","for","batches",".","Store","history","vec","as","context_vec","."]
code: def batchify(self, obs_batch, sort=True):
      """
      Add action and attribute supervision for batches.
  
      Store history vec as context_vec.
      """
      # NOTE: `sort` is set to True here (Default is False in TorchGeneratorAgent)
      # TODO: Sorting the batch will result in various local metrics being broadcasted
      # back to individual examples in the wrong order, such as the lengths of
      # the context and labels. Aggregate metric reports will still be accurate.
      batch = super().batchify(obs_batch, sort)
      # sum here is list concat, not addition
      context_vec, hist_lens_ = self._pad_tensor(
          sum(
              [
                  obs_batch[i]["context_vec"]
                  for i in batch.valid_indices
              ],
              [],
          )
      )
      batch["context_vec"] = context_vec
      batch["hist_lens"] = torch.LongTensor(
          [
              len(obs_batch[i]["context_vec"])
              for i in batch.valid_indices
          ]
      )
      return batch
  
file_path: ParlAI/parlai/agents/hred/hred.py
imports: from typing import Optional
  from parlai.core.params import ParlaiParser
  from parlai.core.opt import Opt
  import torch
  from parlai.agents.seq2seq.modules import opt_to_kwargs
  from parlai.core.torch_generator_agent import TorchGeneratorAgent
  from .modules import HredModel
label_desc: Use image node_id 4 for calling the HredAgent obj's underlying member method code with example usage: obj.batchify(obs_batch, sort) and returns: batch