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
  batch_size int : number of node sequences in each batch
  only_cpu bool : training with CPU
  only_gpu bool : training with GPU
  only_fst bool : only embedding for first-order proximity
  only_snd bool : only embedding for second-order proximity
  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
  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","batch_size","int",":","number","of","node","sequences","in","each","batch","only_cpu","bool",":","training","with","CPU","only_gpu","bool",":","training","with","GPU","only_fst","bool",":","only","embedding","for","first-order","proximity","only_snd","bool",":","only","embedding","for","second-order","proximity","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","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,
      batch_size,
      only_cpu,
      only_gpu,
      only_fst,
      only_snd,
      mix,
      neg_weight,
      negative,
      lr,
      lap_norm,
      fast_neg,
      record_loss,
      async_update,
      num_threads,
  ):
      """initialize embedding on CPU
  
      Paremeters
      ----------
      emb_size int : number of nodes
      emb_dimension int : embedding dimension
      batch_size int : number of node sequences in each batch
      only_cpu bool : training with CPU
      only_gpu bool : training with GPU
      only_fst bool : only embedding for first-order proximity
      only_snd bool : only embedding for second-order proximity
      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
      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.batch_size = batch_size
      self.only_cpu = only_cpu
      self.only_gpu = only_gpu
      if only_fst:
          self.fst = True
          self.snd = False
          self.emb_dimension = emb_dimension
      elif only_snd:
          self.fst = False
          self.snd = True
          self.emb_dimension = emb_dimension
      else:
          self.fst = True
          self.snd = True
          self.emb_dimension = int(emb_dimension / 2)
      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.async_update = async_update
      self.num_threads = num_threads
  
      # initialize the device as cpu
      self.device = torch.device("cpu")
  
      # embedding
      initrange = 1.0 / self.emb_dimension
      if self.fst:
          self.fst_u_embeddings = nn.Embedding(
              self.emb_size, self.emb_dimension, sparse=True
          )
          init.uniform_(
              self.fst_u_embeddings.weight.data, -initrange, initrange
          )
      if self.snd:
          self.snd_u_embeddings = nn.Embedding(
              self.emb_size, self.emb_dimension, sparse=True
          )
          init.uniform_(
              self.snd_u_embeddings.weight.data, -initrange, initrange
          )
          self.snd_v_embeddings = nn.Embedding(
              self.emb_size, self.emb_dimension, sparse=True
          )
          init.constant_(self.snd_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_fst = []
          self.loss_snd = []
  
      # indexes to select positive/negative node pairs from batch_walks
      self.index_emb_negu, self.index_emb_negv = init_emb2neg_index(
          self.negative, self.batch_size
      )
  
      # adam
      if self.fst:
          self.fst_state_sum_u = torch.zeros(self.emb_size)
      if self.snd:
          self.snd_state_sum_u = torch.zeros(self.emb_size)
          self.snd_state_sum_v = torch.zeros(self.emb_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, batch_size, only_cpu, only_gpu, only_fst, only_snd, mix, neg_weight, negative, lr, lap_norm, fast_neg, record_loss, async_update, num_threads)