Upload gap_raw.py with huggingface_hub
Browse files- gap_raw.py +118 -0
gap_raw.py
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# coding=utf-8
|
| 2 |
+
# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
|
| 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 |
+
# Lint as: python3
|
| 17 |
+
"""GAP is a gender-balanced text data set."""
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
import csv
|
| 21 |
+
|
| 22 |
+
import datasets
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
_CITATION = """
|
| 26 |
+
@article{DBLP:journals/corr/abs-1810-05201,
|
| 27 |
+
author = {Kellie Webster and
|
| 28 |
+
Marta Recasens and
|
| 29 |
+
Vera Axelrod and
|
| 30 |
+
Jason Baldridge},
|
| 31 |
+
title = {Mind the {GAP:} {A} Balanced Corpus of Gendered Ambiguous Pronouns},
|
| 32 |
+
journal = {CoRR},
|
| 33 |
+
volume = {abs/1810.05201},
|
| 34 |
+
year = {2018},
|
| 35 |
+
url = {http://arxiv.org/abs/1810.05201},
|
| 36 |
+
archivePrefix = {arXiv},
|
| 37 |
+
eprint = {1810.05201},
|
| 38 |
+
timestamp = {Tue, 30 Oct 2018 20:39:56 +0100},
|
| 39 |
+
biburl = {https://dblp.org/rec/bib/journals/corr/abs-1810-05201},
|
| 40 |
+
bibsource = {dblp computer science bibliography, https://dblp.org}
|
| 41 |
+
}
|
| 42 |
+
"""
|
| 43 |
+
|
| 44 |
+
_DESCRIPTION = """
|
| 45 |
+
GAP is a gender-balanced dataset containing 8,908 coreference-labeled pairs of
|
| 46 |
+
(ambiguous pronoun, antecedent name), sampled from Wikipedia and released by
|
| 47 |
+
Google AI Language for the evaluation of coreference resolution in practical
|
| 48 |
+
applications.
|
| 49 |
+
"""
|
| 50 |
+
|
| 51 |
+
_TRAINURL = "https://raw.githubusercontent.com/google-research-datasets/gap-coreference/master/gap-development.tsv"
|
| 52 |
+
_VALIDATIONURL = "https://raw.githubusercontent.com/google-research-datasets/gap-coreference/master/gap-validation.tsv"
|
| 53 |
+
_TESTURL = "https://raw.githubusercontent.com/google-research-datasets/gap-coreference/master/gap-test.tsv"
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
class Gap(datasets.GeneratorBasedBuilder):
|
| 57 |
+
"""GAP is a gender-balanced dataset.
|
| 58 |
+
|
| 59 |
+
It contains 8,908 coreference-labeled pairs
|
| 60 |
+
of (ambiguous pronoun, antecedent name), sampled from Wikipedia.
|
| 61 |
+
"""
|
| 62 |
+
|
| 63 |
+
VERSION = datasets.Version("0.1.0")
|
| 64 |
+
|
| 65 |
+
def _info(self):
|
| 66 |
+
return datasets.DatasetInfo(
|
| 67 |
+
description=_DESCRIPTION,
|
| 68 |
+
features=datasets.Features(
|
| 69 |
+
{
|
| 70 |
+
"ID": datasets.Value("string"),
|
| 71 |
+
"Text": datasets.Value("string"),
|
| 72 |
+
"Pronoun": datasets.Value("string"),
|
| 73 |
+
"Pronoun-offset": datasets.Value("int32"),
|
| 74 |
+
"A": datasets.Value("string"),
|
| 75 |
+
"A-offset": datasets.Value("int32"),
|
| 76 |
+
"A-coref": datasets.Value("bool"),
|
| 77 |
+
"B": datasets.Value("string"),
|
| 78 |
+
"B-offset": datasets.Value("int32"),
|
| 79 |
+
"B-coref": datasets.Value("bool"),
|
| 80 |
+
"URL": datasets.Value("string"),
|
| 81 |
+
}
|
| 82 |
+
),
|
| 83 |
+
supervised_keys=None,
|
| 84 |
+
homepage="https://github.com/google-research-datasets/gap-coreference",
|
| 85 |
+
citation=_CITATION,
|
| 86 |
+
)
|
| 87 |
+
|
| 88 |
+
def _split_generators(self, dl_manager):
|
| 89 |
+
"""Returns SplitGenerators."""
|
| 90 |
+
directory = dl_manager.download_and_extract(
|
| 91 |
+
{"train": _TRAINURL, "validation": _VALIDATIONURL, "test": _TESTURL}
|
| 92 |
+
)
|
| 93 |
+
return [
|
| 94 |
+
datasets.SplitGenerator(
|
| 95 |
+
name=datasets.Split.TRAIN,
|
| 96 |
+
gen_kwargs={"filepath": directory["train"]},
|
| 97 |
+
),
|
| 98 |
+
datasets.SplitGenerator(
|
| 99 |
+
name=datasets.Split.VALIDATION,
|
| 100 |
+
gen_kwargs={"filepath": directory["validation"]},
|
| 101 |
+
),
|
| 102 |
+
datasets.SplitGenerator(
|
| 103 |
+
name=datasets.Split.TEST,
|
| 104 |
+
gen_kwargs={"filepath": directory["test"]},
|
| 105 |
+
),
|
| 106 |
+
]
|
| 107 |
+
|
| 108 |
+
def _generate_examples(self, filepath):
|
| 109 |
+
"""Yields examples."""
|
| 110 |
+
with open(filepath, encoding="utf-8") as tsvfile:
|
| 111 |
+
reader = csv.DictReader(tsvfile, dialect="excel-tab")
|
| 112 |
+
for i, row in enumerate(reader):
|
| 113 |
+
row["A-coref"] = row["A-coref"] == "TRUE"
|
| 114 |
+
row["B-coref"] = row["B-coref"] == "TRUE"
|
| 115 |
+
row["A-offset"] = int(row["A-offset"])
|
| 116 |
+
row["B-offset"] = int(row["B-offset"])
|
| 117 |
+
row["Pronoun-offset"] = int(row["Pronoun-offset"])
|
| 118 |
+
yield i, row
|