text: from pathlib import Path
  
  import numpy as np
  import scipy.sparse as sp
  import torch
  from torch_sparse import coalesce
  
  from torch_geometric.data import (Data, InMemoryDataset, download_url,
                                    extract_zip)
  
  
  class Reddit(InMemoryDataset):
      r"""The Reddit dataset from the `"Inductive Representation Learning on
      Large Graphs" <https://arxiv.org/abs/1706.02216>`_ paper, containing
      Reddit posts belonging to different communities.
  
      Args:
          root (string): Root directory where the dataset should be saved.
          transform (callable, optional): A function/transform that takes in an
              :obj:`torch_geometric.data.Data` object and returns a transformed
              version. The data object will be transformed before every access.
              (default: :obj:`None`)
          pre_transform (callable, optional): A function/transform that takes in
              an :obj:`torch_geometric.data.Data` object and returns a
              transformed version. The data object will be transformed before
              being saved to disk. (default: :obj:`None`)
  
      Stats:
          .. list-table::
              :widths: 10 10 10 10
              :header-rows: 1
  
              * - #nodes
                - #edges
                - #features
                - #classes
              * - 232,965
                - 114,615,892
                - 602
                - 41
      """
  
      url = 'https://data.dgl.ai/dataset/reddit.zip'
  
      def __init__(self, root, transform=None, pre_transform=None):
          super().__init__(root, transform, pre_transform)
          self.data, self.slices = torch.load(self.processed_paths[0])
  
      @property
      def raw_file_names(self):
          return ['reddit_data.npz', 'reddit_graph.npz']
  
      @property
      def processed_file_names(self):
          return 'data.pt'
  
      def download(self):
          path = download_url(self.url, self.raw_dir)
          extract_zip(path, self.raw_dir)
          Path(path).unlink()
  
      def process(self):
          data = np.load(Path.joinpath(Path(self.raw_dir), 'reddit_data.npz'))
          x = torch.from_numpy(data['feature']).to(torch.float)
          y = torch.from_numpy(data['label']).to(torch.long)
          split = torch.from_numpy(data['node_types'])
  
          adj = sp.load_npz(Path.joinpath(Path(self.raw_dir),
                                          'reddit_graph.npz'))
          row = torch.from_numpy(adj.row).to(torch.long)
          col = torch.from_numpy(adj.col).to(torch.long)
          edge_index = torch.stack([row, col], dim=0)
          edge_index, _ = coalesce(edge_index, None, x.size(0), x.size(0))
  
          data = Data(x=x, edge_index=edge_index, y=y)
          data.train_mask = split == 1
          data.val_mask = split == 2
          data.test_mask = split == 3
  
          data = data if self.pre_transform is None else self.pre_transform(data)
  
          torch.save(self.collate([data]), self.processed_paths[0])
  