code: def build_train_valid_datasets(
      model_cfg,
      consumed_samples,
      tokenizer=None,
  ):
      data_cfg = model_cfg.data
  
      # This function maps data that are tuples to dictionary.
      def tuple_to_dict(inp):
          for input in inp:
              out_dict = dict()
              out_dict["images"] = input[0]
              out_dict["captions"] = input[1]
              yield out_dict
  
      def transform_fn(sample, img_transform, text_transform):
          image, text = sample["jpg"], sample["txt"]
          return img_transform(image), text_transform(text)
  
      train_img_transform, text_transform = get_preprocess_fns(
          model_cfg, tokenizer, is_train=True
      )
      train_data = WebDatasetCommon(
          dataset_cfg=data_cfg,
          consumed_samples=consumed_samples,
          map_fn=partial(
              transform_fn,
              img_transform=train_img_transform,
              text_transform=text_transform,
          ),
          compose_fn=tuple_to_dict,
          is_train=True,
      )
  
      val_data = None
      if data_cfg.get(
          "validation"
      ) is not None and data_cfg.validation.get("dataset_path"):
          val_img_transform, text_transform = get_preprocess_fns(
              model_cfg, tokenizer, is_train=False
          )
          val_data = WebDatasetCommon(
              dataset_cfg=data_cfg,
              consumed_samples=0,
              map_fn=partial(
                  transform_fn,
                  img_transform=val_img_transform,
                  text_transform=text_transform,
              ),
              compose_fn=tuple_to_dict,
              is_train=False,
          )
  
      return train_data, val_data
  
file_path: NeMo/nemo/collections/multimodal/data/clip/clip_dataset.py
imports: from functools import partial
  from typing import Any, List, Union
  import torch
  from torch.utils.data import Dataset, default_collate
  from nemo.collections.multimodal.data.clip.augmentations.augmentations import image_transform
  from nemo.collections.multimodal.data.clip.imagenet_zeroshot_data import imagenet_classnames, openai_imagenet_template
  from nemo.collections.multimodal.data.common.webdataset import WebDatasetCommon
  from nemo.collections.nlp.data.language_modeling.megatron.data_samplers import MegatronPretrainingSampler
  from nemo.collections.vision.data.megatron.image_folder import ImageFolder
label_desc: Use image node_id 3 for calling a global function with example usage: build_train_valid_datasets(model_cfg, consumed_samples, tokenizer) and returns: train_data,  val_data, img_transform,  text_transform