from typing import OrderedDict
import random


def _downsample_dict(full_dict, num_samples):
    """Returns a down-sampled dictionary with a given number of samples in
    each value list.

    Args:
        full_dict: A dictionary with lists as values to down-sample.
        num_samples: The number of elements in each value list from full_dict
        to keep.

    Returns:
        A dictionary with value lengths of num_samples.
    """
    downsampled_dict = OrderedDict()
    for key, value in full_dict.items():
        if len(value) > num_samples:
            downsampled_dict[key] = random.sample(value, k=num_samples)
        else:
            downsampled_dict[key] = value

    return downsampled_dict