|
|
from datasets import DatasetInfo, GeneratorBasedBuilder, SplitGenerator, Split, Value |
|
|
|
|
|
class SinhalaPerplexity(GeneratorBasedBuilder): |
|
|
def _info(self): |
|
|
return DatasetInfo( |
|
|
description="Sinhala Unicode and Romanized sentence pairs for perplexity evaluation.", |
|
|
features={ |
|
|
"sinhala_unicode": Value("string"), |
|
|
"sinhala_romanized": Value("string"), |
|
|
}, |
|
|
supervised_keys=None, |
|
|
) |
|
|
|
|
|
def _split_generators(self, dl_manager): |
|
|
data_path = dl_manager.download("data/diverse_sentences.csv") |
|
|
return [ |
|
|
SplitGenerator( |
|
|
name=Split("data"), |
|
|
gen_kwargs={"filepath": data_path}, |
|
|
) |
|
|
] |
|
|
|
|
|
def _generate_examples(self, filepath): |
|
|
import csv |
|
|
with open(filepath, encoding="utf-8") as f: |
|
|
reader = csv.DictReader(f) |
|
|
for idx, row in enumerate(reader): |
|
|
yield idx, { |
|
|
"sinhala_unicode": row["unicode_sentence"], |
|
|
"sinhala_romanized": row["romanized_sentence"], |
|
|
} |
|
|
|