class_docstr: Wrapper of the ``Node2Vec`` class with a ``train`` method.
  Attributes
  ----------
  g: DGLGraph
      The graph.
  embedding_dim: int
      Dimension of node embedding.
  walk_length: int
      Length of each trace.
  p: float
      Likelihood of immediately revisiting a node in the walk.
  q: float
      Control parameter to interpolate between breadth-first strategy and depth-first strategy.
  num_walks: int
      Number of random walks for each node. Default: 10.
  window_size: int
      Maximum distance between the center node and predicted node. Default: 5.
  num_negatives: int
      The number of negative samples for each positive sample.  Default: 5.
  use_sparse: bool
      If set to True, uses PyTorch's sparse embedding and optimizer. Default: ``True``.
  weight_name : str, optional
      The name of the edge feature tensor on the graph storing the (unnormalized)
      probabilities associated with each edge for choosing the next node.
  
      The feature tensor must be non-negative and the sum of the probabilities
      must be positive for the outbound edges of all nodes (although they don't have
      to sum up to one).  The result will be undefined otherwise.
  
      If omitted, DGL assumes that the neighbors are picked uniformly. Default: ``None``.
  eval_set: list of tuples (Tensor, Tensor)
      [(nodes_train,y_train),(nodes_val,y_val)]
      If omitted, model will not be evaluated. Default: ``None``.
  eval_steps: int
      Interval steps of evaluation.
      if set <= 0, model will not be evaluated. Default: ``None``.
  device: str
      device, default 'cpu'.
class_docstr_tok: ["Wrapper","of","the","``","Node2Vec","``","class","with","a","``","train","``","method",".","Attributes","--","--","--","--","--","g",":","DGLGraph","The","graph",".","embedding_dim",":","int","Dimension","of","node","embedding",".","walk_length",":","int","Length","of","each","trace",".","p",":","float","Likelihood","of","immediately","revisiting","a","node","in","the","walk",".","q",":","float","Control","parameter","to","interpolate","between","breadth-first","strategy","and","depth-first","strategy",".","num_walks",":","int","Number","of","random","walks","for","each","node",".","Default",":","10.","window_size",":","int","Maximum","distance","between","the","center","node","and","predicted","node",".","Default",":","5.","num_negatives",":","int","The","number","of","negative","samples","for","each","positive","sample",".","Default",":","5.","use_sparse",":","bool","If","set","to","True",",","uses","PyTorch","'s","sparse","embedding","and","optimizer",".","Default",":","``","True","``",".","weight_name",":","str",",","optional","The","name","of","the","edge","feature","tensor","on","the","graph","storing","the","(","unnormalized",")","probabilities","associated","with","each","edge","for","choosing","the","next","node",".","The","feature","tensor","must","be","non-negative","and","the","sum","of","the","probabilities","must","be","positive","for","the","outbound","edges","of","all","nodes","(","although","they","do","n't","have","to","sum","up","to","one",")",".","The","result","will","be","undefined","otherwise",".","If","omitted",",","DGL","assumes","that","the","neighbors","are","picked","uniformly",".","Default",":","``","None","``",".","eval_set",":","list","of","tuples","(","Tensor",",","Tensor",")","[","(","nodes_train",",","y_train",")",",","(","nodes_val",",","y_val",")","]","If","omitted",",","model","will","not","be","evaluated",".","Default",":","``","None","``",".","eval_steps",":","int","Interval","steps","of","evaluation",".","if","set","<","=","0",",","model","will","not","be","evaluated",".","Default",":","``","None","``",".","device",":","str","device",",","default","'cpu","'","."]
code: def _train_step(self, model, loader, optimizer, device):
      model.train()
      total_loss = 0
      for pos_traces, neg_traces in loader:
          pos_traces, neg_traces = pos_traces.to(device), neg_traces.to(
              device
          )
          optimizer.zero_grad()
          loss = model.loss(pos_traces, neg_traces)
          loss.backward()
          optimizer.step()
          total_loss += loss.item()
      return total_loss / len(loader)
  
imports: import torch
  import torch.nn
  from dgl.sampling import node2vec_random_walk
  from sklearn.linear_model import LogisticRegression
  from torch.utils.data import DataLoader
label_desc: Use image node_id 2 for calling the Node2vecModel obj's underlying member method code with example usage: obj._train_step(model, loader, optimizer, device) and returns: unknown