class_docstr: A data sampler that takes a single key from the dataset and
  ensures an approximately equal distribution by that key
  
  Arguments
  ---------
  dataset: DynamicItemDataset
      the dataset form which samples will be drawn
  key: str
      the key from which samples will be taken
  num_samples : int
      Number of samples to draw
  replacement : bool
      To draw with replacement or not (within an epoch of num_samples).
  seed : int
      The base seed to use for the random number generator. It is recommended
      to use a value which has a good mix of 0 and 1 bits.
  epoch : int
      The epoch to start at.
  
  Example
  -------
  >>> from speechbrain.dataio.sampler import BalancingDataSampler
  >>> from speechbrain.dataio.dataset import DynamicItemDataset
  >>> sample_data = {
  ...   1: {"category": "A",
  ...       "text": "This is a test"},
  ...   2: {"category": "A",
  ...       "text": "This is a second test"},
  ...   3: {"category": "B",
  ...       "text": "This is a third test"}
  ...  }
  >>> dataset = DynamicItemDataset(data=sample_data)
  >>> sampler = BalancingDataSampler(
  ...     dataset=dataset,
  ...     key="category",
  ...     num_samples=10
  ... )
  >>> sampler.weights
  tensor([0.5000, 0.5000, 1.0000], dtype=torch.float64)
  >>> it = iter(sampler)
  >>> [next(it) for _ in range(10)]
  [2, 2, 1, 2, 2, 0, 1, 1, 1, 2]
class_docstr_tok: ["A","data","sampler","that","takes","a","single","key","from","the","dataset","and","ensures","an","approximately","equal","distribution","by","that","key","Arguments","--","--","--","--","-","dataset",":","DynamicItemDataset","the","dataset","form","which","samples","will","be","drawn","key",":","str","the","key","from","which","samples","will","be","taken","num_samples",":","int","Number","of","samples","to","draw","replacement",":","bool","To","draw","with","replacement","or","not","(","within","an","epoch","of","num_samples",")",".","seed",":","int","The","base","seed","to","use","for","the","random","number","generator",".","It","is","recommended","to","use","a","value","which","has","a","good","mix","of","0","and","1","bits",".","epoch",":","int","The","epoch","to","start","at",".","Example","--","--","--","-",">",">",">","from","speechbrain.dataio.sampler","import","BalancingDataSampler",">",">",">","from","speechbrain.dataio.dataset","import","DynamicItemDataset",">",">",">","sample_data","=","{","...","1",":","{","``","category","''",":","``","A","''",",","...","``","text","''",":","``","This","is","a","test","''","}",",","...","2",":","{","``","category","''",":","``","A","''",",","...","``","text","''",":","``","This","is","a","second","test","''","}",",","...","3",":","{","``","category","''",":","``","B","''",",","...","``","text","''",":","``","This","is","a","third","test","''","}","...","}",">",">",">","dataset","=","DynamicItemDataset","(","data=sample_data",")",">",">",">","sampler","=","BalancingDataSampler","(","...","dataset=dataset",",","...","key=","''","category","''",",","...","num_samples=10","...",")",">",">",">","sampler.weights","tensor","(","[","0.5000",",","0.5000",",","1.0000","]",",","dtype=torch.float64",")",">",">",">","it","=","iter","(","sampler",")",">",">",">","[","next","(","it",")","for","_","in","range","(","10",")","]","[","2",",","2",",","1",",","2",",","2",",","0",",","1",",","1",",","1",",","2","]"]
code: def __init__(
      self,
      dataset,
      key,
      num_samples=None,
      replacement=True,
      seed=563375142,
      epoch=0,
      **kwargs,
  ):
      self.dataset = dataset
      self.key = key
      if not num_samples:
          num_samples = len(dataset)
      weights = self._compute_weights()
      super().__init__(
          weights, num_samples, replacement, seed, epoch, **kwargs
      )
  
imports: import torch
  import logging
  from operator import itemgetter
  from torch.utils.data import RandomSampler, WeightedRandomSampler, DistributedSampler, Sampler
  import numpy
  from typing import List
  from speechbrain.dataio.dataset import DynamicItemDataset
  from collections import Counter
  from scipy.stats import lognorm
label_desc: Use image node_id 1 to create a new BalancingDataSampler object from inherited base classes: ReproducibleWeightedRandomSampler with example: obj = BalancingDataSampler(dataset, key, num_samples, replacement, seed, epoch)