File size: 1,064 Bytes
e2ad6cc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import os
from datasets import load_dataset

BASE_DIR = "/home/cloud/StyleTTS2-fine-tuning"
OUTPUT_DIR = os.path.join(BASE_DIR, "Data")
OUTPUT_FILE = os.path.join(OUTPUT_DIR, "OOD.txt")
HF_DATASET_ID = "agentlans/high-quality-english-sentences"

os.makedirs(OUTPUT_DIR, exist_ok=True)

def download_and_save_text():
    print(f"Downloading first 10,000 lines from {HF_DATASET_ID}...")
    ds = load_dataset(HF_DATASET_ID, split="train[8000:18000]")

    text_column = "text"
    if "sentence" in ds.column_names:
        text_column = "sentence"
    elif "content" in ds.column_names:
        text_column = "content"
    
    print(f"Extracting to {OUTPUT_FILE}...")
    
    with open(OUTPUT_FILE, "w", encoding="utf-8") as f:
        for row in ds:
            line = row[text_column]
            if line and isinstance(line, str):
                clean_line = line.strip()
                if clean_line:
                    f.write(clean_line + "\n")

    print(f"Saved {len(ds)} lines to {OUTPUT_FILE}")

if __name__ == "__main__":
    download_and_save_text()