chujiezheng
commited on
Commit
•
dd4402b
1
Parent(s):
8416d3f
Add chat_template so that it can be used for chat out-of-box
Browse filesI have added a chat_template in the tokenizer (the new feature of transformers), to facilitate out-of-box use for chat
This template generally follows the claude prompt
- tokenizer_config.json +1 -0
tokenizer_config.json
CHANGED
@@ -9,6 +9,7 @@
|
|
9 |
"rstrip": false,
|
10 |
"single_word": false
|
11 |
},
|
|
|
12 |
"clean_up_tokenization_spaces": false,
|
13 |
"eos_token": {
|
14 |
"__type": "AddedToken",
|
|
|
9 |
"rstrip": false,
|
10 |
"single_word": false
|
11 |
},
|
12 |
+
"chat_template": "{% if messages[0]['role'] == 'system' %}{% set loop_messages = messages[1:] %}{% set system_message = messages[0]['content'] %}{% else %}{% set loop_messages = messages %}{% set system_message = '' %}{% endif %}{% for message in loop_messages %}{% if (message['role'] == 'user') != (loop.index0 % 2 == 0) %}{{ raise_exception('Conversation roles must alternate user/assistant/user/assistant/...') }}{% endif %}{% if loop.index0 == 0 %}{{ bos_token + system_message }}{% endif %}{% if message['role'] == 'user' %}{{ '\\n\\nUser: ' + message['content'].strip() }}{% elif message['role'] == 'assistant' %}{{ '\\n\\nAssistant: ' + message['content'].strip() }}{% endif %}{% endfor %}{% if add_generation_prompt %}{{ '\\n\\nAssistant:' }}{% endif %}",
|
13 |
"clean_up_tokenization_spaces": false,
|
14 |
"eos_token": {
|
15 |
"__type": "AddedToken",
|