code: def train(self):
      optimizer = optim.SparseAdam(
          list(self.skip_gram_model.parameters()), lr=self.initial_lr
      )
      scheduler = torch.optim.lr_scheduler.CosineAnnealingLR(
          optimizer, len(self.dataloader)
      )
  
      for iteration in range(self.iterations):
          print("\n\n\nIteration: " + str(iteration + 1))
          running_loss = 0.0
          for i, sample_batched in enumerate(tqdm(self.dataloader)):
              if len(sample_batched[0]) > 1:
                  pos_u = sample_batched[0].to(self.device)
                  pos_v = sample_batched[1].to(self.device)
                  neg_v = sample_batched[2].to(self.device)
  
                  scheduler.step()
                  optimizer.zero_grad()
                  loss = self.skip_gram_model.forward(
                      pos_u, pos_v, neg_v
                  )
                  loss.backward()
                  optimizer.step()
  
                  running_loss = running_loss * 0.9 + loss.item() * 0.1
                  if i > 0 and i % 500 == 0:
                      print(" Loss: " + str(running_loss))
  
      self.skip_gram_model.save_embedding(
          self.data.id2word, self.output_file_name
      )
  
file_path: dgl/examples/pytorch/metapath2vec/metapath2vec.py
imports: import argparse
  import torch
  import torch.optim
  from download import AminerDataset, CustomDataset
  from model import SkipGramModel
  from reading_data import DataReader, Metapath2vecDataset
  from torch.utils.data import DataLoader
  from tqdm import tqdm
label_desc: Use image node_id 2 for calling the Metapath2VecTrainer obj's underlying member method code with example usage: obj.train() without return types