Datasets:
File size: 4,719 Bytes
e4521e4 e208278 e4521e4 090bc6f e4521e4 e958fd0 e4521e4 ecc3912 e4521e4 72fbb7d e4521e4 e958fd0 e4521e4 2a712a3 e4521e4 |
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 |
import datasets
from typing import List
logger = datasets.logging.get_logger(__name__)
_CITATION = """\
@inproceedings{haagsma-etal-2020-magpie,
title = "{MAGPIE}: A Large Corpus of Potentially Idiomatic Expressions",
author = "Haagsma, Hessel and
Bos, Johan and
Nissim, Malvina",
booktitle = "Proceedings of the 12th Language Resources and Evaluation Conference",
month = may,
year = "2020",
address = "Marseille, France",
publisher = "European Language Resources Association",
url = "https://aclanthology.org/2020.lrec-1.35",
pages = "279--287",
language = "English",
ISBN = "979-10-95546-34-4",
}
@inproceedings{dankers-etal-2022-transformer,
title = "Can Transformer be Too Compositional? Analysing Idiom Processing in Neural Machine Translation",
author = "Dankers, Verna and
Lucas, Christopher and
Titov, Ivan",
booktitle = "Proceedings of the 60th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers)",
month = may,
year = "2022",
address = "Dublin, Ireland",
publisher = "Association for Computational Linguistics",
url = "https://aclanthology.org/2022.acl-long.252",
doi = "10.18653/v1/2022.acl-long.252",
pages = "3608--3626",
}
"""
_DESCRIPTION = """\
The MAGPIE corpus is a large sense-annotated corpus of potentially idiomatic expressions (PIEs), based on the British National Corpus (BNC). Potentially idiomatic expressions are like idiomatic expressions, but the term also covers literal uses of idiomatic expressions, such as 'I leave work at the end of the day.' for the idiom 'at the end of the day'. This version of the dataset reflects the filtered subset used by Dankers et al. (2022) in their investigation on how PIEs are represented by NMT models. Authors use 37k samples annotated as fully figurative or literal, for 1482 idioms that contain nouns, numerals or adjectives that are colours (which they refer to as keywords). Because idioms show syntactic and morphological variability, the focus is mostly put on nouns. PIEs and their context are separated using the original corpus’s word-level annotations.
"""
_HOMEPAGE = "https://github.com/vernadankers/mt_idioms"
_LICENSE = "CC-BY-4.0"
class MagpieConfig(datasets.BuilderConfig):
"""BuilderConfig for MAGPIE."""
def __init__(self, features, data_url, **kwargs):
"""BuilderConfig for MAGPIE.
Args:
features: : `list[string]`, list of the features that will appear in the
feature dict. Should not include "label".
**kwargs: keyword arguments forwarded to super.
"""
super().__init__(**kwargs)
self.features = features
self.data_url = data_url
class Magpie(datasets.GeneratorBasedBuilder):
"""MAGPIE: A Large Corpus of Potentially Idiomatic Expressions"""
BUILDER_CONFIGS = [
MagpieConfig(
name="magpie",
version=datasets.Version("1.0.0"),
features=["sentence", "annotation", "idiom", "usage", "variant", "pos_tags"],
data_url="https://huggingface.co/datasets/gsarti/magpie/resolve/main/magpie.tsv"
)
]
DEFAULT_CONFIG_NAME = "magpie"
def _info(self):
features = {feature: datasets.Value("string") for feature in self.config.features}
features["annotation"] = datasets.features.Sequence(datasets.Value("uint8"))
features["pos_tags"] = datasets.features.Sequence(datasets.Value("string"))
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=datasets.Features(features),
supervised_keys=None,
homepage=_HOMEPAGE,
citation=_CITATION,
license=_LICENSE
)
def _split_generators(self, dl_manager):
data_file = dl_manager.download_and_extract(self.config.data_url)
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={
"filepath": data_file,
"features": self.config.features,
},
),
]
def _generate_examples(self, filepath: str, features: List[str]):
"""Yields examples as (key, example) tuples."""
with open(filepath, encoding="utf8") as f:
for id_, row in enumerate(f):
if id_ == 0:
continue
fields = row.strip().split("\t")
fields[1] = fields[1].strip().split()
fields[-1] = fields[-1].strip().split()
yield id_, {
k:v for k,v in zip(features, fields)
} |