code: def test_language_weighted_random_sampler(
      self,
  ):  # pylint: disable=no-self-use
      weighted_sampler = torch.utils.data.sampler.WeightedRandomSampler(
          get_language_balancer_weights(train_samples),
          len(train_samples),
      )
      ids = functools.reduce(
          lambda a, b: a + b,
          [list(weighted_sampler) for i in range(100)],
      )
      en, pt = 0, 0
      for index in ids:
          if train_samples[index]["language"] == "en":
              en += 1
          else:
              pt += 1
  
      assert is_balanced(
          en, pt
      ), "Language Weighted sampler is supposed to be balanced"
  
file_path: TTS/tests/data_tests/test_samplers.py
imports: import functools
  import random
  import unittest
  import torch
  from TTS.config.shared_configs import BaseDatasetConfig
  from TTS.tts.datasets import load_tts_samples
  from TTS.tts.utils.data import get_length_balancer_weights
  from TTS.tts.utils.languages import get_language_balancer_weights
  from TTS.tts.utils.speakers import get_speaker_balancer_weights
  from TTS.utils.samplers import BucketBatchSampler, PerfectBatchSampler
label_desc: Use image node_id 2 for calling the TestSamplers obj's underlying member method code with example usage: obj.test_language_weighted_random_sampler() without return types