File size: 4,458 Bytes
cb8774b 0a87813 cb8774b 10a171d cb8774b 6f26617 cb8774b 6f26617 cb8774b d6791d7 cb8774b d6791d7 cb8774b a7ab105 cb8774b 6f26617 a04f566 9289956 cb8774b 10a171d cb8774b 10a171d cb8774b 10a171d cb8774b 6f26617 cb8774b 6f26617 a04f566 d451424 9289956 cb8774b |
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 |
# coding=utf-8
# Copyright 2020 HuggingFace Datasets Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Lint as: python3
# ok
import os
import json
import datasets
_DESCRIPTION = """MQA is a multilingual corpus of questions and answers parsed from the Common Crawl. Questions are divided between Frequently Asked Questions (FAQ) pages and Community Question Answering (CQA) pages."""
_HOMEPAGE_URL = "https://huggingface.co/datasets/clips/mqa"
_CITATION = """
@misc{debruyn2021mfaq,
title={MFAQ: a Multilingual FAQ Dataset},
author={Maxime {De Bruyn} and Ehsan Lotfi and Jeska Buhmann and Walter Daelemans},
year={2021},
booktitle={MRQA@EMNLP2021},
}
"""
_VERSION = "0.4"
_BASE_NAME = ""
_TRAIN_BASE_URL = "data/train/data.{}.json"
_VALID_BASE_URL = "data/valid/data.{}.json"
_LANGUAGES = [
"en", "de", "es", "fr",
"ru", "ja", "it", "zh", "pt",
"nl", "tr", "pl", "vi", "ar",
"id", "uk", "ro", "no", "th",
"sv", "el", "fi", "he", "da",
"cs", "ko", "fa", "hi", "hu",
"sk", "lt", "et", "hr", "is",
"lv", "ms", "bg", "sr", "ca"
]
class MFAQLightConfig(datasets.BuilderConfig):
def __init__(self, *args, language="en", negatives=True, **kwargs):
super().__init__(
*args,
name=f"{language}",
**kwargs,
)
self.language = language
self.negatives = negatives
class MFAQLight(datasets.GeneratorBasedBuilder):
BUILDER_CONFIGS = []
for language in _LANGUAGES:
BUILDER_CONFIGS.append(MFAQLightConfig(language=language))
BUILDER_CONFIGS.append(MFAQLightConfig(language="all"))
BUILDER_CONFIG_CLASS = MFAQLightConfig
def _info(self):
features = {
"question": datasets.Value("string"),
"answer": datasets.Value("string"),
"domain": datasets.Value("string"),
"domain_index": datasets.Value("int32"),
"id": datasets.Value("string"),
"negative": datasets.Value("string"),
"candidates": [datasets.Value("string")],
"margin_score": datasets.Value("float32")
}
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=datasets.Features(features),
supervised_keys=None,
homepage=_HOMEPAGE_URL,
citation=_CITATION,
)
def _split_generators(self, dl_manager):
train_filenames = []
valid_filenames = []
languages = _LANGUAGES if self.config.language == "all" else [self.config.language]
for language in languages:
path = dl_manager.download_and_extract(_TRAIN_BASE_URL.format(language))
train_filenames.append(path)
path = dl_manager.download_and_extract(_VALID_BASE_URL.format(language))
valid_filenames.append(path)
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={"filenames": train_filenames},
),
datasets.SplitGenerator(
name=datasets.Split.VALIDATION,
gen_kwargs={"filenames": valid_filenames},
)
]
def _generate_examples(self, filenames):
for filename in filenames:
with open(filename, "r") as f:
for i, line in enumerate(f):
question = json.loads(line)
yield question["id"], {
"question": question["question"],
"answer": question["answer"],
"domain": question["domain"],
"domain_index": question["domain_index"],
"id": question["id"],
"negative": question.get("negative", ""),
"candidates": question.get("candidates", []),
"margin_score": question.get("margin_score", 0)
}
|