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 __init__(
      self,
      num_examples_total: Optional[int] = None,
      num_examples_per_label: Optional[int] = None,
      also_sample_dev: Optional[bool] = False,
      num_examples_total_dev: Optional[int] = None,
      num_examples_per_label_dev: Optional[int] = None,
  ):
      if num_examples_total is None and num_examples_per_label is None:
          raise ValueError(
              "num_examples_total and num_examples_per_label can't be both None."
          )
      elif (
          num_examples_total is not None
          and num_examples_per_label is not None
      ):
          raise ValueError(
              "num_examples_total and num_examples_per_label can't be both set."
          )
  
      if also_sample_dev:
          if (
              num_examples_total_dev is not None
              and num_examples_per_label_dev is not None
          ):
              raise ValueError(
                  "num_examples_total and num_examples_per_label can't be both set."
              )
          elif (
              num_examples_total_dev is None
              and num_examples_per_label_dev is None
          ):
              logger.warning(
                  r"specify neither num_examples_total_dev nor num_examples_per_label_dev,\
                                  set to default (equal to train set setting)."
              )
              self.num_examples_total_dev = num_examples_total
              self.num_examples_per_label_dev = num_examples_per_label
          else:
              self.num_examples_total_dev = num_examples_total_dev
              self.num_examples_per_label_dev = (
                  num_examples_per_label_dev
              )
  
      self.num_examples_total = num_examples_total
      self.num_examples_per_label = num_examples_per_label
      self.also_sample_dev = also_sample_dev
  
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 1 to create a new FewShotSampler object from inherited base classes: object with example: obj = FewShotSampler(num_examples_total, num_examples_per_label, also_sample_dev, num_examples_total_dev, num_examples_per_label_dev)