Datasets:
Tasks:
Question Answering
Languages:
Malay (individual language)
ArXiv:
Tags:
question-answering
License:
Upload tmad_malay_corpus.py with huggingface_hub
Browse files- tmad_malay_corpus.py +140 -0
tmad_malay_corpus.py
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# coding=utf-8
|
| 2 |
+
# Copyright 2022 The HuggingFace Datasets Authors and the current dataset script contributor.
|
| 3 |
+
#
|
| 4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
# you may not use this file except in compliance with the License.
|
| 6 |
+
# You may obtain a copy of the License at
|
| 7 |
+
#
|
| 8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
#
|
| 10 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
# See the License for the specific language governing permissions and
|
| 14 |
+
# limitations under the License.
|
| 15 |
+
|
| 16 |
+
"""
|
| 17 |
+
The Towards Malay Abbreviation Disambiguation (TMAD) Malay Corpus includes sentences from Malay news sites with abbreviations and their meanings. Only abbreviations with more than one possible meaning are included.
|
| 18 |
+
"""
|
| 19 |
+
import csv
|
| 20 |
+
import json
|
| 21 |
+
from pathlib import Path
|
| 22 |
+
from typing import Dict, List, Tuple
|
| 23 |
+
|
| 24 |
+
import datasets
|
| 25 |
+
|
| 26 |
+
from seacrowd.utils import schemas
|
| 27 |
+
from seacrowd.utils.configs import SEACrowdConfig
|
| 28 |
+
from seacrowd.utils.constants import Licenses, Tasks
|
| 29 |
+
|
| 30 |
+
_CITATION = """\
|
| 31 |
+
@article{article,
|
| 32 |
+
author = {Ciosici, Manuel and Sommer, Tobias},
|
| 33 |
+
year = {2019},
|
| 34 |
+
month = {04},
|
| 35 |
+
pages = {},
|
| 36 |
+
title = {Unsupervised Abbreviation Disambiguation Contextual disambiguation using word embeddings}
|
| 37 |
+
}
|
| 38 |
+
"""
|
| 39 |
+
|
| 40 |
+
_DATASETNAME = "tmad_malay_corpus"
|
| 41 |
+
|
| 42 |
+
_DESCRIPTION = """\
|
| 43 |
+
The Towards Malay Abbreviation Disambiguation (TMAD) Malay Corpus includes sentences from Malay news sites with abbreviations and their meanings. Only abbreviations with more than one possible meaning are included.
|
| 44 |
+
"""
|
| 45 |
+
|
| 46 |
+
_HOMEPAGE = "https://github.com/bhysss/TMAD-CUM/tree/master"
|
| 47 |
+
|
| 48 |
+
_LANGUAGES = ["zlm"]
|
| 49 |
+
|
| 50 |
+
_LICENSE = Licenses.UNKNOWN.value
|
| 51 |
+
|
| 52 |
+
_LOCAL = False
|
| 53 |
+
|
| 54 |
+
_URLS = {
|
| 55 |
+
"train": "https://raw.githubusercontent.com/bhysss/TMAD-CUM/master/data/Malay/data_train.csv",
|
| 56 |
+
"dev": "https://raw.githubusercontent.com/bhysss/TMAD-CUM/master/data/Malay/data_dev.csv",
|
| 57 |
+
"test": "https://raw.githubusercontent.com/bhysss/TMAD-CUM/master/data/Malay/data_test.csv",
|
| 58 |
+
"dict": "https://raw.githubusercontent.com/bhysss/TMAD-CUM/master/data/Malay/May_dic.json",
|
| 59 |
+
}
|
| 60 |
+
_SUPPORTED_TASKS = [Tasks.QUESTION_ANSWERING]
|
| 61 |
+
|
| 62 |
+
_SOURCE_VERSION = "1.0.0"
|
| 63 |
+
_SEACROWD_VERSION = "2024.06.20"
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
class TMADMalayCorpusDataset(datasets.GeneratorBasedBuilder):
|
| 67 |
+
"""Abbreviation disambiguation dataset from Malay news sites."""
|
| 68 |
+
|
| 69 |
+
SOURCE_VERSION = datasets.Version(_SOURCE_VERSION)
|
| 70 |
+
SEACROWD_VERSION = datasets.Version(_SEACROWD_VERSION)
|
| 71 |
+
|
| 72 |
+
BUILDER_CONFIGS = [
|
| 73 |
+
SEACrowdConfig(
|
| 74 |
+
name=f"{_DATASETNAME}_source",
|
| 75 |
+
version=SOURCE_VERSION,
|
| 76 |
+
description="{_DATASETNAME} source schema",
|
| 77 |
+
schema="source",
|
| 78 |
+
subset_id=f"{_DATASETNAME}",
|
| 79 |
+
),
|
| 80 |
+
SEACrowdConfig(
|
| 81 |
+
name=f"{_DATASETNAME}_seacrowd_qa",
|
| 82 |
+
version=SEACROWD_VERSION,
|
| 83 |
+
description=f"{_DATASETNAME} SEACrowd schema",
|
| 84 |
+
schema="seacrowd_qa",
|
| 85 |
+
subset_id=f"{_DATASETNAME}",
|
| 86 |
+
),
|
| 87 |
+
]
|
| 88 |
+
|
| 89 |
+
DEFAULT_CONFIG_NAME = f"{_DATASETNAME}_source"
|
| 90 |
+
|
| 91 |
+
def _info(self) -> datasets.DatasetInfo:
|
| 92 |
+
if self.config.schema == "source":
|
| 93 |
+
features = datasets.Features({"abbr": datasets.Value("string"), "definition": datasets.Value("string"), "sentence": datasets.Value("string"), "choices": datasets.Sequence(datasets.Value("string"))})
|
| 94 |
+
|
| 95 |
+
elif self.config.schema == "seacrowd_qa":
|
| 96 |
+
features = schemas.qa_features
|
| 97 |
+
|
| 98 |
+
return datasets.DatasetInfo(
|
| 99 |
+
description=_DESCRIPTION,
|
| 100 |
+
features=features,
|
| 101 |
+
homepage=_HOMEPAGE,
|
| 102 |
+
license=_LICENSE,
|
| 103 |
+
citation=_CITATION,
|
| 104 |
+
)
|
| 105 |
+
|
| 106 |
+
def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
|
| 107 |
+
"""Returns SplitGenerators."""
|
| 108 |
+
|
| 109 |
+
data_dirs = dl_manager.download_and_extract(_URLS)
|
| 110 |
+
|
| 111 |
+
return [
|
| 112 |
+
datasets.SplitGenerator(
|
| 113 |
+
name=datasets.Split.TRAIN,
|
| 114 |
+
# Whatever you put in gen_kwargs will be passed to _generate_examples
|
| 115 |
+
gen_kwargs={"filepath": data_dirs["train"], "dictpath": data_dirs["dict"]},
|
| 116 |
+
),
|
| 117 |
+
datasets.SplitGenerator(
|
| 118 |
+
name=datasets.Split.TEST,
|
| 119 |
+
gen_kwargs={"filepath": data_dirs["test"], "dictpath": data_dirs["dict"]},
|
| 120 |
+
),
|
| 121 |
+
datasets.SplitGenerator(
|
| 122 |
+
name=datasets.Split.VALIDATION,
|
| 123 |
+
gen_kwargs={"filepath": data_dirs["dev"], "dictpath": data_dirs["dict"]},
|
| 124 |
+
),
|
| 125 |
+
]
|
| 126 |
+
|
| 127 |
+
def _generate_examples(self, filepath: Path, dictpath: Path) -> Tuple[int, Dict]:
|
| 128 |
+
|
| 129 |
+
with open(dictpath) as f:
|
| 130 |
+
may_dict = json.load(f)
|
| 131 |
+
|
| 132 |
+
if self.config.schema == "source":
|
| 133 |
+
with open(filepath, encoding="utf-8") as f:
|
| 134 |
+
for row_idx, row in enumerate(csv.DictReader(f)):
|
| 135 |
+
yield row_idx, {"abbr": row["Abbr"], "definition": row["Definition"], "sentence": row["Sentence"], "choices": may_dict[row["Abbr"]]}
|
| 136 |
+
|
| 137 |
+
elif self.config.schema == "seacrowd_qa":
|
| 138 |
+
with open(filepath, encoding="utf-8") as f:
|
| 139 |
+
for row_idx, row in enumerate(csv.DictReader(f)):
|
| 140 |
+
yield row_idx, {"id": row_idx, "question_id": 0, "document_id": 0, "question": row["Abbr"], "type": "multiple_choice", "choices": may_dict[row["Abbr"]], "context": row["Sentence"], "answer": [row["Definition"]], "meta": {}}
|