def get_token_segments(labels, word_ids):
    """
    Function to extract correctly formatted answers
    
    Input: array of labels (can be predicted labels, or true labels)
    Output: array of tuples; (start index of answer, length of answer)
    """
    prev_word_id = None
    labels_stats = []
    for idx, label in enumerate(labels):
        if label == 1 and word_ids[idx] != prev_word_id:
            count = 1
            prev_word_id = word_ids[idx]
            while idx+count < len(labels):
                next_label = labels[idx+count]
                if next_label == 0:
                    break
                if next_label == 1 and word_ids[idx+count] != prev_word_id:
                    break 
                count += 1
            labels_stats.append((idx, count))
    return labels_stats