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","."]
code: def __init__(
      self,
      path,
      exts,
      train="train",
      valid="valid",
      test="test",
      vocab="vocab.txt",
      replace_oov=None,
  ):
      vocab_path = os.path.join(path, vocab)
      self.src = {}
      self.tgt = {}
      with open(
          os.path.join(path, train + "." + exts[0]),
          "r",
          encoding="utf-8",
      ) as f:
          self.src["train"] = f.readlines()
      with open(
          os.path.join(path, train + "." + exts[1]),
          "r",
          encoding="utf-8",
      ) as f:
          self.tgt["train"] = f.readlines()
      with open(
          os.path.join(path, valid + "." + exts[0]),
          "r",
          encoding="utf-8",
      ) as f:
          self.src["valid"] = f.readlines()
      with open(
          os.path.join(path, valid + "." + exts[1]),
          "r",
          encoding="utf-8",
      ) as f:
          self.tgt["valid"] = f.readlines()
      with open(
          os.path.join(path, test + "." + exts[0]),
          "r",
          encoding="utf-8",
      ) as f:
          self.src["test"] = f.readlines()
      with open(
          os.path.join(path, test + "." + exts[1]),
          "r",
          encoding="utf-8",
      ) as f:
          self.tgt["test"] = f.readlines()
  
      if not os.path.exists(vocab_path):
          self._make_vocab(vocab_path)
  
      vocab = Vocab(
          init_token=self.INIT_TOKEN,
          eos_token=self.EOS_TOKEN,
          pad_token=self.PAD_TOKEN,
          unk_token=replace_oov,
      )
      vocab.load(vocab_path)
      self.vocab = vocab
      strip_func = lambda x: x[: self.MAX_LENGTH]
      self.src_field = Field(
          vocab, preprocessing=None, postprocessing=strip_func
      )
      self.tgt_field = Field(
          vocab,
          preprocessing=lambda seq: [self.INIT_TOKEN]
          + seq
          + [self.EOS_TOKEN],
          postprocessing=strip_func,
      )
  
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 1 to create a new TranslationDataset object from inherited base classes: object with example: obj = TranslationDataset(path, exts, train, valid, test, vocab, replace_oov)