class_docstr: The Node2Vec model from the
  `"node2vec: Scalable Feature Learning for Networks"
  <https://arxiv.org/abs/1607.00653>`_ paper where random walks of
  length :obj:`walk_length` are sampled in a given graph, and node embeddings
  are learned via negative sampling optimization.
  
  .. note::
  
      For an example of using Node2Vec, see `examples/node2vec.py
      <https://github.com/pyg-team/pytorch_geometric/blob/master/examples/
      node2vec.py>`_.
  
  Args:
      edge_index (torch.Tensor): The edge indices.
      embedding_dim (int): The size of each embedding vector.
      walk_length (int): The walk length.
      context_size (int): The actual context size which is considered for
          positive samples. This parameter increases the effective sampling
          rate by reusing samples across different source nodes.
      walks_per_node (int, optional): The number of walks to sample for each
          node. (default: :obj:`1`)
      p (float, optional): Likelihood of immediately revisiting a node in the
          walk. (default: :obj:`1`)
      q (float, optional): Control parameter to interpolate between
          breadth-first strategy and depth-first strategy (default: :obj:`1`)
      num_negative_samples (int, optional): The number of negative samples to
          use for each positive sample. (default: :obj:`1`)
      num_nodes (int, optional): The number of nodes. (default: :obj:`None`)
      sparse (bool, optional): If set to :obj:`True`, gradients w.r.t. to the
          weight matrix will be sparse. (default: :obj:`False`)
class_docstr_tok: ["The","Node2Vec","model","from","the","`","``","node2vec",":","Scalable","Feature","Learning","for","Networks","''","<","https",":","\/\/arxiv.org\/abs\/1607.00653",">","`","_","paper","where","random","walks","of","length",":","obj",":","`","walk_length","`","are","sampled","in","a","given","graph",",","and","node","embeddings","are","learned","via","negative","sampling","optimization",".","..","note",":",":","For","an","example","of","using","Node2Vec",",","see","`","examples\/node2vec.py","<","https",":","\/\/github.com\/pyg-team\/pytorch_geometric\/blob\/master\/examples\/","node2vec.py",">","`","_",".","Args",":","edge_index","(","torch.Tensor",")",":","The","edge","indices",".","embedding_dim","(","int",")",":","The","size","of","each","embedding","vector",".","walk_length","(","int",")",":","The","walk","length",".","context_size","(","int",")",":","The","actual","context","size","which","is","considered","for","positive","samples",".","This","parameter","increases","the","effective","sampling","rate","by","reusing","samples","across","different","source","nodes",".","walks_per_node","(","int",",","optional",")",":","The","number","of","walks","to","sample","for","each","node",".","(","default",":",":","obj",":","`","1","`",")","p","(","float",",","optional",")",":","Likelihood","of","immediately","revisiting","a","node","in","the","walk",".","(","default",":",":","obj",":","`","1","`",")","q","(","float",",","optional",")",":","Control","parameter","to","interpolate","between","breadth-first","strategy","and","depth-first","strategy","(","default",":",":","obj",":","`","1","`",")","num_negative_samples","(","int",",","optional",")",":","The","number","of","negative","samples","to","use","for","each","positive","sample",".","(","default",":",":","obj",":","`","1","`",")","num_nodes","(","int",",","optional",")",":","The","number","of","nodes",".","(","default",":",":","obj",":","`","None","`",")","sparse","(","bool",",","optional",")",":","If","set","to",":","obj",":","`","True","`",",","gradients","w.r.t",".","to","the","weight","matrix","will","be","sparse",".","(","default",":",":","obj",":","`","False","`",")"]
code: def __init__(
      self,
      edge_index: Tensor,
      embedding_dim: int,
      walk_length: int,
      context_size: int,
      walks_per_node: int = 1,
      p: float = 1.0,
      q: float = 1.0,
      num_negative_samples: int = 1,
      num_nodes: Optional[int] = None,
      sparse: bool = False,
  ):
      super().__init__()
  
      if WITH_PYG_LIB and p == 1.0 and q == 1.0:
          self.random_walk_fn = torch.ops.pyg.random_walk
      elif WITH_TORCH_CLUSTER:
          self.random_walk_fn = torch.ops.torch_cluster.random_walk
      else:
          if p == 1.0 and q == 1.0:
              raise ImportError(
                  f"'{self.__class__.__name__}' "
                  f"requires either the 'pyg-lib' or "
                  f"'torch-cluster' package"
              )
          else:
              raise ImportError(
                  f"'{self.__class__.__name__}' "
                  f"requires the 'torch-cluster' package"
              )
  
      self.num_nodes = maybe_num_nodes(edge_index, num_nodes)
  
      row, col = sort_edge_index(
          edge_index, num_nodes=self.num_nodes
      ).cpu()
      self.rowptr, self.col = index2ptr(row, self.num_nodes), col
  
      self.EPS = 1e-15
      assert walk_length >= context_size
  
      self.embedding_dim = embedding_dim
      self.walk_length = walk_length - 1
      self.context_size = context_size
      self.walks_per_node = walks_per_node
      self.p = p
      self.q = q
      self.num_negative_samples = num_negative_samples
  
      self.embedding = Embedding(
          self.num_nodes, embedding_dim, sparse=sparse
      )
  
      self.reset_parameters()
  
imports: from typing import List, Optional, Tuple, Union
  import torch
  from torch import Tensor
  from torch.nn import Embedding
  from torch.utils.data import DataLoader
  from torch_geometric.typing import WITH_PYG_LIB, WITH_TORCH_CLUSTER
  from torch_geometric.utils import sort_edge_index
  from torch_geometric.utils.num_nodes import maybe_num_nodes
  from torch_geometric.utils.sparse import index2ptr
label_desc: Use image node_id 1 to create a new Node2Vec object from inherited base classes: torch.nn with example: obj = Node2Vec(edge_index, embedding_dim, walk_length, context_size, walks_per_node, p, q, num_negative_samples, num_nodes, sparse)