Created
October 21, 2021 10:12
-
-
Save AeroXi/53be4fe5bde3857c0c941c09dc51ea12 to your computer and use it in GitHub Desktop.
将txt转换为GPT2-Chinese的训练格式
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
dic = {} | |
with open("train.txt", "r", encoding="utf8") as f: | |
merge_line = "" | |
for line in f: | |
line = line.strip() | |
merge_line += line | |
if len(merge_line) > 500: | |
dic[merge_line] = 1 | |
merge_line = "" | |
with open("train.json", "w", encoding="utf8") as f: | |
json.dump(dic, f, ensure_ascii=False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment