def _has_repeated_entity(tokens, token_strings, vocab_size, comma_id):
    """
    Returns whether the same entity token is repeated back to back or separated by a comma.
    E.g. 'Obama Obama' or 'India, India'.
    """
    for i in range(len(tokens) - 2):
        if tokens[i] < vocab_size:
            continue
        if token_strings[i] == token_strings[i + 1]:
            return True
        if token_strings[i] == token_strings[i + 2] and tokens[i + 1] == comma_id:
            return True

    if tokens[-2] >= vocab_size and token_strings[-2] == token_strings[-1]:
        return True

    return False