|
|
|
|
|
import argparse |
|
import json |
|
from pathlib import Path |
|
|
|
import pandas as pd |
|
from tqdm import tqdm |
|
|
|
from project_settings import project_path |
|
|
|
|
|
def get_args(): |
|
parser = argparse.ArgumentParser() |
|
|
|
parser.add_argument( |
|
"--data_dir", |
|
default=(project_path / "original_data/weibo-400w").as_posix(), |
|
type=str |
|
) |
|
parser.add_argument( |
|
"--output_file", |
|
default=(project_path / "data/weibo.jsonl"), |
|
type=str |
|
) |
|
|
|
args = parser.parse_args() |
|
return args |
|
|
|
|
|
def main(): |
|
args = get_args() |
|
|
|
data_dir = Path(args.data_dir) |
|
|
|
questions = list() |
|
with open(data_dir / "stc_weibo_train_post", "r", encoding="utf-8") as f: |
|
for row in f: |
|
row = str(row).strip() |
|
row = "".join(row.split()) |
|
questions.append(row) |
|
|
|
answers = list() |
|
with open(data_dir / "stc_weibo_train_response.part", "r", encoding="utf-8") as f: |
|
for row in f: |
|
row = str(row).strip() |
|
row = "".join(row.split()) |
|
answers.append(row) |
|
|
|
if len(questions) != len(answers): |
|
raise AssertionError |
|
|
|
with open(args.output_file, "w", encoding="utf-8") as f: |
|
for question, answer in tqdm(zip(questions, answers)): |
|
row = { |
|
"conversation": [ |
|
{"role": "human", "message": question}, |
|
{"role": "assistant", "message": answer}, |
|
], |
|
"category": None, |
|
"data_source": "weibo", |
|
} |
|
row = json.dumps(row, ensure_ascii=False) |
|
f.write("{}\n".format(row)) |
|
return |
|
|
|
|
|
if __name__ == '__main__': |
|
main() |
|
|