class_docstr: Dataset class for translation task.
  By default, the source language shares the same vocabulary with the target language.
class_docstr_tok: ["Dataset","class","for","translation","task",".","By","default",",","the","source","language","shares","the","same","vocabulary","with","the","target","language","."]
docstr: Create a batched graph correspond to the mini-batch of the dataset.
  args:
      graph_pool: a GraphPool object for accelerating.
      mode: train/valid/test
      batch_size: batch size
      k: beam size(only required for test)
      device: str or torch.device
      dev_rank: rank (id) of current device
      ndev: number of devices
docstr_tok: ["Create","a","batched","graph","correspond","to","the","mini-batch","of","the","dataset",".","args",":","graph_pool",":","a","GraphPool","object","for","accelerating",".","mode",":","train\/valid\/test","batch_size",":","batch","size","k",":","beam","size","(","only","required","for","test",")","device",":","str","or","torch.device","dev_rank",":","rank","(","id",")","of","current","device","ndev",":","number","of","devices"]
code: def __call__(
      self,
      graph_pool,
      mode="train",
      batch_size=32,
      k=1,
      device="cpu",
      dev_rank=0,
      ndev=1,
  ):
      """
      Create a batched graph correspond to the mini-batch of the dataset.
      args:
          graph_pool: a GraphPool object for accelerating.
          mode: train/valid/test
          batch_size: batch size
          k: beam size(only required for test)
          device: str or torch.device
          dev_rank: rank (id) of current device
          ndev: number of devices
      """
      src_data, tgt_data = self.src[mode], self.tgt[mode]
      n = len(src_data)
      # make sure all devices have the same number of batch
      n = n // ndev * ndev
  
      # XXX: partition then shuffle may not be equivalent to shuffle then
      # partition
      order = list(range(dev_rank, n, ndev))
      if mode == "train":
          random.shuffle(order)
  
      src_buf, tgt_buf = [], []
  
      for idx in order:
          src_sample = self.src_field(src_data[idx].strip().split())
          tgt_sample = self.tgt_field(tgt_data[idx].strip().split())
          src_buf.append(src_sample)
          tgt_buf.append(tgt_sample)
          if len(src_buf) == batch_size:
              if mode == "test":
                  yield graph_pool.beam(
                      src_buf,
                      self.sos_id,
                      self.MAX_LENGTH,
                      k,
                      device=device,
                  )
              else:
                  yield graph_pool(src_buf, tgt_buf, device=device)
              src_buf, tgt_buf = [], []
  
      if len(src_buf) != 0:
          if mode == "test":
              yield graph_pool.beam(
                  src_buf,
                  self.sos_id,
                  self.MAX_LENGTH,
                  k,
                  device=device,
              )
          else:
              yield graph_pool(src_buf, tgt_buf, device=device)
  
file_path: dgl/examples/pytorch/transformer/dataset/__init__.py
imports: import os
  import random
  from .fields import *
  from .graph import *
  from .utils import prepare_dataset
label_desc: Use image node_id 8 for calling the TranslationDataset obj's underlying member method code with example usage: obj.__call__(graph_pool, mode, batch_size, k, device, dev_rank, ndev) without return types