class_docstr: Negative sampling based skip-gram
class_docstr_tok: ["Negative","sampling","based","skip-gram"]
docstr: initialize embedding on CPU
  
  Paremeters
  ----------
  emb_size int : number of nodes
  emb_dimension int : embedding dimension
  walk_length int : number of nodes in a sequence
  window_size int : context window size
  batch_size int : number of node sequences in each batch
  only_cpu bool : training with CPU
  only_gpu bool : training with GPU
  mix bool : mixed training with CPU and GPU
  negative int : negative samples for each positve node pair
  neg_weight float : negative weight
  lr float : initial learning rate
  lap_norm float : weight of laplacian normalization
  fast_neg bool : do negative sampling inside a batch
  record_loss bool : print the loss during training
  norm bool : do normalizatin on the embedding after training
  use_context_weight : give different weights to the nodes in a context window
  async_update : asynchronous training
docstr_tok: ["initialize","embedding","on","CPU","Paremeters","--","--","--","--","--","emb_size","int",":","number","of","nodes","emb_dimension","int",":","embedding","dimension","walk_length","int",":","number","of","nodes","in","a","sequence","window_size","int",":","context","window","size","batch_size","int",":","number","of","node","sequences","in","each","batch","only_cpu","bool",":","training","with","CPU","only_gpu","bool",":","training","with","GPU","mix","bool",":","mixed","training","with","CPU","and","GPU","negative","int",":","negative","samples","for","each","positve","node","pair","neg_weight","float",":","negative","weight","lr","float",":","initial","learning","rate","lap_norm","float",":","weight","of","laplacian","normalization","fast_neg","bool",":","do","negative","sampling","inside","a","batch","record_loss","bool",":","print","the","loss","during","training","norm","bool",":","do","normalizatin","on","the","embedding","after","training","use_context_weight",":","give","different","weights","to","the","nodes","in","a","context","window","async_update",":","asynchronous","training"]
code: def __init__(
      self,
      emb_size,
      emb_dimension,
      walk_length,
      window_size,
      batch_size,
      only_cpu,
      only_gpu,
      mix,
      neg_weight,
      negative,
      lr,
      lap_norm,
      fast_neg,
      record_loss,
      norm,
      use_context_weight,
      async_update,
      num_threads,
  ):
      """initialize embedding on CPU
  
      Paremeters
      ----------
      emb_size int : number of nodes
      emb_dimension int : embedding dimension
      walk_length int : number of nodes in a sequence
      window_size int : context window size
      batch_size int : number of node sequences in each batch
      only_cpu bool : training with CPU
      only_gpu bool : training with GPU
      mix bool : mixed training with CPU and GPU
      negative int : negative samples for each positve node pair
      neg_weight float : negative weight
      lr float : initial learning rate
      lap_norm float : weight of laplacian normalization
      fast_neg bool : do negative sampling inside a batch
      record_loss bool : print the loss during training
      norm bool : do normalizatin on the embedding after training
      use_context_weight : give different weights to the nodes in a context window
      async_update : asynchronous training
      """
      super(SkipGramModel, self).__init__()
      self.emb_size = emb_size
      self.emb_dimension = emb_dimension
      self.walk_length = walk_length
      self.window_size = window_size
      self.batch_size = batch_size
      self.only_cpu = only_cpu
      self.only_gpu = only_gpu
      self.mixed_train = mix
      self.neg_weight = neg_weight
      self.negative = negative
      self.lr = lr
      self.lap_norm = lap_norm
      self.fast_neg = fast_neg
      self.record_loss = record_loss
      self.norm = norm
      self.use_context_weight = use_context_weight
      self.async_update = async_update
      self.num_threads = num_threads
  
      # initialize the device as cpu
      self.device = torch.device("cpu")
  
      # content embedding
      self.u_embeddings = nn.Embedding(
          self.emb_size, self.emb_dimension, sparse=True
      )
      # context embedding
      self.v_embeddings = nn.Embedding(
          self.emb_size, self.emb_dimension, sparse=True
      )
      # initialze embedding
      initrange = 1.0 / self.emb_dimension
      init.uniform_(
          self.u_embeddings.weight.data, -initrange, initrange
      )
      init.constant_(self.v_embeddings.weight.data, 0)
  
      # lookup_table is used for fast sigmoid computing
      self.lookup_table = torch.sigmoid(torch.arange(-6.01, 6.01, 0.01))
      self.lookup_table[0] = 0.0
      self.lookup_table[-1] = 1.0
      if self.record_loss:
          self.logsigmoid_table = torch.log(
              torch.sigmoid(torch.arange(-6.01, 6.01, 0.01))
          )
          self.loss = []
  
      # indexes to select positive/negative node pairs from batch_walks
      self.index_emb_posu, self.index_emb_posv = init_emb2pos_index(
          self.walk_length, self.window_size, self.batch_size
      )
      self.index_emb_negu, self.index_emb_negv = init_emb2neg_index(
          self.walk_length,
          self.window_size,
          self.negative,
          self.batch_size,
      )
  
      if self.use_context_weight:
          self.context_weight = init_weight(
              self.walk_length, self.window_size, self.batch_size
          )
  
      # adam
      self.state_sum_u = torch.zeros(self.emb_size)
      self.state_sum_v = torch.zeros(self.emb_size)
  
      # gradients of nodes in batch_walks
      self.grad_u, self.grad_v = init_empty_grad(
          self.emb_dimension, self.walk_length, self.batch_size
      )
  
imports: import random
  import numpy
  import torch
  import torch.multiprocessing
  import torch.nn
  import torch.nn.functional
  from torch.multiprocessing import Queue
  from torch.nn import init
label_desc: Use image node_id 1 to create a new SkipGramModel object from inherited base classes: nn with example: obj = SkipGramModel(emb_size, emb_dimension, walk_length, window_size, batch_size, only_cpu, only_gpu, mix, neg_weight, negative, lr, lap_norm, fast_neg, record_loss, norm, use_context_weight, async_update, num_threads)