def collate_dictionaries(dicts):
    """
    Collate a list of dictionaries into a single dictionary.
    """
    if len(dicts) == 0:
        return

    res = {}
    for key in dicts[0].keys():
        els = [d[key] for d in dicts]
        if isinstance(els[0], torch.Tensor):
            res[key] = torch.stack(els)
        elif isinstance(els[0], int):
            res[key] = torch.tensor(els)
        else:
            res[key] = els
    return res

    Collate a list of dictionaries into a single dictionary.
    
tests/training/test_dictionary_mbatches.py