derek33125
commited on
Commit
•
2e4c6ad
1
Parent(s):
3d780b5
Upload tokenizer
Browse files- added_tokens.json +16 -0
- special_tokens_map.json +32 -0
- tokenization_chatglm.py +322 -0
- tokenizer.model +3 -0
- tokenizer_config.json +148 -0
added_tokens.json
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"<eop>": 151334,
|
3 |
+
"<sop>": 151333,
|
4 |
+
"<|assistant|>": 151337,
|
5 |
+
"<|begin_of_image|>": 151339,
|
6 |
+
"<|begin_of_video|>": 151341,
|
7 |
+
"<|end_of_image|>": 151340,
|
8 |
+
"<|end_of_video|>": 151342,
|
9 |
+
"<|endoftext|>": 151329,
|
10 |
+
"<|observation|>": 151338,
|
11 |
+
"<|system|>": 151335,
|
12 |
+
"<|user|>": 151336,
|
13 |
+
"[MASK]": 151330,
|
14 |
+
"[gMASK]": 151331,
|
15 |
+
"[sMASK]": 151332
|
16 |
+
}
|
special_tokens_map.json
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"additional_special_tokens": [
|
3 |
+
"<|endoftext|>",
|
4 |
+
"[MASK]",
|
5 |
+
"[gMASK]",
|
6 |
+
"[sMASK]",
|
7 |
+
"<sop>",
|
8 |
+
"<eop>",
|
9 |
+
"<|system|>",
|
10 |
+
"<|user|>",
|
11 |
+
"<|assistant|>",
|
12 |
+
"<|observation|>",
|
13 |
+
"<|begin_of_image|>",
|
14 |
+
"<|end_of_image|>",
|
15 |
+
"<|begin_of_video|>",
|
16 |
+
"<|end_of_video|>"
|
17 |
+
],
|
18 |
+
"eos_token": {
|
19 |
+
"content": "<|endoftext|>",
|
20 |
+
"lstrip": false,
|
21 |
+
"normalized": false,
|
22 |
+
"rstrip": false,
|
23 |
+
"single_word": false
|
24 |
+
},
|
25 |
+
"pad_token": {
|
26 |
+
"content": "<|endoftext|>",
|
27 |
+
"lstrip": false,
|
28 |
+
"normalized": false,
|
29 |
+
"rstrip": false,
|
30 |
+
"single_word": false
|
31 |
+
}
|
32 |
+
}
|
tokenization_chatglm.py
ADDED
@@ -0,0 +1,322 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import regex as re
|
2 |
+
import base64
|
3 |
+
import os
|
4 |
+
import json
|
5 |
+
import tiktoken
|
6 |
+
from typing import List, Optional, Union, Dict, Any
|
7 |
+
from transformers import PreTrainedTokenizer
|
8 |
+
from transformers.utils import logging, PaddingStrategy, TensorType
|
9 |
+
from transformers.tokenization_utils_base import EncodedInput, BatchEncoding
|
10 |
+
|
11 |
+
|
12 |
+
class ChatGLM4Tokenizer(PreTrainedTokenizer):
|
13 |
+
vocab_files_names = {"vocab_file": "tokenizer.model"}
|
14 |
+
model_input_names = ["input_ids", "attention_mask", "position_ids"]
|
15 |
+
|
16 |
+
def __init__(
|
17 |
+
self,
|
18 |
+
vocab_file,
|
19 |
+
padding_side="left",
|
20 |
+
clean_up_tokenization_spaces=False,
|
21 |
+
encode_special_tokens=False,
|
22 |
+
**kwargs
|
23 |
+
):
|
24 |
+
self.name = "GLM4Tokenizer"
|
25 |
+
self.vocab_file = vocab_file
|
26 |
+
pat_str = "(?i:'s|'t|'re|'ve|'m|'ll|'d)|[^\\r\\n\\p{L}\\p{N}]?\\p{L}+|\\p{N}{1,3}| ?[^\\s\\p{L}\\p{N}]+[\\r\\n]*|\\s*[\\r\\n]+|\\s+(?!\\S)|\\s+"
|
27 |
+
self.pat_str = re.compile(pat_str)
|
28 |
+
self.encode_special_tokens = encode_special_tokens
|
29 |
+
|
30 |
+
mergeable_ranks = {}
|
31 |
+
with open(vocab_file) as f:
|
32 |
+
for line in f:
|
33 |
+
token, rank = line.strip().split()
|
34 |
+
rank = int(rank)
|
35 |
+
token = base64.b64decode(token)
|
36 |
+
mergeable_ranks[token] = rank
|
37 |
+
|
38 |
+
self.mergeable_ranks = mergeable_ranks
|
39 |
+
|
40 |
+
self.tokenizer = tiktoken.Encoding(
|
41 |
+
name="my_tokenizer",
|
42 |
+
pat_str=pat_str,
|
43 |
+
mergeable_ranks=mergeable_ranks,
|
44 |
+
special_tokens={}
|
45 |
+
)
|
46 |
+
self.decoder = {rank: token for token, rank in mergeable_ranks.items()}
|
47 |
+
self.n_words = len(self.decoder)
|
48 |
+
|
49 |
+
super().__init__(
|
50 |
+
padding_side=padding_side,
|
51 |
+
clean_up_tokenization_spaces=clean_up_tokenization_spaces,
|
52 |
+
**kwargs
|
53 |
+
)
|
54 |
+
|
55 |
+
@property
|
56 |
+
def vocab_size(self):
|
57 |
+
return self.n_words
|
58 |
+
|
59 |
+
def get_vocab(self):
|
60 |
+
""" Returns vocab as a dict """
|
61 |
+
vocab = {self._convert_id_to_token(i): i for i in range(self.vocab_size)}
|
62 |
+
vocab.update(self.added_tokens_encoder)
|
63 |
+
return vocab
|
64 |
+
|
65 |
+
def convert_tokens_to_string(self, tokens: List[Union[bytes, str, int]]) -> str:
|
66 |
+
"""
|
67 |
+
Converts a sequence of tokens in a single string.
|
68 |
+
"""
|
69 |
+
text = ""
|
70 |
+
temp = b""
|
71 |
+
for t in tokens:
|
72 |
+
if isinstance(t, int):
|
73 |
+
t = chr(t)
|
74 |
+
if isinstance(t, str):
|
75 |
+
if temp:
|
76 |
+
text += temp.decode("utf-8", errors="replace")
|
77 |
+
elif isinstance(t, bytes):
|
78 |
+
temp += t
|
79 |
+
else:
|
80 |
+
raise TypeError("token should only be of type int, bytes or str")
|
81 |
+
if temp:
|
82 |
+
text += temp.decode("utf-8", errors="replace")
|
83 |
+
return text
|
84 |
+
|
85 |
+
def _tokenize(self, text, **kwargs):
|
86 |
+
tokens = []
|
87 |
+
ids = self.tokenizer.encode(text)
|
88 |
+
for t in ids:
|
89 |
+
tokens.append(self.decoder[t])
|
90 |
+
return tokens
|
91 |
+
|
92 |
+
def _convert_token_to_id(self, token):
|
93 |
+
""" Converts a token (str) in an id using the vocab. """
|
94 |
+
return self.mergeable_ranks[token]
|
95 |
+
|
96 |
+
def _convert_id_to_token(self, index):
|
97 |
+
"""Converts an index (integer) in a token (str) using the vocab."""
|
98 |
+
return self.decoder.get(index, "")
|
99 |
+
|
100 |
+
def save_vocabulary(self, save_directory, filename_prefix=None):
|
101 |
+
"""
|
102 |
+
Save the vocabulary and special tokens file to a directory.
|
103 |
+
|
104 |
+
Args:
|
105 |
+
save_directory (`str`):
|
106 |
+
The directory in which to save the vocabulary.
|
107 |
+
filename_prefix (`str`, *optional*):
|
108 |
+
An optional prefix to add to the named of the saved files.
|
109 |
+
|
110 |
+
Returns:
|
111 |
+
`Tuple(str)`: Paths to the files saved.
|
112 |
+
"""
|
113 |
+
if os.path.isdir(save_directory):
|
114 |
+
vocab_file = os.path.join(
|
115 |
+
save_directory, self.vocab_files_names["vocab_file"]
|
116 |
+
)
|
117 |
+
else:
|
118 |
+
vocab_file = save_directory
|
119 |
+
|
120 |
+
with open(self.vocab_file, 'rb') as fin:
|
121 |
+
proto_str = fin.read()
|
122 |
+
|
123 |
+
with open(vocab_file, "wb") as writer:
|
124 |
+
writer.write(proto_str)
|
125 |
+
|
126 |
+
return (vocab_file,)
|
127 |
+
|
128 |
+
def get_prefix_tokens(self):
|
129 |
+
prefix_tokens = [self.convert_tokens_to_ids("[gMASK]"), self.convert_tokens_to_ids("<sop>")]
|
130 |
+
return prefix_tokens
|
131 |
+
|
132 |
+
def build_single_message(self, role, metadata, message, tokenize=True):
|
133 |
+
assert role in ["system", "user", "assistant", "observation"], role
|
134 |
+
if tokenize:
|
135 |
+
role_tokens = [self.convert_tokens_to_ids(f"<|{role}|>")] + self.tokenizer.encode(f"{metadata}\n",
|
136 |
+
disallowed_special=())
|
137 |
+
message_tokens = self.tokenizer.encode(message, disallowed_special=())
|
138 |
+
tokens = role_tokens + message_tokens
|
139 |
+
return tokens
|
140 |
+
else:
|
141 |
+
return str(f"<|{role}|>{metadata}\n{message}")
|
142 |
+
|
143 |
+
# Use Jinja Template in tokenizer_config.json
|
144 |
+
# def apply_chat_template(
|
145 |
+
# self,
|
146 |
+
# conversation: Union[List[Dict[str, str]], List[List[Dict[str, str]]], "Conversation"],
|
147 |
+
# add_generation_prompt: bool = False,
|
148 |
+
# tokenize: bool = True,
|
149 |
+
# padding: bool = False,
|
150 |
+
# truncation: bool = False,
|
151 |
+
# max_length: Optional[int] = None,
|
152 |
+
# return_tensors: Optional[Union[str, TensorType]] = None,
|
153 |
+
# return_dict: bool = False,
|
154 |
+
# tokenizer_kwargs: Optional[Dict[str, Any]] = None,
|
155 |
+
# add_special_tokens: bool = True,
|
156 |
+
# **kwargs,
|
157 |
+
# ) -> Union[str, List[int], List[str], List[List[int]], BatchEncoding]:
|
158 |
+
#
|
159 |
+
# if return_dict and not tokenize:
|
160 |
+
# raise ValueError(
|
161 |
+
# "`return_dict=True` is incompatible with `tokenize=False`, because there is no dict "
|
162 |
+
# "of tokenizer outputs to return."
|
163 |
+
# )
|
164 |
+
#
|
165 |
+
# def handle_single_conversation(conversation):
|
166 |
+
# input_ids = self.get_prefix_tokens() if add_special_tokens else []
|
167 |
+
# input_message = "[gMASK]<sop>" if add_special_tokens else ""
|
168 |
+
# for item in conversation:
|
169 |
+
# if item.get("tools"):
|
170 |
+
# tools = item["tools"]
|
171 |
+
# content = "你是一个名为 GhatGLM 的人工智能助手。你是基于智谱AI训练的语言模型 GLM-4 模型开发的,你的任务是针对用户的问题和要求提供适当的答复和支持。"
|
172 |
+
# content += "\n\n# 可用工具"
|
173 |
+
# for tool in tools:
|
174 |
+
# if tool["type"] == "function":
|
175 |
+
# function = tool["function"]
|
176 |
+
# content += f"\n\n## {function['name']}\n\n{json.dumps(function, ensure_ascii=False, indent=4)}"
|
177 |
+
# content += "\n在调用上述函数时,请使用 Json 格式表示调用的参数。"
|
178 |
+
# elif tool["type"] == "python":
|
179 |
+
# content += "\n\n## python\n\n当你向 `python` 发送包含 Python 代码的消息时,该代码将会在一个有状态的 Jupyter notebook 环境中执行。\n`python` 返回代码执行的输出,或在执行 60 秒后返回超时。\n`/mnt/data` 将会持久化存储你的文件。在此会话中,`python` 无法访问互联网。不要使用 `python` 进行任何网络请求或者在线 API 调用,这些在线内容的访问将不会成功。"
|
180 |
+
# elif tool["type"] == "simple_browser":
|
181 |
+
# content += "\n\n## simple_browser\n\n你可以使用 `simple_browser` 工具。该工具支持以下函数:\n`search(query: str, recency_days: int)`:使用搜索引擎进行查询并显示结果,可以使用 `recency_days` 参数控制搜索内容的时效性。\n`mclick(ids: list[int])`:获取一系列指定 id 的页面内容。每次调用时,须选择3-10个页面。选择多个角度的页面,同时尽可能选择可信任的信息来源。考虑到部分页面是无法加载的,你也可以多打开一些可能有用的页面而不用担心内容过多。\n`open_url(url: str)`:打开指定的 URL。\n\n使用 `【{引用 id}†{引用文本}】` 来引用内容。\n\n操作步骤:1. 使用 `search` 来获得信息列表; 2. 使用 `mclick` 来获取指定 ID 页面的内容; 3. 根据获得的内容进行回复。在回复中应当引用信息来源。\n 如果用户提供了 URL,也可以用 `open_url` 直接打开页面。\n如果初次搜索结果没有找到合适的信息,也可以再次使用 `search` 进行搜索。"
|
182 |
+
# elif tool["type"] == "cogview":
|
183 |
+
# content += "\n\n## cogview\n\n如果用户的请求中包含了对图像的描述,你可以使用 `cogview` 来生成图像并展示给用户。你需要向 `cogview` 发送图像描述,规则:\n- 发送给 `cogview` 的消息必须使用英语。用户的中文描述必须完全翻译为英语。\n- 应当尽可能详细地描述图像生成的需求,需求描述约 100 英文单词。\n- 保持用户原始描述的意图。不要虚构内容或者没见过的人物。\n- 如无特殊说明,所在地为中国,持有中国立场并遵循中国社会主义价值观。"
|
184 |
+
# else:
|
185 |
+
# raise NotImplementedError(f"Unknown tool type {tool['type']}")
|
186 |
+
# input = self.build_single_message("system", "", content, tokenize=tokenize)
|
187 |
+
# if tokenize:
|
188 |
+
# input_ids.extend(input)
|
189 |
+
# else:
|
190 |
+
# input_message += input
|
191 |
+
# if item["content"]:
|
192 |
+
# input = self.build_single_message(
|
193 |
+
# item["role"],
|
194 |
+
# item.get("metadata", ""),
|
195 |
+
# item["content"],
|
196 |
+
# tokenize=tokenize
|
197 |
+
# )
|
198 |
+
# if tokenize:
|
199 |
+
# input_ids.extend(input)
|
200 |
+
# else:
|
201 |
+
# input_message += input
|
202 |
+
# if add_generation_prompt:
|
203 |
+
# if tokenize:
|
204 |
+
# input_ids.extend([self.convert_tokens_to_ids("<|assistant|>")])
|
205 |
+
# else:
|
206 |
+
# input_message += "<|assistant|>"
|
207 |
+
# return input_ids if tokenize else input_message
|
208 |
+
#
|
209 |
+
# # Main logic to handle different conversation formats
|
210 |
+
# if isinstance(conversation, list) and all(isinstance(i, dict) for i in conversation):
|
211 |
+
# result = handle_single_conversation(conversation)
|
212 |
+
# elif isinstance(conversation, list) and all(isinstance(i, list) for i in conversation):
|
213 |
+
# result = [handle_single_conversation(c) for c in conversation]
|
214 |
+
# elif hasattr(conversation, "messages"):
|
215 |
+
# result = handle_single_conversation(conversation.messages)
|
216 |
+
# else:
|
217 |
+
# raise ValueError("Invalid conversation format")
|
218 |
+
#
|
219 |
+
# if tokenize:
|
220 |
+
# output = self.batch_encode_plus(
|
221 |
+
# [result] if isinstance(result[0], int) else result,
|
222 |
+
# padding=padding,
|
223 |
+
# truncation=truncation,
|
224 |
+
# max_length=max_length,
|
225 |
+
# return_tensors=return_tensors,
|
226 |
+
# is_split_into_words=True,
|
227 |
+
# add_special_tokens=False
|
228 |
+
# )
|
229 |
+
# if return_dict:
|
230 |
+
# return output
|
231 |
+
# else:
|
232 |
+
# return output["input_ids"]
|
233 |
+
# else:
|
234 |
+
# return result
|
235 |
+
|
236 |
+
def build_inputs_with_special_tokens(
|
237 |
+
self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None
|
238 |
+
) -> List[int]:
|
239 |
+
"""
|
240 |
+
Build model inputs from a sequence or a pair of sequence for sequence classification tasks by concatenating and
|
241 |
+
adding special tokens. A BERT sequence has the following format:
|
242 |
+
|
243 |
+
- single sequence: `[CLS] X [SEP]`
|
244 |
+
- pair of sequences: `[CLS] A [SEP] B [SEP]`
|
245 |
+
|
246 |
+
Args:
|
247 |
+
token_ids_0 (`List[int]`):
|
248 |
+
List of IDs to which the special tokens will be added.
|
249 |
+
token_ids_1 (`List[int]`, *optional*):
|
250 |
+
Optional second list of IDs for sequence pairs.
|
251 |
+
|
252 |
+
Returns:
|
253 |
+
`List[int]`: List of [input IDs](../glossary#input-ids) with the appropriate special tokens.
|
254 |
+
"""
|
255 |
+
prefix_tokens = self.get_prefix_tokens()
|
256 |
+
token_ids_0 = prefix_tokens + token_ids_0
|
257 |
+
if token_ids_1 is not None:
|
258 |
+
token_ids_0 = token_ids_0 + token_ids_1 + [self.convert_tokens_to_ids("<eos>")]
|
259 |
+
return token_ids_0
|
260 |
+
|
261 |
+
def _pad(
|
262 |
+
self,
|
263 |
+
encoded_inputs: Union[Dict[str, EncodedInput], BatchEncoding],
|
264 |
+
max_length: Optional[int] = None,
|
265 |
+
padding_strategy: PaddingStrategy = PaddingStrategy.DO_NOT_PAD,
|
266 |
+
pad_to_multiple_of: Optional[int] = None,
|
267 |
+
return_attention_mask: Optional[bool] = None,
|
268 |
+
) -> dict:
|
269 |
+
"""
|
270 |
+
Pad encoded inputs (on left/right and up to predefined length or max length in the batch)
|
271 |
+
|
272 |
+
Args:
|
273 |
+
encoded_inputs:
|
274 |
+
Dictionary of tokenized inputs (`List[int]`) or batch of tokenized inputs (`List[List[int]]`).
|
275 |
+
max_length: maximum length of the returned list and optionally padding length (see below).
|
276 |
+
Will truncate by taking into account the special tokens.
|
277 |
+
padding_strategy: PaddingStrategy to use for padding.
|
278 |
+
|
279 |
+
- PaddingStrategy.LONGEST Pad to the longest sequence in the batch
|
280 |
+
- PaddingStrategy.MAX_LENGTH: Pad to the max length (default)
|
281 |
+
- PaddingStrategy.DO_NOT_PAD: Do not pad
|
282 |
+
The tokenizer padding sides are defined in self.padding_side:
|
283 |
+
|
284 |
+
- 'left': pads on the left of the sequences
|
285 |
+
- 'right': pads on the right of the sequences
|
286 |
+
pad_to_multiple_of: (optional) Integer if set will pad the sequence to a multiple of the provided value.
|
287 |
+
This is especially useful to enable the use of Tensor Core on NVIDIA hardware with compute capability
|
288 |
+
`>= 7.5` (Volta).
|
289 |
+
return_attention_mask:
|
290 |
+
(optional) Set to False to avoid returning attention mask (default: set to model specifics)
|
291 |
+
"""
|
292 |
+
# Load from model defaults
|
293 |
+
assert self.padding_side == "left"
|
294 |
+
|
295 |
+
required_input = encoded_inputs[self.model_input_names[0]]
|
296 |
+
seq_length = len(required_input)
|
297 |
+
|
298 |
+
if padding_strategy == PaddingStrategy.LONGEST:
|
299 |
+
max_length = len(required_input)
|
300 |
+
|
301 |
+
if max_length is not None and pad_to_multiple_of is not None and (max_length % pad_to_multiple_of != 0):
|
302 |
+
max_length = ((max_length // pad_to_multiple_of) + 1) * pad_to_multiple_of
|
303 |
+
|
304 |
+
needs_to_be_padded = padding_strategy != PaddingStrategy.DO_NOT_PAD and len(required_input) != max_length
|
305 |
+
|
306 |
+
# Initialize attention mask if not present.
|
307 |
+
if "attention_mask" not in encoded_inputs:
|
308 |
+
encoded_inputs["attention_mask"] = [1] * seq_length
|
309 |
+
|
310 |
+
if "position_ids" not in encoded_inputs:
|
311 |
+
encoded_inputs["position_ids"] = list(range(seq_length))
|
312 |
+
|
313 |
+
if needs_to_be_padded:
|
314 |
+
difference = max_length - len(required_input)
|
315 |
+
|
316 |
+
if "attention_mask" in encoded_inputs:
|
317 |
+
encoded_inputs["attention_mask"] = [0] * difference + encoded_inputs["attention_mask"]
|
318 |
+
if "position_ids" in encoded_inputs:
|
319 |
+
encoded_inputs["position_ids"] = [0] * difference + encoded_inputs["position_ids"]
|
320 |
+
encoded_inputs[self.model_input_names[0]] = [self.pad_token_id] * difference + required_input
|
321 |
+
|
322 |
+
return encoded_inputs
|
tokenizer.model
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:5a493598071550244b2ee7f26118f3edec2150b9dfa967929a99052ac83fe716
|
3 |
+
size 2623634
|
tokenizer_config.json
ADDED
@@ -0,0 +1,148 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"added_tokens_decoder": {
|
3 |
+
"151329": {
|
4 |
+
"content": "<|endoftext|>",
|
5 |
+
"lstrip": false,
|
6 |
+
"normalized": false,
|
7 |
+
"rstrip": false,
|
8 |
+
"single_word": false,
|
9 |
+
"special": true
|
10 |
+
},
|
11 |
+
"151330": {
|
12 |
+
"content": "[MASK]",
|
13 |
+
"lstrip": false,
|
14 |
+
"normalized": false,
|
15 |
+
"rstrip": false,
|
16 |
+
"single_word": false,
|
17 |
+
"special": true
|
18 |
+
},
|
19 |
+
"151331": {
|
20 |
+
"content": "[gMASK]",
|
21 |
+
"lstrip": false,
|
22 |
+
"normalized": false,
|
23 |
+
"rstrip": false,
|
24 |
+
"single_word": false,
|
25 |
+
"special": true
|
26 |
+
},
|
27 |
+
"151332": {
|
28 |
+
"content": "[sMASK]",
|
29 |
+
"lstrip": false,
|
30 |
+
"normalized": false,
|
31 |
+
"rstrip": false,
|
32 |
+
"single_word": false,
|
33 |
+
"special": true
|
34 |
+
},
|
35 |
+
"151333": {
|
36 |
+
"content": "<sop>",
|
37 |
+
"lstrip": false,
|
38 |
+
"normalized": false,
|
39 |
+
"rstrip": false,
|
40 |
+
"single_word": false,
|
41 |
+
"special": true
|
42 |
+
},
|
43 |
+
"151334": {
|
44 |
+
"content": "<eop>",
|
45 |
+
"lstrip": false,
|
46 |
+
"normalized": false,
|
47 |
+
"rstrip": false,
|
48 |
+
"single_word": false,
|
49 |
+
"special": true
|
50 |
+
},
|
51 |
+
"151335": {
|
52 |
+
"content": "<|system|>",
|
53 |
+
"lstrip": false,
|
54 |
+
"normalized": false,
|
55 |
+
"rstrip": false,
|
56 |
+
"single_word": false,
|
57 |
+
"special": true
|
58 |
+
},
|
59 |
+
"151336": {
|
60 |
+
"content": "<|user|>",
|
61 |
+
"lstrip": false,
|
62 |
+
"normalized": false,
|
63 |
+
"rstrip": false,
|
64 |
+
"single_word": false,
|
65 |
+
"special": true
|
66 |
+
},
|
67 |
+
"151337": {
|
68 |
+
"content": "<|assistant|>",
|
69 |
+
"lstrip": false,
|
70 |
+
"normalized": false,
|
71 |
+
"rstrip": false,
|
72 |
+
"single_word": false,
|
73 |
+
"special": true
|
74 |
+
},
|
75 |
+
"151338": {
|
76 |
+
"content": "<|observation|>",
|
77 |
+
"lstrip": false,
|
78 |
+
"normalized": false,
|
79 |
+
"rstrip": false,
|
80 |
+
"single_word": false,
|
81 |
+
"special": true
|
82 |
+
},
|
83 |
+
"151339": {
|
84 |
+
"content": "<|begin_of_image|>",
|
85 |
+
"lstrip": false,
|
86 |
+
"normalized": false,
|
87 |
+
"rstrip": false,
|
88 |
+
"single_word": false,
|
89 |
+
"special": true
|
90 |
+
},
|
91 |
+
"151340": {
|
92 |
+
"content": "<|end_of_image|>",
|
93 |
+
"lstrip": false,
|
94 |
+
"normalized": false,
|
95 |
+
"rstrip": false,
|
96 |
+
"single_word": false,
|
97 |
+
"special": true
|
98 |
+
},
|
99 |
+
"151341": {
|
100 |
+
"content": "<|begin_of_video|>",
|
101 |
+
"lstrip": false,
|
102 |
+
"normalized": false,
|
103 |
+
"rstrip": false,
|
104 |
+
"single_word": false,
|
105 |
+
"special": true
|
106 |
+
},
|
107 |
+
"151342": {
|
108 |
+
"content": "<|end_of_video|>",
|
109 |
+
"lstrip": false,
|
110 |
+
"normalized": false,
|
111 |
+
"rstrip": false,
|
112 |
+
"single_word": false,
|
113 |
+
"special": true
|
114 |
+
}
|
115 |
+
},
|
116 |
+
"additional_special_tokens": [
|
117 |
+
"<|endoftext|>",
|
118 |
+
"[MASK]",
|
119 |
+
"[gMASK]",
|
120 |
+
"[sMASK]",
|
121 |
+
"<sop>",
|
122 |
+
"<eop>",
|
123 |
+
"<|system|>",
|
124 |
+
"<|user|>",
|
125 |
+
"<|assistant|>",
|
126 |
+
"<|observation|>",
|
127 |
+
"<|begin_of_image|>",
|
128 |
+
"<|end_of_image|>",
|
129 |
+
"<|begin_of_video|>",
|
130 |
+
"<|end_of_video|>"
|
131 |
+
],
|
132 |
+
"auto_map": {
|
133 |
+
"AutoTokenizer": [
|
134 |
+
"tokenization_chatglm.ChatGLM4Tokenizer",
|
135 |
+
null
|
136 |
+
]
|
137 |
+
},
|
138 |
+
"chat_template": "{{ '[gMASK]<sop>' }}{% if messages[0]['role'] == 'system' %}{% set loop_messages = messages[1:] %}{% set system_message = messages[0]['content'] %}{% else %}{% set loop_messages = messages %}{% endif %}{% if system_message is defined %}{{ '<|system|>\n' + system_message }}{% endif %}{% for message in loop_messages %}{% set content = message['content'] %}{% if message['role'] == 'user' %}{{ '<|user|>\n' + content + '<|assistant|>' }}{% elif message['role'] == 'assistant' %}{{ '\n' + content }}{% endif %}{% endfor %}",
|
139 |
+
"clean_up_tokenization_spaces": false,
|
140 |
+
"do_lower_case": false,
|
141 |
+
"eos_token": "<|endoftext|>",
|
142 |
+
"model_max_length": 128000,
|
143 |
+
"pad_token": "<|endoftext|>",
|
144 |
+
"padding_side": "left",
|
145 |
+
"remove_space": false,
|
146 |
+
"split_special_tokens": false,
|
147 |
+
"tokenizer_class": "ChatGLM4Tokenizer"
|
148 |
+
}
|