我下载了一些中文wikipedia数据,准备采用ChatGLMTokenizer对齐进行清洗,整理为预训练语料。
cpp
import numpy as np
import json
from tqdm import tqdm
from chatglm_tokenizer.tokenization_chatglm import ChatGLMTokenizer
tokenizer = ChatGLMTokenizer(vocab_file='./chatglm_tokenizer/tokenizer.model')
with open('./data/wikipedia-cn-20230720-filtered.json') as f:
data = json.load(f)
print(data[0:3])
data = data[0:3]
doc_ids = []
for line in tqdm(data):
text = line['completion']
text_id = tokenizer.encode(text, add_special_tokens=False)
text_id.append(tokenizer.special_tokens['<eos>'])
# doc_ids = doc_ids+text_id
doc_ids.append(doc_ids)
doc_ids = np.array(doc_ids, dtype=np.uint16)
with open('./test.bin', 'wb') as f:
f.write(doc_ids.tobytes())
其中,chatglm_tokenizer目录下的文件如下: