def reverse_subtoken_map(subtoken_map):
    """
    Creates a map: idx --> (left_span_boundary, right_span_boundary) that effectively reverse the map created in
    create_subtoken_map.
    """
    reverse_map = {}
    for idx, mapped_val in enumerate(subtoken_map):
        if mapped_val in reverse_map:
            reverse_map[mapped_val] = (min(idx, reverse_map[mapped_val][0]), max(idx, reverse_map[mapped_val][1]))
        else:
            reverse_map[mapped_val] = (idx, idx)
    return list(reverse_map.values())