File size: 1,003 Bytes
2054ea3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from transformers import GPT2Tokenizer

# we use the format `<|im_start|>{role}\n{content}<|im_end|>`, e.g.:
# 
#     User: What color is the sky?
#     Assistant: Blue, when it's sunny and the sun is not blocked
#                by the clouds.
# 
# would be encoded as:
# 
#     <|im_start|>user
#     What color is the sky?<|im_end|>
#     <|im_start|>assistant
#     Blue, when it's sunny and the sun is not blocked by the clouds.<|im_end|>

TokenizerNoIM = GPT2Tokenizer.from_pretrained('gpt2')

TokenizerNoThinking = GPT2Tokenizer.from_pretrained('gpt2')
_additional_token = [
    '<|im_start|>',
    '<|im_end|>',
]
TokenizerNoThinking.add_special_tokens({'additional_special_tokens': _additional_token})

Tokenizer = GPT2Tokenizer.from_pretrained('gpt2')
_additional_token = [
    '<|im_start|>',
    '<|im_end|>',
    '<think>',
    '</think>',
]
Tokenizer.add_special_tokens({'additional_special_tokens': _additional_token})

TokenizerVocabSize = Tokenizer.vocab_size + len(_additional_token)