class_docstr: Few-shot learning is an important scenario for prompt-learning, this is a sampler that samples few examples over each class.
  
  Args:
      num_examples_total(:obj:`int`, optional): Sampling strategy ``I``: Use total number of examples for few-shot sampling.
      num_examples_per_label(:obj:`int`, optional): Sampling strategy ``II``: Use the number of examples for each label for few-shot sampling.
      also_sample_dev(:obj:`bool`, optional): Whether to apply the sampler to the dev data.
      num_examples_total_dev(:obj:`int`, optional): Sampling strategy ``I``: Use total number of examples for few-shot sampling.
      num_examples_per_label_dev(:obj:`int`, optional): Sampling strategy ``II``: Use the number of examples for each label for few-shot sampling.
class_docstr_tok: ["Few-shot","learning","is","an","important","scenario","for","prompt-learning",",","this","is","a","sampler","that","samples","few","examples","over","each","class",".","Args",":","num_examples_total","(",":","obj",":","`","int","`",",","optional",")",":","Sampling","strategy","``","I","``",":","Use","total","number","of","examples","for","few-shot","sampling",".","num_examples_per_label","(",":","obj",":","`","int","`",",","optional",")",":","Sampling","strategy","``","II","``",":","Use","the","number","of","examples","for","each","label","for","few-shot","sampling",".","also_sample_dev","(",":","obj",":","`","bool","`",",","optional",")",":","Whether","to","apply","the","sampler","to","the","dev","data",".","num_examples_total_dev","(",":","obj",":","`","int","`",",","optional",")",":","Sampling","strategy","``","I","``",":","Use","total","number","of","examples","for","few-shot","sampling",".","num_examples_per_label_dev","(",":","obj",":","`","int","`",",","optional",")",":","Sampling","strategy","``","II","``",":","Use","the","number","of","examples","for","each","label","for","few-shot","sampling","."]
code: def _sample(
      self,
      data: Union[Dataset, List],
      seed: Optional[int],
      sample_twice=False,
      is_dev=False,
  ) -> Union[Dataset, List]:
      if seed is not None:
          self.rng = np.random.RandomState(seed)
      else:
          self.rng = np.random.RandomState()
      indices = [i for i in range(len(data))]
  
      num_examples_per_label = (
          self.num_examples_per_label_dev
          if is_dev
          else self.num_examples_per_label
      )
      num_examples_total = (
          self.num_examples_total_dev
          if is_dev
          else self.num_examples_total
      )
  
      if num_examples_per_label is not None:
          assert hasattr(
              data[0], "label"
          ), "sample by label requires the data has a 'label' attribute."
          labels = [x.label for x in data]
          selected_ids = self.sample_per_label(
              indices, labels, num_examples_per_label
          )
      else:
          selected_ids = self.sample_total(indices, num_examples_total)
  
      if sample_twice:
          selected_set = set(selected_ids)
          remain_ids = [
              i for i in range(len(data)) if i not in selected_set
          ]
          if self.num_examples_per_label_dev is not None:
              assert hasattr(
                  data[0], "label"
              ), "sample by label requires the data has a 'label' attribute."
              remain_labels = [
                  x.label
                  for idx, x in enumerate(data)
                  if idx not in selected_set
              ]
              selected_ids_dev = self.sample_per_label(
                  remain_ids,
                  remain_labels,
                  self.num_examples_per_label_dev,
              )
          else:
              selected_ids_dev = self.sample_total(
                  remain_ids, self.num_examples_total_dev
              )
  
          if isinstance(data, Dataset):
              return Subset(data, selected_ids), Subset(
                  data, selected_ids_dev
              )
          elif isinstance(data, List):
              return [data[i] for i in selected_ids], [
                  data[i] for i in selected_ids_dev
              ]
  
      else:
          if isinstance(data, Dataset):
              return Subset(data, selected_ids)
          elif isinstance(data, List):
              return [data[i] for i in selected_ids]
  
file_path: OpenPrompt/openprompt/data_utils/data_sampler.py
imports: from collections import defaultdict, namedtuple
  from typing import *
  import numpy
  from torch.utils.data import Dataset
  from torch.utils.data.dataset import Subset
  from openprompt.utils.logging import logger
  from typing import Union
label_desc: Use image node_id 3 for calling the FewShotSampler obj's underlying member method code with example usage: obj._sample(data, seed, sample_twice, is_dev) and returns: Subset,  Subset, Subset, unknown,  unknown, unknown