prepare_data.py 770 Bytes
Newer Older
Rayyyyy's avatar
Rayyyyy committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import fire
import os
from datasets import load_dataset

DATASET = "rahular/varta"

def main(split="validation", lang="hi", docs_to_sample=10_000, save_path="data"):
    dataset = load_dataset(DATASET, split=split, streaming=True)
    os.makedirs(save_path, exist_ok=True)
    with open(os.path.join(save_path, f"{lang}.txt"), "w") as f:
        count = 0
        for idx, d in enumerate(dataset):
            if idx % 10_000 == 0:
                print(f"Searched {idx} documents for {lang} documents. Found {count} documents.")
            if count >= docs_to_sample:
                break
            if d["langCode"] == lang:
                f.write(d["headline"] + "\n" + d["text"] + "\n")
                count += 1


if __name__ == "__main__":
    fire.Fire(main)