def convert_tokens_to_ids(word_to_id, tokens, max_sent_length=None, unknown_token=None):
    """
    Converts tokens to integers with a predefined given mapping from word_to_id dictionary
    :param Dict[str, int] vocabulary:
    :param List[str] tokens:
    :param Optional[str] unknown_token: The token to use for tokens that are not in the index. If
    None is given then '<OOV>' is used.
    :rtype: List[int]
    """
    if unknown_token is None:
        unknown_token = '<OOV>'

    if max_sent_length is not None:
        tokens = [item for sublist in tokens for item in sublist]

    text_to_id = [
        word_to_id[token] if token in word_to_id else word_to_id[unknown_token]
        for token in tokens
    ]
    if max_sent_length is not None:
        text_to_id = [text_to_id[x:x + max_sent_length] for x in range(0, len(text_to_id), max_sent_length)]

    return text_to_id