def create_subtoken_map(tokens_len, indices):
    """
    Creates subtoken map by grouping specified indices.
    """
    if len(indices) == 0:
        return list(range(tokens_len))  # No entities, nothing to do

    k = 0  # Tracks new tokens with named entities grouped
    j = 0  # Tracks which named entity we are processing
    subtoken_map = {}
    sorted_indices = sorted(indices, key=lambda x: x[0])
    curr_start, curr_end = sorted_indices[j]
    for i in range(tokens_len):
        if i > curr_end and j < len(sorted_indices) - 1:  # Move up to next named entity
            j += 1
            curr_start, curr_end = sorted_indices[j]

        if curr_start <= i < curr_end:
            subtoken_map[i] = k
        else:
            subtoken_map[i] = k
            k += 1
    return list(subtoken_map.values())