class_docstr: :class:`Sampler` is used to sample negative items for each input user. In order to avoid positive items
  in train-phase to be sampled in valid-phase, and positive items in train-phase or valid-phase to be sampled
  in test-phase, we need to input the datasets of all phases for pre-processing. And, before using this sampler,
  it is needed to call :meth:`set_phase` to get the sampler of corresponding phase.
  
  Args:
      phases (str or list of str): All the phases of input.
      datasets (Dataset or list of Dataset): All the dataset for each phase.
      distribution (str, optional): Distribution of the negative items. Defaults to 'uniform'.
  
  Attributes:
      phase (str): the phase of sampler. It will not be set until :meth:`set_phase` is called.
class_docstr_tok: [":","class",":","`","Sampler","`","is","used","to","sample","negative","items","for","each","input","user",".","In","order","to","avoid","positive","items","in","train-phase","to","be","sampled","in","valid-phase",",","and","positive","items","in","train-phase","or","valid-phase","to","be","sampled","in","test-phase",",","we","need","to","input","the","datasets","of","all","phases","for","pre-processing",".","And",",","before","using","this","sampler",",","it","is","needed","to","call",":","meth",":","`","set_phase","`","to","get","the","sampler","of","corresponding","phase",".","Args",":","phases","(","str","or","list","of","str",")",":","All","the","phases","of","input",".","datasets","(","Dataset","or","list","of","Dataset",")",":","All","the","dataset","for","each","phase",".","distribution","(","str",",","optional",")",":","Distribution","of","the","negative","items",".","Defaults","to","'uniform","'",".","Attributes",":","phase","(","str",")",":","the","phase","of","sampler",".","It","will","not","be","set","until",":","meth",":","`","set_phase","`","is","called","."]
docstr: Get the sampler of corresponding phase.
  
  Args:
      phase (str): The phase of new sampler.
  
  Returns:
      Sampler: the copy of this sampler, :attr:`phase` is set the same as input phase, and :attr:`used_ids`
      is set to the value of corresponding phase.
docstr_tok: ["Get","the","sampler","of","corresponding","phase",".","Args",":","phase","(","str",")",":","The","phase","of","new","sampler",".","Returns",":","Sampler",":","the","copy","of","this","sampler",",",":","attr",":","`","phase","`","is","set","the","same","as","input","phase",",","and",":","attr",":","`","used_ids","`","is","set","to","the","value","of","corresponding","phase","."]
code: def set_phase(self, phase):
      """Get the sampler of corresponding phase.
  
      Args:
          phase (str): The phase of new sampler.
  
      Returns:
          Sampler: the copy of this sampler, :attr:`phase` is set the same as input phase, and :attr:`used_ids`
          is set to the value of corresponding phase.
      """
      if phase not in self.phases:
          raise ValueError(f"Phase [{phase}] not exist.")
      new_sampler = copy.copy(self)
      new_sampler.phase = phase
      new_sampler.used_ids = new_sampler.used_ids[phase]
      return new_sampler
  
imports: import copy
  import numpy
  from numpy.random import sample
  import torch
  from collections import Counter
label_desc: Use image node_id 5 for calling the Sampler obj's underlying member method code with example usage: obj.set_phase(phase) and returns: new_sampler