File size: 2,170 Bytes
4448461
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2edba4d
4448461
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2edba4d
4448461
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
"""TODO(Indicxparaphrase): Add a description here."""


import json
import pandas as pd
import datasets


_HOMEPAGE = ""

_CITATION = """\

"""

_DESCRIPTION = """\

"""

_LANG = ["as", "hi", "kn", "ml", "mr", "pa", "te"]
_URL = "https://huggingface.co./datasets/ai4bharat/IndicXParaphrase/resolve/main/data/{language}.tsv"
_VERSION = datasets.Version("1.0.0", "First version of Indicxparaphrase")


class Indicxparaphrase(datasets.GeneratorBasedBuilder):
    """TODO(Indicxparaphrase): Short description of my dataset."""
    BUILDER_CONFIGS = [
        datasets.BuilderConfig(
            name=f"{lang}",
            description=f"Cross-lingual paraphrase dataset for language {lang}",
            version=_VERSION,
        )
        for lang in _LANG
    ]

    def _info(self):
        return datasets.DatasetInfo(
            description=_DESCRIPTION + self.config.description,
            features=datasets.Features(
                {
                    "english": datasets.Value("string"),
                    "translation": datasets.Value("string"),
                    "paraphrase": datasets.Value("string"),
                    "non-paraphrase": datasets.Value("string"),
                }
            ),
            homepage=_HOMEPAGE,
            citation=_CITATION,
        )

    def _split_generators(self, dl_manager):
        """Returns SplitGenerators."""
        language = self.config.name
        splits = {datasets.Split.TEST: "test"}
        data_urls = {
            split: _URL.format(language=language) for split in splits
        }
        dl_paths = dl_manager.download(data_urls)
        return [
            datasets.SplitGenerator(
                name=split,
                gen_kwargs={"filepath": dl_paths[split]},
            )
            for split in splits
        ]

    def _generate_examples(self, filepath):
        """Yields examples."""
        df = pd.read_csv(filepath, sep="\t", header=None)
        for idx, row in df.iterrows():
            yield idx, {
                "english": row[0],
                "translation": row[1],
                "paraphrase": row[2],
                "non-paraphrase": row[3],
            }