File size: 5,905 Bytes
4e22ee4
 
 
 
 
57a6cb7
4e22ee4
57a6cb7
 
4e22ee4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57a6cb7
4e22ee4
 
 
 
 
 
57a6cb7
4e22ee4
 
57a6cb7
4e22ee4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
from pathlib import Path
from typing import Dict, List, Tuple

import datasets

from seacrowd.sea_datasets.x_fact.utils.x_fact_utils import \
    load_x_fact_dataset
from seacrowd.utils.configs import SEACrowdConfig
from seacrowd.utils.constants import Tasks

_CITATION = """\
@inproceedings{gupta2021xfact,
      title={{X-FACT: A New Benchmark Dataset for Multilingual Fact Checking}},
      author={Gupta, Ashim and Srikumar, Vivek},
      booktitle = "Proceedings of the 59th Annual Meeting of the Association for Computational Linguistics",
      month = jul,
      year = "2021",
      address = "Online",
      publisher = "Association for Computational Linguistics",
}
"""
_DATASETNAME = "x_fact"

_DESCRIPTION = """\
X-FACT: the largest publicly available multilingual dataset for factual verification of naturally existing realworld claims.
"""

_HOMEPAGE = "https://github.com/utahnlp/x-fact"

_LANGUAGES = [
    'ara', 'aze', 'ben', 'deu', 'spa', 
    'fas', 'fra', 'guj', 'hin', 'ind', 
    'ita', 'kat', 'mar', 'nor', 'nld', 
    'pan', 'pol', 'por', 'ron', 'rus',
    'sin', 'srp', 'sqi', 'tam', 'tur'
]
_LOCAL = False

_LICENSE = "MIT"

_URLS = {
    "train": "https://raw.githubusercontent.com/utahnlp/x-fact/main/data/x-fact-including-en/train.all.tsv",
    "validation": "https://raw.githubusercontent.com/utahnlp/x-fact/main/data/x-fact-including-en/dev.all.tsv",
    "test": {
        "in_domain": "https://raw.githubusercontent.com/utahnlp/x-fact/main/data/x-fact-including-en/test.all.tsv",
        "out_domain": "https://raw.githubusercontent.com/utahnlp/x-fact/main/data/x-fact-including-en/ood.tsv",
    },
}

_SUPPORTED_TASKS = [Tasks.FACT_CHECKING]

_SOURCE_VERSION = "1.0.0"

_SEACROWD_VERSION = "2024.06.20"


class XFact(datasets.GeneratorBasedBuilder):
    """X-FACT: the largest publicly available multilingual dataset for factual verification of naturally existing realworld claims."""

    SOURCE_VERSION = datasets.Version(_SOURCE_VERSION)
    SEACROWD_VERSION = datasets.Version(_SEACROWD_VERSION)

    BUILDER_CONFIGS = [
        SEACrowdConfig(
            name="x_fact_source",
            version=SOURCE_VERSION,
            description="x_fact source schema",
            schema="source",
            subset_id="x_fact",
        ),
    ]

    DEFAULT_CONFIG_NAME = "x_fact_source"

    def _info(self) -> datasets.DatasetInfo:

        if self.config.schema == "source":
            features = datasets.Features(
                {
                    "language": datasets.Value("string"),
                    "site": datasets.Value("string"),
                    "evidence_1": datasets.Value("string"),
                    "evidence_2": datasets.Value("string"),
                    "evidence_3": datasets.Value("string"),
                    "evidence_4": datasets.Value("string"),
                    "evidence_5": datasets.Value("string"),
                    "link_1": datasets.Value("string"),
                    "link_2": datasets.Value("string"),
                    "link_3": datasets.Value("string"),
                    "link_4": datasets.Value("string"),
                    "link_5": datasets.Value("string"),
                    "claimDate": datasets.Value("string"),
                    "reviewDate": datasets.Value("string"),
                    "claimant": datasets.Value("string"),
                    "claim": datasets.Value("string"),
                    "label": datasets.Value("string"),
                }
            )

        return datasets.DatasetInfo(
            description=_DESCRIPTION,
            features=features,
            homepage=_HOMEPAGE,
            license=_LICENSE,
            citation=_CITATION,
        )

    def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
        return [
            datasets.SplitGenerator(
                name=datasets.Split.TRAIN,
                gen_kwargs={
                    "filepath": _URLS["train"],
                    "split": "train",
                },
            ),
            datasets.SplitGenerator(
                name=datasets.Split.VALIDATION,
                gen_kwargs={
                    "filepath": _URLS["validation"],
                    "split": "dev",
                },
            ),
            datasets.SplitGenerator(
                name=datasets.splits.NamedSplit("TEST_IN_DOMAIN"),
                gen_kwargs={
                    "filepath": _URLS["test"]["in_domain"],
                    "split": "test_in_domain",
                },
            ),
            datasets.SplitGenerator(
                name=datasets.splits.NamedSplit("TEST_OUT_DOMAIN"),
                gen_kwargs={
                    "filepath": _URLS["test"]["out_domain"],
                    "split": "test_out_domain",
                },
            ),
        ]

    def _generate_examples(self, filepath: Path, split: str) -> Tuple[int, Dict]:

        df = load_x_fact_dataset(filepath)
        if self.config.schema == "source":
            for row in df.itertuples():
                entry = {
                    "language": row.language,
                    "site": row.site,
                    "evidence_1": row.evidence_1,
                    "evidence_2": row.evidence_2,
                    "evidence_3": row.evidence_3,
                    "evidence_4": row.evidence_4,
                    "evidence_5": row.evidence_5,
                    "link_1": row.link_1,
                    "link_2": row.link_2,
                    "link_3": row.link_3,
                    "link_4": row.link_4,
                    "link_5": row.link_5,
                    "claimDate": row.claimDate,
                    "reviewDate": row.reviewDate,
                    "claimant": row.claimant,
                    "claim": row.claim,
                    "label": row.label,
                }
                yield row.index, entry