Skip to content

对得到的tsv文件语料进一步处理,可直接用于chatgpt2模型的训练 #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions clean_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
class Config():
# 读取文件路径
filename_in = "clean_chat_corpus/chatterbot.tsv"

# 保存文件路径
filesname_out = "clean_data/train_chatterbot.txt"


def load_data():
config = Config()
print(config.filename_in)
# 打开文件
with open(config.filename_in, "rb") as f:
data = f.read().decode("utf-8")
return data


def clean(data):
data1 = []
text = ''
for i in range(0,len(data)):
if data[i] != '\t':
text=text+data[i]
if data[i] == '\n':
text=text+'\n'
else:

text=text+'\n'
data1.append(text)
text=''
return data1


def save_file(data):
config = Config()
f=open(config.filesname_out,"w",encoding='utf-8')
for line in data:
f.write(line)
f.close()
print("数据已保存")

def run():
print("读取文件")
data=load_data()
print("整理数据")
data1=clean(data)
save_file(data1)

if __name__ == '__main__':
run()
17 changes: 17 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,23 @@

**使用该项目,即可对所有的聊天语料进行一次性的处理和统一下载,不需要到处自己去搜集下载和分别处理各种不同的格式。**

# 新增
*clean_data.py*
根据处理方法操作完后,将会得到 *clean_chat_corpus*文件夹
修改clean_data.py下的config,更改读取数据的路径以及输出数据的路径。
```
class Config():
# 读取文件路径
filename_in = " "

# 保存文件路径
filesname_out = " "

```

**处理得到的数据可直接用于GPT2-chitchat模型的训练**
详见:GPT2-chitchat|https://github.com/yangjianxin1/GPT2-chitchat

# 环境
python3
# 处理过程
Expand Down