metadata
license: apache-2.0
task_categories:
- text-generation
language:
- zh
tags:
- llm
- pretrain
size_categories:
- 1B<n<10B
简介
搜集网络上的网文小说,清洗,分割后,用于训练大语言模型,共计9000本左右,大约5B左右token。
使用
格式说明
采用jsonl
格式存储,分为三个字段:
title
:小说名称chapter
:章节text
:正文内容
示例:
{"title": "斗破苍穹", "chapter": " 第一章 陨落的天才", "text": "“斗之力,三段!”\n望着测验魔石碑上面闪亮得甚至有些刺眼的五个大字,少年面无表情,唇角有着一抹自嘲,紧握的手掌,因为大力,而导致略微尖锐的指甲深深的刺进了掌心之中,带来一阵阵钻心的疼痛……\n“萧炎,斗之力,三段!级别:低级!”测验魔石碑之旁,一位中年男子,看了一眼碑上所显示出来的信息,语气漠然的将之公布了出来……\n"}
示例代码
def process_webnovel(input_dir, tokenizer):
for subdir, dirs, files in os.walk(input_dir):
all_tokens = []
for idx, file in enumerate(files):
# 只处理txt文件
if file.endswith('.jsonl'):
# 获取当前文件的绝对路径
file_path = os.path.join(subdir, file)
# 读取jsonl文件
with open(file_path, 'r', encoding='utf-8') as infile:
lines = infile.readlines()
for line in lines:
json_obj = json.loads(line) # 解析json字符串为python对象
text = json_obj['text']
tokens = tokenizer.encode(text, add_special_tokens=False)
tokens.append(tokenizer.special_tokens['<eos>'])
if len(tokens) > 5:
all_tokens += tokens
arr = np.array(all_tokens, dtype = np.uint16)
with open('./data/webnovel_{idx}.bin','wb') as f:
f.write(arr.tobytes())