Utils for applying chat templates

trl.apply_chat_template

< >

( example: Dict tokenizer: PreTrainedTokenizer )

Apply a chat template to a conversational example.

For more details, see maybe_apply_chat_template().

trl.data_utils.is_conversational

< >

( example: Dict ) bool

Parameters

  • example (Dict[str, Any]) — A single data entry of a dataset. The example can have different keys depending on the dataset format.

Returns

bool

True if the data is in a conversational format, False otherwise.

Check if the example is in a conversational format.

Examples:

>>> example = {"prompt": [{"role": "user", "content": "What color is the sky?"}]}
>>> is_conversational(example)
True
>>> example = {"prompt": "The sky is"})
>>> is_conversational(example)
False
< > Update on GitHub