File size: 1,474 Bytes
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
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": 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'],
            }