MinuriR commited on
Commit
3eb311f
·
1 Parent(s): 6be348c

Add data_loader

Browse files
Files changed (1) hide show
  1. data_loader.py +29 -0
data_loader.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from datasets import DatasetInfo, GeneratorBasedBuilder, SplitGenerator, Split
2
+ import datasets
3
+
4
+ class SinhalaPerplexityDataset(datasets.GeneratorBasedBuilder):
5
+ def _info(self):
6
+ return DatasetInfo(
7
+ features=datasets.Features({
8
+ "sinhala_unicode": datasets.Value("string"),
9
+ "sinhala_romanized": datasets.Value("string"),
10
+ }),
11
+ description="Sinhala Perplexity Test Dataset with Unicode and Romanized Sinhala sentences.",
12
+ supervised_keys=None,
13
+ )
14
+
15
+ def _split_generators(self, dl_manager):
16
+ data_path = dl_manager.download_and_extract("data/sinhala.csv")
17
+ return [
18
+ SplitGenerator(name="data", gen_kwargs={"filepath": data_path}),
19
+ ]
20
+
21
+ def _generate_examples(self, filepath):
22
+ import csv
23
+ with open(filepath, encoding="utf-8") as f:
24
+ reader = csv.DictReader(f)
25
+ for idx, row in enumerate(reader):
26
+ yield idx, {
27
+ "sinhala_unicode": row["sinhala_unicode"],
28
+ "sinhala_romanized": row["sinhala_romanized"],
29
+ }