Allow loading of multiple languages
Browse files- xmarket_ml.py +11 -10
xmarket_ml.py
CHANGED
@@ -15,7 +15,7 @@ https://xmrec.github.io/
|
|
15 |
"""
|
16 |
|
17 |
_HOMEPAGE_URL = 'https://xmrec.github.io/'
|
18 |
-
_LANGUAGES = {'es': '
|
19 |
_VERSION = '1.0.0'
|
20 |
|
21 |
|
@@ -40,7 +40,7 @@ URLS = [
|
|
40 |
|
41 |
|
42 |
class XMarketMLConfig(datasets.BuilderConfig):
|
43 |
-
"""BuilderConfig for
|
44 |
|
45 |
def __init__(self, languages=None, **kwargs):
|
46 |
super(XMarketMLConfig, self).__init__(
|
@@ -50,15 +50,15 @@ class XMarketMLConfig(datasets.BuilderConfig):
|
|
50 |
|
51 |
|
52 |
class XMarketML(datasets.GeneratorBasedBuilder):
|
53 |
-
"""The
|
54 |
|
55 |
BUILDER_CONFIGS = [
|
56 |
XMarketMLConfig(
|
57 |
-
name=name,
|
58 |
description=f'{name.title()} of the multilingual XMarket dataset.',
|
59 |
languages=None,
|
60 |
)
|
61 |
-
for name in ['corpus', 'queries', 'qrels']
|
62 |
]
|
63 |
|
64 |
BUILDER_CONFIG_CLASS = XMarketMLConfig
|
@@ -84,8 +84,9 @@ class XMarketML(datasets.GeneratorBasedBuilder):
|
|
84 |
def _split_generators(self, dl_manager: datasets.DownloadManager):
|
85 |
json_files = []
|
86 |
for lang in self.config.languages:
|
|
|
87 |
for url in URLS:
|
88 |
-
json_files.append(dl_manager.download(url % (
|
89 |
return [
|
90 |
datasets.SplitGenerator(
|
91 |
name=datasets.Split.TEST,
|
@@ -129,17 +130,17 @@ class XMarketML(datasets.GeneratorBasedBuilder):
|
|
129 |
'queries': queries,
|
130 |
'qrels': qrels,
|
131 |
}
|
132 |
-
if self.config.name
|
133 |
for line in self._data['corpus']:
|
134 |
yield line['_id'], line
|
135 |
-
elif self.config.name
|
136 |
for query, qid in queries.items():
|
137 |
yield qid, {
|
138 |
"_id": qid,
|
139 |
"title": '',
|
140 |
"text": query,
|
141 |
}
|
142 |
-
elif self.config.name
|
143 |
for qid, dids in qrels.items():
|
144 |
yield qid, {
|
145 |
"_id": qid,
|
@@ -147,4 +148,4 @@ class XMarketML(datasets.GeneratorBasedBuilder):
|
|
147 |
"text": ' '.join(dids),
|
148 |
}
|
149 |
else:
|
150 |
-
raise ValueError(f'Unknown config name: {self.config.name}')
|
|
|
15 |
"""
|
16 |
|
17 |
_HOMEPAGE_URL = 'https://xmrec.github.io/'
|
18 |
+
_LANGUAGES = {'es': 'es', 'de': 'de', 'en': 'us'}
|
19 |
_VERSION = '1.0.0'
|
20 |
|
21 |
|
|
|
40 |
|
41 |
|
42 |
class XMarketMLConfig(datasets.BuilderConfig):
|
43 |
+
"""BuilderConfig for XMarket."""
|
44 |
|
45 |
def __init__(self, languages=None, **kwargs):
|
46 |
super(XMarketMLConfig, self).__init__(
|
|
|
50 |
|
51 |
|
52 |
class XMarketML(datasets.GeneratorBasedBuilder):
|
53 |
+
"""The XMarket category to product retrieval dataset"""
|
54 |
|
55 |
BUILDER_CONFIGS = [
|
56 |
XMarketMLConfig(
|
57 |
+
name=f"{name}-{lang}",
|
58 |
description=f'{name.title()} of the multilingual XMarket dataset.',
|
59 |
languages=None,
|
60 |
)
|
61 |
+
for name in ['corpus', 'queries', 'qrels'] for lang in _LANGUAGES
|
62 |
]
|
63 |
|
64 |
BUILDER_CONFIG_CLASS = XMarketMLConfig
|
|
|
84 |
def _split_generators(self, dl_manager: datasets.DownloadManager):
|
85 |
json_files = []
|
86 |
for lang in self.config.languages:
|
87 |
+
url_lang = _LANGUAGES[lang]
|
88 |
for url in URLS:
|
89 |
+
json_files.append(dl_manager.download(url % (url_lang, url_lang)))
|
90 |
return [
|
91 |
datasets.SplitGenerator(
|
92 |
name=datasets.Split.TEST,
|
|
|
130 |
'queries': queries,
|
131 |
'qrels': qrels,
|
132 |
}
|
133 |
+
if self.config.name.startswith('corpus'):
|
134 |
for line in self._data['corpus']:
|
135 |
yield line['_id'], line
|
136 |
+
elif self.config.name.startswith('queries'):
|
137 |
for query, qid in queries.items():
|
138 |
yield qid, {
|
139 |
"_id": qid,
|
140 |
"title": '',
|
141 |
"text": query,
|
142 |
}
|
143 |
+
elif self.config.name.startswith('qrels'):
|
144 |
for qid, dids in qrels.items():
|
145 |
yield qid, {
|
146 |
"_id": qid,
|
|
|
148 |
"text": ' '.join(dids),
|
149 |
}
|
150 |
else:
|
151 |
+
raise ValueError(f'Unknown config name: {self.config.name}')
|