|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"""Wiki-Convert: Language Modelling with Cardinal Number Annotations""" |
|
|
|
|
|
import json |
|
|
|
import datasets |
|
|
|
|
|
|
|
logger = datasets.logging.get_logger(__name__) |
|
|
|
|
|
_CITATION = """\ |
|
@inproceedings{thawani-etal-2021-numeracy, |
|
title = "Numeracy enhances the Literacy of Language Models", |
|
author = "Thawani, Avijit and |
|
Pujara, Jay and |
|
Ilievski, Filip", |
|
booktitle = "Proceedings of the 2021 Conference on Empirical Methods in Natural Language Processing", |
|
month = nov, |
|
year = "2021", |
|
address = "Online and Punta Cana, Dominican Republic", |
|
publisher = "Association for Computational Linguistics", |
|
url = "https://aclanthology.org/2021.emnlp-main.557", |
|
pages = "6960--6967", |
|
abstract = "Specialized number representations in NLP have shown improvements on numerical reasoning tasks like arithmetic word problems and masked number prediction. But humans also use numeracy to make better sense of world concepts, e.g., you can seat 5 people in your {`}room{'} but not 500. Does a better grasp of numbers improve a model{'}s understanding of other concepts and words? This paper studies the effect of using six different number encoders on the task of masked word prediction (MWP), as a proxy for evaluating literacy. To support this investigation, we develop Wiki-Convert, a 900,000 sentence dataset annotated with numbers and units, to avoid conflating nominal and ordinal number occurrences. We find a significant improvement in MWP for sentences containing numbers, that exponent embeddings are the best number encoders, yielding over 2 points jump in prediction accuracy over a BERT baseline, and that these enhanced literacy skills also generalize to contexts without annotated numbers. We release all code at https://git.io/JuZXn.", |
|
} |
|
""" |
|
|
|
_DESCRIPTION = """\ |
|
Language Modelling with Cardinal Number Annotations. |
|
""" |
|
|
|
|
|
_URL = "https://huggingface.co/datasets/usc-isi/WikiConvert/resolve/main/" |
|
_URLS = { |
|
"train": _URL + "train_wiki.json", |
|
"dev": _URL + "dev_wiki.json", |
|
"test": _URL + "test_wiki.json", |
|
} |
|
|
|
|
|
class WikiConvertConfig(datasets.BuilderConfig): |
|
"""BuilderConfig for WikiConvert.""" |
|
|
|
def __init__(self, **kwargs): |
|
"""BuilderConfig for WikiConvert. |
|
|
|
Args: |
|
**kwargs: keyword arguments forwarded to super. |
|
""" |
|
super(WikiConvertConfig, self).__init__(**kwargs) |
|
|
|
|
|
class WikiConvert(datasets.GeneratorBasedBuilder): |
|
"""WikiConvert: Language Modelling with Cardinal Number Annotations.. Version 1.1.""" |
|
|
|
BUILDER_CONFIGS = [ |
|
WikiConvertConfig( |
|
name="plain_text", |
|
version=datasets.Version("1.0.0", ""), |
|
description="Plain text", |
|
), |
|
] |
|
|
|
def _info(self): |
|
return datasets.DatasetInfo( |
|
description=_DESCRIPTION, |
|
features=datasets.Features( |
|
{ |
|
"id": datasets.Value("int32"), |
|
"UNIQUE_STORY_INDEX": datasets.Value("string"), |
|
"offset": datasets.Value("int32"), |
|
"length": datasets.Value("int32"), |
|
"magnitude": datasets.Value("int32"), |
|
"comment": datasets.Value("string"), |
|
"number": datasets.Value("int32"), |
|
} |
|
), |
|
|
|
supervised_keys=None, |
|
homepage="https://github.com/avi-jit/numeracy-literacy/", |
|
citation=_CITATION, |
|
|
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
downloaded_files = dl_manager.download_and_extract(_URLS) |
|
|
|
return [ |
|
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}), |
|
datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files["dev"]}), |
|
] |
|
|
|
def _generate_examples(self, filepath): |
|
"""This function returns the examples in the raw (text) form.""" |
|
logger.info("generating examples from = %s", filepath) |
|
key = 0 |
|
with open(filepath, encoding="utf-8") as f: |
|
ds = json.load(f) |
|
|
|
|
|
|
|
|
|
|
|
|
|
for row in ds: |
|
yield key, { |
|
"id": row["id"], |
|
"UNIQUE_STORY_INDEX": row["UNIQUE_STORY_INDEX"], |
|
"offset": row["offset"], |
|
"length": row["length"], |
|
"magnitude": row["magnitude"], |
|
"comment": row["comment"], |
|
"number": row["number"], |
|
} |
|
key += 1 |