Datasets:

Modalities:
Text
Formats:
text
Languages:
English
Size:
< 1K
ArXiv:
Libraries:
Datasets
License:
EchoShao8899 commited on
Commit
a336d7e
·
verified ·
1 Parent(s): ca18b9c

Create dataset.py

Browse files
Files changed (1) hide show
  1. dataset.py +38 -0
dataset.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from datasets import Dataset, DatasetInfo, load_dataset_builder, GeneratorBasedBuilder
2
+
3
+ class FreshWikiDataset(GeneratorBasedBuilder):
4
+ def _info(self):
5
+ return DatasetInfo(
6
+ description="The FreshWiki Dataset is a collection of high-quality Wikipedia articles focusing on the most-edited pages from February 2022 to September 2023.",
7
+ features=datasets.Features({
8
+ "json_file": datasets.Value("string"),
9
+ "txt_file": datasets.Value("string"),
10
+ "topics": datasets.Sequence(datasets.Value("string")),
11
+ }),
12
+ )
13
+
14
+ def _split_generators(self, dl_manager):
15
+ # Access the folder where all files are stored
16
+ data_dir = dl_manager.download_and_extract("https://huggingface.co/datasets/EchoShao8899/FreshWiki")
17
+ return [
18
+ datasets.SplitGenerator(
19
+ name=datasets.Split.TRAIN,
20
+ gen_kwargs={
21
+ "json_files": os.path.join(data_dir, "json"),
22
+ "txt_files": os.path.join(data_dir, "txt"),
23
+ "topic_list_csv": os.path.join(data_dir, "topic_list.csv"),
24
+ },
25
+ ),
26
+ ]
27
+
28
+ def _generate_examples(self, json_files, txt_files, topic_list_csv):
29
+ # Read the CSV file, and pair it with JSON and TXT files
30
+ with open(topic_list_csv, "r") as csv_file:
31
+ reader = csv.DictReader(csv_file)
32
+ for idx, row in enumerate(reader):
33
+ topic_name = row['topic'].replace(' ', '_').replace('/', '_')
34
+ yield idx, {
35
+ "json_file": open(os.path.join(json_files, f'{topic_name}.json'), "r").read(),
36
+ "txt_file": open(os.path.join(txt_files, f'{topic_name}.txt'), "r").read(),
37
+ "topic": row['topic'],
38
+ }