def generate_samples(self, data_dir, tmp_dir, dataset_split):
    """Downloads and extracts the dataset and generates examples.

    Args:
      data_dir: The base directory where data and vocab files are stored.
      tmp_dir: temp directory to download and extract the dataset.
      dataset_split: split of the data-set.

    Yields:
      The data examples.
    """
    # Create directories if needed.
    if not tf.gfile.Exists(tmp_dir):
      tf.gfile.MakeDirs(tmp_dir)
    if not tf.gfile.Exists(data_dir):
      tf.gfile.MakeDirs(data_dir)

    # Download and extract the data.
    filename = os.path.basename(_URL)
    path = generator_utils.maybe_download(tmp_dir, filename, _URL)
    tarfile.open(path, "r:gz").extractall(tmp_dir)

    # Create the list of directories with data files.
    train_dirs = ["v1.0/train-easy", "v1.0/train-medium", "v1.0/train-hard"]
    eval_dirs = ["v1.0/interpolate", "v1.0/extrapolate"]
    dirs = eval_dirs
    if dataset_split == problem.DatasetSplit.TRAIN:
      dirs = train_dirs
    dirs = [os.path.join(tmp_dir, d) for d in dirs]

    # Iterate over directories and files generating examples.
    for d in dirs:
      files = tf.gfile.Glob(d + "/*.txt")
      for fname in files:
        # In each text file, the first line is the input, the next the answer,
        # and so on until the end of the file.
        cur_input = None
        with tf.gfile.Open(fname, "rb") as f:
          for line in f:
            if cur_input is None:
              cur_input = line.strip()
            else:
              yield {"inputs": cur_input, "targets": line.strip()}
              cur_input = None
Downloads and extracts the dataset and generates examples.

    Args:
      data_dir: The base directory where data and vocab files are stored.
      tmp_dir: temp directory to download and extract the dataset.
      dataset_split: split of the data-set.

    Yields:
      The data examples.
    
tensor2tensor/data_generators/algorithmic_math_deepmind.py