代码拉取完成,页面将自动刷新
同步操作将从 zlipper/GPT2-chitchat 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
import argparse
from os.path import join
import numpy as np
from collections import Counter
import matplotlib.pyplot as plt
from matplotlib.pyplot import MultipleLocator
def generate_subset():
"""
用于生成训练子集
:return:
"""
parser = argparse.ArgumentParser()
parser.add_argument('--raw_data_path', default='data/train.txt', type=str, required=False, help='原始训练语料')
parser.add_argument('--subset_size', default=500000, type=int, required=False, help='要获取的对话数据子集的规模')
parser.add_argument('--subset_data_path', default='data', type=str, required=False,
help='数据子集文件路径,指定文件的父目录')
args = parser.parse_args()
with open(args.raw_data_path, "r", encoding="utf8") as f:
data = f.read()
dialogues = data.split("\n\n")
subset_size = min(len(dialogues), args.subset_size)
with open(join(args.subset_data_path, "train_{}w.txt".format(int(subset_size / 10000))), "w", encoding="utf8") as f:
print("generating subset,please wait a few seconds ")
for dialogue_index, dialogue in enumerate(dialogues):
if dialogue_index >= subset_size:
break
for utterance in dialogue.split("\n"):
f.writelines(utterance + "\n")
f.writelines("\n")
def compute_dialogue_length():
"""
查看聊天语料中的dialogue的长度分布
:return:
"""
parser = argparse.ArgumentParser()
parser.add_argument('--raw_data_path', default='data/train.txt', type=str, required=False, help='原始训练语料')
args = parser.parse_args()
with open(args.raw_data_path, "r", encoding="utf8") as f:
data = f.read()
dialogues = data.split("\n\n")
# 统计各个dialogue的长度
dialogues_lengths = [len(dialogue.replace("\n", "")) for dialogue in dialogues]
counter = Counter(dialogues_lengths) # {label:sum(label)}
dialogue_length_arr = list(counter)
num_arr = [counter[element] for element in list(counter)]
print(counter[300])
x_major_locator = MultipleLocator(100) # MultipleLocator用于设置刻度间隔
# y_major_locator = MultipleLocator(20000)
ax = plt.gca() # ax为两条坐标轴的实例
ax.xaxis.set_major_locator(x_major_locator) # 把x轴的主刻度设置为10的倍数
# ax.yaxis.set_major_locator(y_major_locator)
plt.xlabel('dialogue length')
plt.ylabel('number of dialogue')
# plt.plot(dialogue_length_arr, num_arr, c='green')
plt.scatter(dialogue_length_arr, num_arr)
plt.show()
if __name__ == '__main__':
compute_dialogue_length()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。