code: def __init__(
      self,
      vocab: str,
      num_samples: int,
      cache_samples: bool = False,
      font_family: Optional[Union[str, List[str]]] = None,
      img_transforms: Optional[Callable[[Any], Any]] = None,
      sample_transforms: Optional[
          Callable[[Any, Any], Tuple[Any, Any]]
      ] = None,
  ) -> None:
      self.vocab = vocab
      self._num_samples = num_samples
      self.font_family = font_family if isinstance(font_family, list) else [font_family]  # type: ignore[list-item]
      # Validate fonts
      if isinstance(font_family, list):
          for font in self.font_family:
              try:
                  _ = get_font(font, 10)
              except OSError:
                  raise ValueError(f"unable to locate font: {font}")
      self.img_transforms = img_transforms
      self.sample_transforms = sample_transforms
  
      self._data: List[Image.Image] = []
      if cache_samples:
          self._data = [
              (synthesize_text_img(char, font_family=font), idx)
              for idx, char in enumerate(self.vocab)
              for font in self.font_family
          ]
  
file_path: doctr/doctr/datasets/generator/base.py
imports: import random
  from typing import Any, Callable, List, Optional, Tuple, Union
  from PIL import Image, ImageDraw
  from doctr.io.image import tensor_from_pil
  from doctr.utils.fonts import get_font
  from ..datasets import AbstractDataset
label_desc: Use image node_id 1 to create a new _CharacterGenerator object from inherited base classes: AbstractDataset with example: obj = _CharacterGenerator(vocab, num_samples, cache_samples, font_family, img_transforms, sample_transforms)