From 2518e368105a78f6cdc50ded6971712f2c1e7ac4 Mon Sep 17 00:00:00 2001 From: Matt Date: Fri, 15 Sep 2023 12:50:57 +0100 Subject: [PATCH] Tweaks to Chat Templates docs (#26168) * Put tokenizer methods in the right alphabetical order in the docs * Quick tweak to ConversationalPipeline * Typo fixes in the developer doc * make fixup --- docs/source/en/chat_templating.md | 4 ++-- docs/source/en/main_classes/tokenizer.md | 4 ++-- src/transformers/pipelines/conversational.py | 4 +++- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/docs/source/en/chat_templating.md b/docs/source/en/chat_templating.md index 8a9c1e915d4e..f568c9949efd 100644 --- a/docs/source/en/chat_templating.md +++ b/docs/source/en/chat_templating.md @@ -190,7 +190,7 @@ once you set the correct chat template, your model will automatically become com Before the introduction of chat templates, chat handling was hardcoded at the model class level. For backwards compatibility, we have retained this class-specific handling as default templates, also set at the class level. If a -model does not have a chat template set, but there is a default template for its model class, the `ConversationPipeline` +model does not have a chat template set, but there is a default template for its model class, the `ConversationalPipeline` class and methods like `apply_chat_template` will use the class template instead. You can find out what the default template for your tokenizer is by checking the `tokenizer.default_chat_template` attribute. @@ -248,7 +248,7 @@ with an empty chat template, or one that's still using the default class templat the model repository so that this attribute can be set properly! Once the attribute is set, that's it, you're done! `tokenizer.apply_chat_template` will now work correctly for that -model, which means it is also automatically supported in places like `ConversationPipeline`! +model, which means it is also automatically supported in places like `ConversationalPipeline`! By ensuring that models have this attribute, we can make sure that the whole community gets to use the full power of open-source models. Formatting mismatches have been haunting the field and silently harming performance for too long - diff --git a/docs/source/en/main_classes/tokenizer.md b/docs/source/en/main_classes/tokenizer.md index 71f96c55cb51..bf43014ee51d 100644 --- a/docs/source/en/main_classes/tokenizer.md +++ b/docs/source/en/main_classes/tokenizer.md @@ -55,10 +55,10 @@ to a given token). [[autodoc]] PreTrainedTokenizer - __call__ + - apply_chat_template - batch_decode - decode - encode - - apply_chat_template - push_to_hub - all @@ -69,10 +69,10 @@ loaded very simply into 🤗 transformers. Take a look at the [Using tokenizers [[autodoc]] PreTrainedTokenizerFast - __call__ + - apply_chat_template - batch_decode - decode - encode - - apply_chat_template - push_to_hub - all diff --git a/src/transformers/pipelines/conversational.py b/src/transformers/pipelines/conversational.py index c455c7557443..3d037799c839 100644 --- a/src/transformers/pipelines/conversational.py +++ b/src/transformers/pipelines/conversational.py @@ -275,7 +275,9 @@ def _forward(self, model_inputs, minimum_tokens=10, **generate_kwargs): n = model_inputs["input_ids"].shape[1] if max_length - minimum_tokens < n: - logger.warning(f"Conversation input is to long ({n}), trimming it to ({max_length} - {minimum_tokens})") + logger.warning( + f"Conversation input is too long ({n}), trimming it to {max_length - minimum_tokens} tokens. Consider increasing `max_length` to avoid truncation." + ) trim = max_length - minimum_tokens model_inputs["input_ids"] = model_inputs["input_ids"][:, -trim:] if "attention_mask" in model_inputs: