# Tokenizer.apply\_chat\_template vs formatting\_func

**URL:** <https://discuss.huggingface.co/t/tokenizer-apply-chat-template-vs-formatting-func/95096>\
**Category:** Beginners\
**Created:** [July 2, 2024, 7:45am UTC](https://discuss.huggingface.co/t/tokenizer-apply-chat-template-vs-formatting-func/95096 "2024-07-02T07:45:32Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![zy113](https://avatars.discourse-cdn.com/v4/letter/z/278dde/32.png) [@zy113](https://discuss.huggingface.co/u/zy113)\
**Post date:** [July 2, 2024, 7:45am UTC](https://discuss.huggingface.co/t/tokenizer-apply-chat-template-vs-formatting-func/95096/1 "2024-07-02T07:45:32Z")

</div>

From what I understand from h[ttps://huggingface.co/docs/transformers/main/en/chat\_templating#what-are-generation-prompts](https://huggingface.co/docs/transformers/main/en/chat_templating#can-i-use-chat-templates-in-training), tokenizer.apply\_chat\_template serves exactly the same role as

```auto
def formatting_prompts_func(example):
    output_texts = []
    for i in range(len(example['question'])):
        text = f"### Question: {example['question'][i]}\n ### Answer: {example['answer'][i]}"
        output_texts.append(text)
    return output_texts

```

in [Supervised Fine-tuning Trainer](https://huggingface.co/docs/trl/en/sft_trainer#format-your-input-prompts). Is my understanding correct? If not, what are some of their differences?
