def _get_token_ids(token_word_ids, span_word_id, offset=1):
    """Retrieve token ids based on word ids.
    Args:
        token_word_ids: the list of word ids for token.
        span_word_id: int. the word id in the original string.
        offset: int. if the tokenized sequence is prepended with special token, this offset will be set to
        the number of special tokens (for example, if [CLS] is added, then offset=1).
    For example, the token word ids can be:
     ['ir', 'an', 'Ġand', 'Ġaf', 'ghan', 'istan', 'Ġspeak', 'Ġthe', 'Ġsame', 'Ġlanguage', 'Ġ.']
    And the original sentence is "iran and afghanistan speak the same language ."
    Suppose the span_word_id is 2 (afghanistan), then the token id is [3, 4, 5]
    """
    results = []
    for ix, word_id in enumerate(token_word_ids):
        if word_id == span_word_id:
            results.append(ix + offset)
        elif word_id > span_word_id:
            break
    return results