使用ChatGLMTokenizer处理json格式数据

我下载了一些中文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目录下的文件如下:

相关推荐
Jonathan Star19 小时前
JSON-RPC 2.0 详解
qt·rpc·json
还算善良_1 天前
【XML生成】根据JSON格式化的报文,动态生成XML
xml·json
涛涛讲AI2 天前
被 JSON 格式折磨?1 个快捷键让 JSON-handle 秒启动,开发者必看!
json
韩仔搭建2 天前
Cocos Creator 项目配置 JSON 最佳实践
json
曼巴UE52 天前
JSON Reader
java·服务器·json
864记忆3 天前
Qt 对 JSON和XML文件的操作详解
xml·qt·json
x***01063 天前
使用 MySQL 从 JSON 字符串提取数据
mysql·oracle·json
咸甜适中4 天前
rust语言,将JSON中的所有值以字符串形式存储到sqlite数据库中(逐行注释)
数据库·rust·sqlite·json
Ustinian_3104 天前
【HTML】前端工具箱实现【文本处理/JSON工具/加解密/校验和/ASCII/时间戳转换等】【附完整源代码】
前端·html·json
消失的旧时光-19435 天前
Kotlinx.serialization 使用指南
android·kotlin·json