def remove_special_tokens(idx, bos: int, eos: int, pad: int):
    """
    Remove special tokens from nd index list

    Args:
        idx: a nd index list
        bos: begin-of-sequence index
        eos: end-of-sequence index
        pad: padding index

    Returns:
        - index list without special tokens
    """
    if isinstance(idx, list) and isinstance(idx[0], int):
        return [i for i in idx if i not in [bos, eos, pad]]
    else:
        return [remove_special_tokens(i, bos, eos, pad) for i in idx]