jupyterjazz
commited on
Commit
•
5ab80af
1
Parent(s):
96fb00b
Upload 2 files
Browse files- .gitattributes +1 -0
- test.csv +3 -0
- xpqa.py +62 -0
.gitattributes
CHANGED
@@ -53,3 +53,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
53 |
*.jpg filter=lfs diff=lfs merge=lfs -text
|
54 |
*.jpeg filter=lfs diff=lfs merge=lfs -text
|
55 |
*.webp filter=lfs diff=lfs merge=lfs -text
|
|
|
|
53 |
*.jpg filter=lfs diff=lfs merge=lfs -text
|
54 |
*.jpeg filter=lfs diff=lfs merge=lfs -text
|
55 |
*.webp filter=lfs diff=lfs merge=lfs -text
|
56 |
+
test.csv filter=lfs diff=lfs merge=lfs -text
|
test.csv
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:1647f87a48a5537a9449af065d9eed41a42ab6fbd6203c7cf964374af8f5cab4
|
3 |
+
size 89978573
|
xpqa.py
ADDED
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import csv
|
2 |
+
from typing import List
|
3 |
+
|
4 |
+
import datasets
|
5 |
+
|
6 |
+
LANGUAGES = ["ar", "de", "es", "fr", "hi", "it", "ja", "ko", "pl", "pt", "ta", "zh"]
|
7 |
+
DATA_PATH = "test.csv"
|
8 |
+
|
9 |
+
|
10 |
+
class XPQAConfig(datasets.BuilderConfig):
|
11 |
+
def __init__(self, language, **kwargs):
|
12 |
+
super().__init__(**kwargs)
|
13 |
+
self.language = language
|
14 |
+
|
15 |
+
|
16 |
+
class XPQA(datasets.GeneratorBasedBuilder):
|
17 |
+
BUILDER_CONFIG_CLASS = XPQAConfig
|
18 |
+
|
19 |
+
BUILDER_CONFIGS = [
|
20 |
+
XPQAConfig(name=language, language=language) for language in LANGUAGES
|
21 |
+
]
|
22 |
+
|
23 |
+
def _info(self):
|
24 |
+
return datasets.DatasetInfo(
|
25 |
+
description="xPQA is a large-scale annotated cross-lingual Product QA dataset.",
|
26 |
+
features=datasets.Features(
|
27 |
+
{
|
28 |
+
"id": datasets.Value("string"),
|
29 |
+
"question": datasets.Value("string"),
|
30 |
+
"answer": datasets.Value("string"),
|
31 |
+
}
|
32 |
+
),
|
33 |
+
homepage="https://github.com/amazon-science/contextual-product-qa/tree/main?tab=readme-ov-file#xpqa",
|
34 |
+
citation="https://arxiv.org/abs/2305.09249",
|
35 |
+
)
|
36 |
+
|
37 |
+
def _split_generators(
|
38 |
+
self, dl_manager: datasets.DownloadManager
|
39 |
+
) -> List[datasets.SplitGenerator]:
|
40 |
+
return [
|
41 |
+
datasets.SplitGenerator(
|
42 |
+
name=datasets.Split.TEST, gen_kwargs={"filepath": DATA_PATH}
|
43 |
+
),
|
44 |
+
]
|
45 |
+
|
46 |
+
def _generate_examples(self, filepath):
|
47 |
+
id_ = 0
|
48 |
+
with open(filepath, newline="") as csvfile:
|
49 |
+
csvreader = csv.reader(csvfile, delimiter=",")
|
50 |
+
header = next(csvreader)
|
51 |
+
lang_pos = header.index("lang")
|
52 |
+
answer_pos = header.index("answer")
|
53 |
+
question_pos = header.index("question")
|
54 |
+
label_pos = header.index("label")
|
55 |
+
for row in csvreader:
|
56 |
+
if row[lang_pos] == self.config.language and row[label_pos] == "2":
|
57 |
+
answer = row[answer_pos]
|
58 |
+
question = row[question_pos]
|
59 |
+
if not answer or not question:
|
60 |
+
continue
|
61 |
+
yield id_, {"id": id_, "question": question, "answer": answer}
|
62 |
+
id_ += 1
|