Sebastian Gehrmann commited on
Commit
70bc399
1 Parent(s): 1159251
Files changed (2) hide show
  1. common_gen.py +154 -0
  2. dataset_infos.json +105 -0
common_gen.py ADDED
@@ -0,0 +1,154 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import os
3
+ import datasets
4
+
5
+ _CITATION = """\
6
+ @inproceedings{lin-etal-2020-commongen,
7
+ title = "{C}ommon{G}en: A Constrained Text Generation Challenge for Generative Commonsense Reasoning",
8
+ author = "Lin, Bill Yuchen and
9
+ Zhou, Wangchunshu and
10
+ Shen, Ming and
11
+ Zhou, Pei and
12
+ Bhagavatula, Chandra and
13
+ Choi, Yejin and
14
+ Ren, Xiang",
15
+ booktitle = "Findings of the Association for Computational Linguistics: EMNLP 2020",
16
+ month = nov,
17
+ year = "2020",
18
+ address = "Online",
19
+ publisher = "Association for Computational Linguistics",
20
+ url = "https://www.aclweb.org/anthology/2020.findings-emnlp.165",
21
+ pages = "1823--1840",
22
+ }
23
+ """
24
+
25
+ _DESCRIPTION = """\
26
+ CommonGen is a constrained text generation task, associated with a benchmark
27
+ dataset, to explicitly test machines for the ability of generative commonsense
28
+ reasoning. Given a set of common concepts; the task is to generate a coherent
29
+ sentence describing an everyday scenario using these concepts.
30
+ """
31
+
32
+ _URLs = {
33
+ "data": "https://storage.googleapis.com/huggingface-nlp/datasets/common_gen/commongen_data.zip",
34
+ "challenge_set": "https://storage.googleapis.com/huggingface-nlp/datasets/gem/gem_challenge_sets/common_gen.zip",
35
+ }
36
+
37
+
38
+ class CommonGen(datasets.GeneratorBasedBuilder):
39
+ VERSION = datasets.Version("1.0.0")
40
+
41
+ def _info(self):
42
+ return datasets.DatasetInfo(
43
+ description=_DESCRIPTION,
44
+ features=datasets.Features(
45
+ {
46
+ "gem_id": datasets.Value("string"),
47
+ "gem_parent_id": datasets.Value("string"),
48
+ "concept_set_id": datasets.Value("int32"),
49
+ "concepts": [datasets.Value("string")],
50
+ "target": datasets.Value("string"), # single target for train
51
+ "references": [
52
+ datasets.Value("string")
53
+ ], # multiple references for validation
54
+ }
55
+ ),
56
+ supervised_keys=None,
57
+ homepage="https://inklab.usc.edu/CommonGen/",
58
+ citation=_CITATION,
59
+ )
60
+
61
+ def _split_generators(self, dl_manager):
62
+ """Returns SplitGenerators."""
63
+ dl_dir = dl_manager.download_and_extract(_URLs[self.config.name])
64
+ challenge_sets = [
65
+ ("challenge_train_sample", "train_common_gen_RandomSample500.json"),
66
+ (
67
+ "challenge_validation_sample",
68
+ "validation_common_gen_RandomSample500.json",
69
+ ),
70
+ (
71
+ "challenge_test_scramble",
72
+ "test_common_gen_ScrambleInputStructure500.json",
73
+ ),
74
+ ]
75
+ return [
76
+ datasets.SplitGenerator(
77
+ name=datasets.Split.TRAIN,
78
+ gen_kwargs={
79
+ "filepath": os.path.join(dl_dir["data"], "commongen.train.jsonl"),
80
+ "split": "train",
81
+ },
82
+ ),
83
+ datasets.SplitGenerator(
84
+ name=datasets.Split.VALIDATION,
85
+ gen_kwargs={
86
+ "filepath": os.path.join(dl_dir["data"], "commongen.dev.jsonl"),
87
+ "split": "validation",
88
+ },
89
+ ),
90
+ datasets.SplitGenerator(
91
+ name=datasets.Split.TEST,
92
+ gen_kwargs={
93
+ "filepath": os.path.join(
94
+ dl_dir["data"], "commongen.test_noref.jsonl"
95
+ ),
96
+ "split": "test",
97
+ },
98
+ ),
99
+ ] + [
100
+ datasets.SplitGenerator(
101
+ name=challenge_split,
102
+ gen_kwargs={
103
+ "filepath": os.path.join(
104
+ dl_dir["challenge_set"], self.config.name, filename
105
+ ),
106
+ "split": challenge_split,
107
+ },
108
+ )
109
+ for challenge_split, filename in challenge_sets
110
+ ]
111
+
112
+ def _generate_examples(self, filepath, split, filepaths=None, lang=None):
113
+ """Yields examples."""
114
+ if split.startswith("challenge"):
115
+ exples = json.load(open(filepath, encoding="utf-8"))
116
+ if isinstance(exples, dict):
117
+ assert len(exples) == 1, "multiple entries found"
118
+ exples = list(exples.values())[0]
119
+ for id_, exple in enumerate(exples):
120
+ if len(exple) == 0:
121
+ continue
122
+ exple["gem_parent_id"] = exple["gem_id"]
123
+ exple["gem_id"] = f"{self.config.name}-{split}-{id_}"
124
+ yield id_, exple
125
+ else:
126
+ with open(filepath, encoding="utf-8") as f:
127
+ id_ = -1
128
+ i = -1
129
+ for row in f:
130
+ row = row.replace(", }", "}") # Fix possible JSON format error
131
+ data = json.loads(row)
132
+ concepts = [word for word in data["concept_set"].split("#")]
133
+ if split == "train":
134
+ i += 1
135
+ for scene in data["scene"]:
136
+ id_ += 1
137
+ yield id_, {
138
+ "gem_id": f"{self.config.name}-{split}-{id_}",
139
+ "gem_parent_id": f"{self.config.name}-{split}-{id_}",
140
+ "concept_set_id": i,
141
+ "concepts": concepts,
142
+ "target": scene,
143
+ "references": [],
144
+ }
145
+ else:
146
+ id_ += 1
147
+ yield id_, {
148
+ "gem_id": f"{self.config.name}-{split}-{id_}",
149
+ "gem_parent_id": f"{self.config.name}-{split}-{id_}",
150
+ "concept_set_id": id_,
151
+ "concepts": concepts,
152
+ "target": "" if split == "test" else data["scene"][0],
153
+ "references": [] if split == "test" else data["scene"],
154
+ }
dataset_infos.json ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "description": "GEM is a benchmark environment for Natural Language Generation with a focus on its Evaluation,\nboth through human annotations and automated Metrics.\n\nGEM aims to:\n- measure NLG progress across 13 datasets spanning many NLG tasks and languages.\n- provide an in-depth analysis of data and models presented via data statements and challenge sets.\n- develop standards for evaluation of generated text using both automated and human metrics.\n\nIt is our goal to regularly update GEM and to encourage toward more inclusive practices in dataset development\nby extending existing data or developing datasets for additional languages.\n",
3
+ "citation": "@article{gem_benchmark,\n author = {Sebastian Gehrmann and\n Tosin P. Adewumi and\n Karmanya Aggarwal and\n Pawan Sasanka Ammanamanchi and\n Aremu Anuoluwapo and\n Antoine Bosselut and\n Khyathi Raghavi Chandu and\n Miruna{-}Adriana Clinciu and\n Dipanjan Das and\n Kaustubh D. Dhole and\n Wanyu Du and\n Esin Durmus and\n Ondrej Dusek and\n Chris Emezue and\n Varun Gangal and\n Cristina Garbacea and\n Tatsunori Hashimoto and\n Yufang Hou and\n Yacine Jernite and\n Harsh Jhamtani and\n Yangfeng Ji and\n Shailza Jolly and\n Dhruv Kumar and\n Faisal Ladhak and\n Aman Madaan and\n Mounica Maddela and\n Khyati Mahajan and\n Saad Mahamood and\n Bodhisattwa Prasad Majumder and\n Pedro Henrique Martins and\n Angelina McMillan{-}Major and\n Simon Mille and\n Emiel van Miltenburg and\n Moin Nadeem and\n Shashi Narayan and\n Vitaly Nikolaev and\n Rubungo Andre Niyongabo and\n Salomey Osei and\n Ankur P. Parikh and\n Laura Perez{-}Beltrachini and\n Niranjan Ramesh Rao and\n Vikas Raunak and\n Juan Diego Rodriguez and\n Sashank Santhanam and\n Joao Sedoc and\n Thibault Sellam and\n Samira Shaikh and\n Anastasia Shimorina and\n Marco Antonio Sobrevilla Cabezudo and\n Hendrik Strobelt and\n Nishant Subramani and\n Wei Xu and\n Diyi Yang and\n Akhila Yerukola and\n Jiawei Zhou},\n title = {The {GEM} Benchmark: Natural Language Generation, its Evaluation and\n Metrics},\n journal = {CoRR},\n volume = {abs/2102.01672},\n year = {2021},\n url = {https://arxiv.org/abs/2102.01672},\n archivePrefix = {arXiv},\n eprint = {2102.01672}\n}\n",
4
+ "homepage": "https://gem-benchmark.github.io/",
5
+ "license": "CC-BY-SA-4.0",
6
+ "features": {
7
+ "gem_id": {
8
+ "dtype": "string",
9
+ "id": null,
10
+ "_type": "Value"
11
+ },
12
+ "gem_parent_id": {
13
+ "dtype": "string",
14
+ "id": null,
15
+ "_type": "Value"
16
+ },
17
+ "concept_set_id": {
18
+ "dtype": "int32",
19
+ "id": null,
20
+ "_type": "Value"
21
+ },
22
+ "concepts": [
23
+ {
24
+ "dtype": "string",
25
+ "id": null,
26
+ "_type": "Value"
27
+ }
28
+ ],
29
+ "target": {
30
+ "dtype": "string",
31
+ "id": null,
32
+ "_type": "Value"
33
+ },
34
+ "references": [
35
+ {
36
+ "dtype": "string",
37
+ "id": null,
38
+ "_type": "Value"
39
+ }
40
+ ]
41
+ },
42
+ "post_processed": null,
43
+ "supervised_keys": null,
44
+ "builder_name": "gem",
45
+ "config_name": "common_gen",
46
+ "version": {
47
+ "version_str": "1.1.0",
48
+ "description": null,
49
+ "major": 1,
50
+ "minor": 1,
51
+ "patch": 0
52
+ },
53
+ "splits": {
54
+ "train": {
55
+ "name": "train",
56
+ "num_bytes": 10475926,
57
+ "num_examples": 67389,
58
+ "dataset_name": "gem"
59
+ },
60
+ "validation": {
61
+ "name": "validation",
62
+ "num_bytes": 405872,
63
+ "num_examples": 993,
64
+ "dataset_name": "gem"
65
+ },
66
+ "test": {
67
+ "name": "test",
68
+ "num_bytes": 153170,
69
+ "num_examples": 1497,
70
+ "dataset_name": "gem"
71
+ },
72
+ "challenge_train_sample": {
73
+ "name": "challenge_train_sample",
74
+ "num_bytes": 85413,
75
+ "num_examples": 500,
76
+ "dataset_name": "gem"
77
+ },
78
+ "challenge_validation_sample": {
79
+ "name": "challenge_validation_sample",
80
+ "num_bytes": 215192,
81
+ "num_examples": 500,
82
+ "dataset_name": "gem"
83
+ },
84
+ "challenge_test_scramble": {
85
+ "name": "challenge_test_scramble",
86
+ "num_bytes": 60411,
87
+ "num_examples": 500,
88
+ "dataset_name": "gem"
89
+ }
90
+ },
91
+ "download_checksums": {
92
+ "https://storage.googleapis.com/huggingface-nlp/datasets/common_gen/commongen_data.zip": {
93
+ "num_bytes": 1845699,
94
+ "checksum": "a3f19ca607da4e874fc5f2dd1f53c13a6788a497f883d74cc3f9a1fcda44c594"
95
+ },
96
+ "https://storage.googleapis.com/huggingface-nlp/datasets/gem/gem_challenge_sets/common_gen.zip": {
97
+ "num_bytes": 87818,
98
+ "checksum": "f6ebc814256da2e771c4ab32d7a9ed052762d83184c1a2450c3cc208145485dc"
99
+ }
100
+ },
101
+ "download_size": 1933517,
102
+ "post_processing_size": null,
103
+ "dataset_size": 11395984,
104
+ "size_in_bytes": 13329501
105
+ }