def get_labels(likely_cat, threshold="max"):
    """
    Input:
        - likely_cat: the confidence scores for every category for every test doc as a dict (scores normalized to 1)
        - threshold: threshold for the likeliness score: selects as many categories as have a score equal to or above the
                   threshold (between 0 and 1). If threshold is set to 'max', only the category with the highest score
                   is chosen (unless all categories have a score of 0)
    Returns:
        - labels: dict with doc:[cats] for each test doc where the list contains as many categories as have scores above threshold
                 --> the categories are chosen as the highest scoring categories in likely_cat
    Note:
        if threshold='max' and all categories have score of 0, a random category is chosen,
        otherwise if threshold is a float and no category has a score above threshold, the list will be empty
    """
    labels = {}
    for tid in likely_cat:
        # either take the most likely category
        if threshold == "max":
            labels[tid] = [max(likely_cat[tid].keys(), key=likely_cat[tid].get)]
        # or all categories with a score above threshold
        else:
            labels[tid] = [cat for cat in likely_cat[tid] if likely_cat[tid][cat] >= threshold]
    return labels