def build_category_index(data):
    """
    Returns mappings from index to category and vice versa.

    Args:
        data: list of dicts, each dict is one sample
    """
    categories = set()
    for sample in data:
        categories.add(sample['category'])
    categories = sorted(list(categories))
    idx2cat = {i: cat for i, cat in enumerate(categories)}
    cat2idx = {cat: i for i, cat in idx2cat.items()}

    return idx2cat, cat2idx