File size: 1,669 Bytes
74c6a73 cd33f7b 74c6a73 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
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):
# Path to your CSV file
csv_path = poems-qa.csv"
return [
SplitGenerator(
name=Split.TRAIN,
gen_kwargs={
"filepath": poems-qa-train.csv
}
),
SplitGenerator(
name=Split.VALIDATION,
gen_kwargs={
"filepath": poems-qa-validation.csv
}
),
]
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'],
}
|