def transform_context_token_ids_to_sentences(x_ids, index_to_token):
    """
    Transforms batch of token ids into list of joined strings (sentences)
    Transformation of each sentence ends when the end_token occurred.
    Skips start tokens.

    :param x_ids: context token ids, numpy array of shape (batch_size, context_len, tokens_num)
    :param index_to_token:
    :return:
    """
    n_samples, n_contexts, n_tokens = x_ids.shape

    samples = []
    for sample_idx in range(n_samples):
        context_samples = []
        for cont_idx in range(n_contexts):
            sample_tokens = []
            for token_idx in range(n_tokens):
                token_to_add = index_to_token[x_ids[sample_idx, cont_idx, token_idx]]

                if token_to_add == SPECIAL_TOKENS.EOS_TOKEN or token_to_add == SPECIAL_TOKENS.PAD_TOKEN:
                    break
                if token_to_add == SPECIAL_TOKENS.START_TOKEN:
                    continue

                sample_tokens.append(token_to_add)

            sample_str = ' '.join(sample_tokens)
            context_samples.append(sample_str)
        samples.append(' / '.join(context_samples))
    return samples

    Transforms batch of token ids into list of joined strings (sentences)
    Transformation of each sentence ends when the end_token occurred.
    Skips start tokens.

    :param x_ids: context token ids, numpy array of shape (batch_size, context_len, tokens_num)
    :param index_to_token:
    :return:
    
cakechat/dialog_model/model_utils.py