Update parsinlu-multiple-choice.py
Browse files- parsinlu-multiple-choice.py +9 -15
parsinlu-multiple-choice.py
CHANGED
@@ -1,15 +1,8 @@
|
|
1 |
-
"""ParsiNLU Persian multiple choice task (Mostly copy-paste from https://huggingface.co/datasets/persiannlp/parsinlu_reading_comprehension/blob/main/parsinlu_reading_comprehension.py)"""
|
2 |
-
|
3 |
-
|
4 |
-
from __future__ import absolute_import, division, print_function
|
5 |
-
|
6 |
import json
|
7 |
-
|
8 |
import datasets
|
|
|
9 |
|
10 |
|
11 |
-
logger = datasets.logging.get_logger(__name__)
|
12 |
-
|
13 |
_CITATION = """\
|
14 |
@article{huggingface:dataset,
|
15 |
title = {ParsiNLU: A Suite of Language Understanding Challenges for Persian},
|
@@ -43,14 +36,13 @@ class ParsinluMultipleChoice(datasets.GeneratorBasedBuilder):
|
|
43 |
|
44 |
BUILDER_CONFIGS = [
|
45 |
datasets.BuilderConfig(
|
46 |
-
name="parsinlu-repo", version=VERSION, description="
|
47 |
-
),
|
48 |
-
]
|
49 |
|
50 |
def _info(self):
|
51 |
features = datasets.Features(
|
52 |
{
|
53 |
-
"answer": datasets.Value("
|
54 |
"candidates": datasets.features.Sequence(feature=datasets.Value(dtype='string', id=None), length=-1),
|
55 |
"category": datasets.Value("string"),
|
56 |
"question": datasets.Value("string"),
|
@@ -75,6 +67,7 @@ class ParsinluMultipleChoice(datasets.GeneratorBasedBuilder):
|
|
75 |
citation=_CITATION,
|
76 |
)
|
77 |
|
|
|
78 |
def _split_generators(self, dl_manager):
|
79 |
data_dir = dl_manager.download_and_extract(_URLs)
|
80 |
return [
|
@@ -89,7 +82,9 @@ class ParsinluMultipleChoice(datasets.GeneratorBasedBuilder):
|
|
89 |
datasets.SplitGenerator(
|
90 |
name=datasets.Split.TEST,
|
91 |
# These kwargs will be passed to _generate_examples
|
92 |
-
gen_kwargs={
|
|
|
|
|
93 |
),
|
94 |
datasets.SplitGenerator(
|
95 |
name=datasets.Split.VALIDATION,
|
@@ -101,9 +96,8 @@ class ParsinluMultipleChoice(datasets.GeneratorBasedBuilder):
|
|
101 |
),
|
102 |
]
|
103 |
|
104 |
-
def _generate_examples(self, filepath, split):
|
105 |
-
logger.info("generating examples from = %s", filepath)
|
106 |
|
|
|
107 |
def get_answer_index(passage, answer):
|
108 |
return passage.index(answer) if answer in passage else -1
|
109 |
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import json
|
|
|
2 |
import datasets
|
3 |
+
import os
|
4 |
|
5 |
|
|
|
|
|
6 |
_CITATION = """\
|
7 |
@article{huggingface:dataset,
|
8 |
title = {ParsiNLU: A Suite of Language Understanding Challenges for Persian},
|
|
|
36 |
|
37 |
BUILDER_CONFIGS = [
|
38 |
datasets.BuilderConfig(
|
39 |
+
name="parsinlu-repo", version=VERSION, description="Here the task is to pick a correct answer among 3-5 given candidate answers"
|
40 |
+
),]
|
|
|
41 |
|
42 |
def _info(self):
|
43 |
features = datasets.Features(
|
44 |
{
|
45 |
+
"answer": datasets.Value("string"),
|
46 |
"candidates": datasets.features.Sequence(feature=datasets.Value(dtype='string', id=None), length=-1),
|
47 |
"category": datasets.Value("string"),
|
48 |
"question": datasets.Value("string"),
|
|
|
67 |
citation=_CITATION,
|
68 |
)
|
69 |
|
70 |
+
|
71 |
def _split_generators(self, dl_manager):
|
72 |
data_dir = dl_manager.download_and_extract(_URLs)
|
73 |
return [
|
|
|
82 |
datasets.SplitGenerator(
|
83 |
name=datasets.Split.TEST,
|
84 |
# These kwargs will be passed to _generate_examples
|
85 |
+
gen_kwargs={
|
86 |
+
"filepath": data_dir["test"],
|
87 |
+
"split": "test"},
|
88 |
),
|
89 |
datasets.SplitGenerator(
|
90 |
name=datasets.Split.VALIDATION,
|
|
|
96 |
),
|
97 |
]
|
98 |
|
|
|
|
|
99 |
|
100 |
+
def _generate_examples(self, filepath, split):
|
101 |
def get_answer_index(passage, answer):
|
102 |
return passage.index(answer) if answer in passage else -1
|
103 |
|