|
import pandas as pd |
|
from datasets import DatasetBuilder, SplitGenerator, Split, Features, Value |
|
|
|
class PersianPoetry(DatasetBuilder): |
|
VERSION = "1.0.0" |
|
|
|
def _info(self): |
|
return datasets.DatasetInfo( |
|
description="This dataset contains a rich collection of Persian poems along with metadata about the poets and the verses.", |
|
features=Features({ |
|
'context': Value('string'), |
|
'question': Value('string'), |
|
'answer': Value('string'), |
|
'answer_start': Value('int32'), |
|
}), |
|
homepage="https://github.com/ganjoor/desktop/releases/tag/v2.81", |
|
citation="""Persian Poetry Dataset. Collected by Kakooch from the Ganjoor Project. Available at: https://huggingface.co/datasets/persian_poetry""", |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
|
|
csv_path = poems-qa.csv" |
|
return [ |
|
SplitGenerator( |
|
name=Split.TRAIN, |
|
gen_kwargs={ |
|
"filepath": csv_path |
|
} |
|
), |
|
] |
|
|
|
def _generate_examples(self, filepath): |
|
df = pd.read_csv(filepath) |
|
for idx, row in df.iterrows(): |
|
yield idx, { |
|
'context': row['context'], |
|
'question': row['question'], |
|
'answer': row['answer'], |
|
'answer_start': row['answer_start'], |
|
} |
|
|