|
Download README.md from yuwei1289/LLMclass: direct link, hf CLI and curl.
- Browser
- Download file 1.2 kB
-
https://huggingface.co/datasets/yuwei1289/LLMclass/resolve/main/README.md
- Command line
-
hf download hf://datasets/yuwei1289/LLMclass/README.md
-
curl -L -o README.md https://huggingface.co/datasets/yuwei1289/LLMclass/resolve/main/README.md
1.2 kB
| import os | |
| import json | |
| import pandas as pd | |
| folder_path = "双语数据\史记\七十列传" | |
| def get_files(folder_path): | |
| subfolders = [f.path for f in os.scandir(folder_path) if f.is_dir()] | |
| print(subfolders) | |
| dataset = [] | |
| source_file = "source.txt" | |
| target_file = "target.txt" | |
| for x in subfolders: | |
| with open(os.path.join(x,source_file) , "r", encoding="utf-8") as f: | |
| source_content = f.read() | |
| with open(os.path.join(x,target_file), "r", encoding="utf-8") as f: | |
| target_content = f.read() | |
| source_content = source_content.split("\n") | |
| target_content = target_content.split("\n") | |
| for i in range(len(source_content)): | |
| dataset.append([source_content[i], target_content[i]]) | |
| return dataset | |
| dataset = get_files(folder_path) | |
| # add one column "instruction" with the content "请把古文翻译成现代汉语" to the dataset | |
| df = pd.DataFrame(dataset, columns=["source", "target"]) | |
| df["instruction"] = "请把现代汉语翻译成古文" | |
| df.rename(columns={"source": "output", "target": "input"}, inplace=True) | |
| print(len(df)) | |
| df.to_json("dataset.jsonl", orient="records", lines=True, force_ascii=False) |