def label2tag(label_sequence, tag_vocab):
    """
    convert label sequence to tag sequence
    :param label_sequence: label sequence
    :param tag_vocab: tag vocabulary, i.e., mapping between tag and label
    :return:
    """
    inv_tag_vocab = {}
    for tag in tag_vocab:
        label = tag_vocab[tag]
        inv_tag_vocab[label] = tag
    tag_sequences = []
    n_tag = len(tag_vocab)
    for seq in label_sequence:
        tag_seq = []
        for l in seq:
            if l in inv_tag_vocab:
                tag_seq.append(inv_tag_vocab[l])
            elif l == n_tag or l == n_tag + 1:
                tag_seq.append("O")
            else:
                raise Exception("Invalid label %s" % l)
        tag_sequences.append(tag_seq)

    return tag_sequences