class_docstr: Base class for creating contrastive learning models for either graph-level or 
  node-level tasks.
  
  *Alias*: :obj:`dig.sslgraph.method.contrastive.model.`:obj:`Contrastive`.
  
  Args:
      objective (string, or callable): The learning objective of contrastive model.
          If string, should be one of 'NCE' and 'JSE'. If callable, should take lists
          of representations as inputs and returns loss Tensor 
          (see `dig.sslgraph.method.contrastive.objectives` for examples).
      views_fn (list of callable): List of functions to generate views from given graphs.
      graph_level (bool, optional): Whether to include graph-level representation 
          for contrast. (default: :obj:`True`)
      node_level (bool, optional): Whether to include node-level representation 
          for contrast. (default: :obj:`False`)
      z_dim (int, optional): The dimension of graph-level representations. 
          Required if :obj:`graph_level` = :obj:`True`. (default: :obj:`None`)
      z_dim (int, optional): The dimension of node-level representations. 
          Required if :obj:`node_level` = :obj:`True`. (default: :obj:`None`)
      proj (string, or Module, optional): Projection head for graph-level representation. 
          If string, should be one of :obj:`"linear"` or :obj:`"MLP"`. Required if
          :obj:`graph_level` = :obj:`True`. (default: :obj:`None`)
      proj_n (string, or Module, optional): Projection head for node-level representations. 
          If string, should be one of :obj:`"linear"` or :obj:`"MLP"`. Required if
          :obj:`node_level` = :obj:`True`. (default: :obj:`None`)
      neg_by_crpt (bool, optional): The mode to obtain negative samples in JSE. If True, 
          obtain negative samples by performing corruption. Otherwise, consider pairs of
          different graph samples as negative pairs. Only used when 
          :obj:`objective` = :obj:`"JSE"`. (default: :obj:`False`)
      tau (int): The tempurature parameter in InfoNCE (NT-XENT) loss. Only used when 
          :obj:`objective` = :obj:`"NCE"`. (default: :obj:`0.5`)
      device (int, or `torch.device`, optional): The device to perform computation.
      choice_model (string, optional): Whether to yield model with :obj:`best` training loss or
          at the :obj:`last` epoch. (default: :obj:`last`)
      model_path (string, optinal): The directory to restore the saved model. 
          (default: :obj:`models`)
class_docstr_tok: ["Base","class","for","creating","contrastive","learning","models","for","either","graph-level","or","node-level","tasks",".","*","Alias","*",":",":","obj",":","`","dig.sslgraph.method.contrastive.model.","`",":","obj",":","`","Contrastive","`",".","Args",":","objective","(","string",",","or","callable",")",":","The","learning","objective","of","contrastive","model",".","If","string",",","should","be","one","of","'NCE","'","and","'JSE","'",".","If","callable",",","should","take","lists","of","representations","as","inputs","and","returns","loss","Tensor","(","see","`","dig.sslgraph.method.contrastive.objectives","`","for","examples",")",".","views_fn","(","list","of","callable",")",":","List","of","functions","to","generate","views","from","given","graphs",".","graph_level","(","bool",",","optional",")",":","Whether","to","include","graph-level","representation","for","contrast",".","(","default",":",":","obj",":","`","True","`",")","node_level","(","bool",",","optional",")",":","Whether","to","include","node-level","representation","for","contrast",".","(","default",":",":","obj",":","`","False","`",")","z_dim","(","int",",","optional",")",":","The","dimension","of","graph-level","representations",".","Required","if",":","obj",":","`","graph_level","`","=",":","obj",":","`","True","`",".","(","default",":",":","obj",":","`","None","`",")","z_dim","(","int",",","optional",")",":","The","dimension","of","node-level","representations",".","Required","if",":","obj",":","`","node_level","`","=",":","obj",":","`","True","`",".","(","default",":",":","obj",":","`","None","`",")","proj","(","string",",","or","Module",",","optional",")",":","Projection","head","for","graph-level","representation",".","If","string",",","should","be","one","of",":","obj",":","`","``","linear","''","`","or",":","obj",":","`","``","MLP","''","`",".","Required","if",":","obj",":","`","graph_level","`","=",":","obj",":","`","True","`",".","(","default",":",":","obj",":","`","None","`",")","proj_n","(","string",",","or","Module",",","optional",")",":","Projection","head","for","node-level","representations",".","If","string",",","should","be","one","of",":","obj",":","`","``","linear","''","`","or",":","obj",":","`","``","MLP","''","`",".","Required","if",":","obj",":","`","node_level","`","=",":","obj",":","`","True","`",".","(","default",":",":","obj",":","`","None","`",")","neg_by_crpt","(","bool",",","optional",")",":","The","mode","to","obtain","negative","samples","in","JSE",".","If","True",",","obtain","negative","samples","by","performing","corruption",".","Otherwise",",","consider","pairs","of","different","graph","samples","as","negative","pairs",".","Only","used","when",":","obj",":","`","objective","`","=",":","obj",":","`","``","JSE","''","`",".","(","default",":",":","obj",":","`","False","`",")","tau","(","int",")",":","The","tempurature","parameter","in","InfoNCE","(","NT-XENT",")","loss",".","Only","used","when",":","obj",":","`","objective","`","=",":","obj",":","`","``","NCE","''","`",".","(","default",":",":","obj",":","`","0.5","`",")","device","(","int",",","or","`","torch.device","`",",","optional",")",":","The","device","to","perform","computation",".","choice_model","(","string",",","optional",")",":","Whether","to","yield","model","with",":","obj",":","`","best","`","training","loss","or","at","the",":","obj",":","`","last","`","epoch",".","(","default",":",":","obj",":","`","last","`",")","model_path","(","string",",","optinal",")",":","The","directory","to","restore","the","saved","model",".","(","default",":",":","obj",":","`","models","`",")"]
code: def _corrupt_graph(self, view):
      data_list = view.to_data_list()
      crpt_list = []
      for data in data_list:
          n_nodes = data.x.shape[0]
          perm = torch.randperm(n_nodes).long()
          crpt_x = data.x[perm]
          crpt_list.append(Data(x=crpt_x, edge_index=data.edge_index))
      view_crpt = Batch.from_data_list(crpt_list)
  
      return view_crpt
  
file_path: DIG/dig/sslgraph/method/contrastive/model/contrastive.py
imports: import os
  import torch
  from tqdm import trange
  import torch.nn
  from torch_geometric.data import Batch, Data
  from dig.sslgraph.method.contrastive.objectives import NCE_loss, JSE_loss
label_desc: Use image node_id 7 for calling the Contrastive obj's underlying member method code with example usage: obj._corrupt_graph(view) and returns: view_crpt