def parse_ft_line(line, vocab_to_idx=None, lbl_to_idx=None):
    """Convert line from fastText format to list of labels and tokens.

    If vocab_to_idx and/or lbl_to_idx provided, tokens are converted to integer indices.
    """
    line = line.strip().split()
    labels = [w for w in line if w.startswith('__label__')]
    if lbl_to_idx:
        labels = [lbl_to_idx[w] for w in labels]
    tokens = [w for w in line if not w.startswith('__label__')]
    if vocab_to_idx:
        tokens = [vocab_to_idx.get(w, len(vocab_to_idx)) for w in tokens]
    return labels, tokens