def collect_phrases(ranks, labels, num_phrases=5):
    """Collect phrases from a ranked lemma graph.

    Args:
        ranks (dict): map graph nodes to their ranking.
        lables (dict): map graph nodes to their corresponding lemma.
        num_phrases (int): num of phrases to return.

    Returns:
        list
    """
    phrase_list = []
    phrase_num = 0
    for node_id, rank in sorted(ranks.items(), key=lambda x: x[1], reverse=True):
        lemma = labels.get(node_id)
        if not lemma:
            continue
        phrase_list.append((lemma, rank))
        phrase_num += 1
        if phrase_num == num_phrases:
            break
    return phrase_list