Datasets:

Sub-tasks:
rdf-to-text
Multilinguality:
monolingual
Size Categories:
1K<n<10K
Language Creators:
crowdsourced
Annotations Creators:
found
Source Datasets:
extended|other-web-nlg
License:
system HF staff commited on
Commit
345ad85
0 Parent(s):

Update files from the datasets library (from 1.2.0)

Browse files

Release notes: https://github.com/huggingface/datasets/releases/tag/1.2.0

.gitattributes ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bin.* filter=lfs diff=lfs merge=lfs -text
5
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.model filter=lfs diff=lfs merge=lfs -text
12
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
13
+ *.onnx filter=lfs diff=lfs merge=lfs -text
14
+ *.ot filter=lfs diff=lfs merge=lfs -text
15
+ *.parquet filter=lfs diff=lfs merge=lfs -text
16
+ *.pb filter=lfs diff=lfs merge=lfs -text
17
+ *.pt filter=lfs diff=lfs merge=lfs -text
18
+ *.pth filter=lfs diff=lfs merge=lfs -text
19
+ *.rar filter=lfs diff=lfs merge=lfs -text
20
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
21
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
22
+ *.tflite filter=lfs diff=lfs merge=lfs -text
23
+ *.tgz filter=lfs diff=lfs merge=lfs -text
24
+ *.xz filter=lfs diff=lfs merge=lfs -text
25
+ *.zip filter=lfs diff=lfs merge=lfs -text
26
+ *.zstandard filter=lfs diff=lfs merge=lfs -text
27
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,214 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ annotations_creators:
3
+ - found
4
+ language_creators:
5
+ - crowdsourced
6
+ languages:
7
+ de:
8
+ - de
9
+ en:
10
+ - en
11
+ licenses:
12
+ - cc-by-sa-4-0
13
+ multilinguality:
14
+ - monolingual
15
+ size_categories:
16
+ - 1K<n<10K
17
+ source_datasets:
18
+ - extended|other-web-nlg
19
+ task_categories:
20
+ - conditional-text-generation
21
+ task_ids:
22
+ - other-stuctured-to-text
23
+ ---
24
+
25
+ # Dataset Card for WebNLG
26
+
27
+ ## Table of Contents
28
+
29
+ - [Dataset Description](#dataset-description)
30
+ - [Dataset Summary](#dataset-summary)
31
+ - [Supported Tasks](#supported-tasks-and-leaderboards)
32
+ - [Languages](#languages)
33
+ - [Dataset Structure](#dataset-structure)
34
+ - [Data Instances](#data-instances)
35
+ - [Data Fields](#data-instances)
36
+ - [Data Splits](#data-instances)
37
+ - [Dataset Creation](#dataset-creation)
38
+ - [Curation Rationale](#curation-rationale)
39
+ - [Source Data](#source-data)
40
+ - [Annotations](#annotations)
41
+ - [Personal and Sensitive Information](#personal-and-sensitive-information)
42
+ - [Considerations for Using the Data](#considerations-for-using-the-data)
43
+ - [Social Impact of Dataset](#social-impact-of-dataset)
44
+ - [Discussion of Biases](#discussion-of-biases)
45
+ - [Other Known Limitations](#other-known-limitations)
46
+ - [Additional Information](#additional-information)
47
+ - [Dataset Curators](#dataset-curators)
48
+ - [Licensing Information](#licensing-information)
49
+ - [Citation Information](#citation-information)
50
+
51
+ ## Dataset Description
52
+
53
+ - **Homepage:** [WebNLG challenge website](https://webnlg-challenge.loria.fr/)
54
+ - **Repository:** [Enriched WebNLG Github repository](https://github.com/ThiagoCF05/webnlg)
55
+ - **Paper:** [Enriching the WebNLG corpus](https://www.aclweb.org/anthology/W18-6521/)
56
+
57
+ ### Dataset Summary
58
+
59
+ The WebNLG challenge consists in mapping data to text. The training data consists of Data/Text pairs where the data is a
60
+ set of triples extracted from DBpedia and the text is a verbalisation of these triples. For instance, given the 3
61
+ DBpedia triples shown in (a), the aim is to generate a text such as (b). It is a valuable resource and benchmark for the Natural Language Generation (NLG) community. However, as other NLG benchmarks, it only consists of a collection of parallel raw representations and their corresponding textual realizations. This work aimed to provide intermediate representations of the data for the development and evaluation of popular tasks in the NLG pipeline architecture, such as Discourse Ordering, Lexicalization, Aggregation and Referring Expression Generation.
62
+
63
+ ### Supported Tasks and Leaderboards
64
+
65
+ The dataset supports a `other-structured-to-text` task which requires a model takes a set of RDF (Resource Description
66
+ Format) triples from a database (DBpedia) of the form (subject, property, object) as input and write out a natural
67
+ language sentence expressing the information contained in the triples.
68
+
69
+ ### Languages
70
+
71
+ The dataset is presented in two versions: English (config `en`) and German (config `de`)
72
+
73
+ ## Dataset Structure
74
+
75
+ ### Data Instances
76
+
77
+ A typical example contains the original RDF triples in the set, a modified version which presented to crowd workers, and
78
+ a set of possible verbalizations for this set of triples:
79
+
80
+ ```
81
+ { 'category': 'Politician',
82
+ 'eid': 'Id10',
83
+ 'lex': {'comment': ['good', 'good', 'good'],
84
+ 'lid': ['Id1', 'Id2', 'Id3'],
85
+ 'text': ['World War II had Chiang Kai-shek as a commander and United States Army soldier Abner W. Sibal.',
86
+ 'Abner W. Sibal served in the United States Army during the Second World War and during that war Chiang Kai-shek was one of the commanders.',
87
+ 'Abner W. Sibal, served in the United States Army and fought in World War II, one of the commanders of which, was Chiang Kai-shek.']},
88
+ 'modified_triple_sets': {'mtriple_set': [['Abner_W._Sibal | battle | World_War_II',
89
+ 'World_War_II | commander | Chiang_Kai-shek',
90
+ 'Abner_W._Sibal | militaryBranch | United_States_Army']]},
91
+ 'original_triple_sets': {'otriple_set': [['Abner_W._Sibal | battles | World_War_II', 'World_War_II | commander | Chiang_Kai-shek', 'Abner_W._Sibal | branch | United_States_Army'],
92
+ ['Abner_W._Sibal | militaryBranch | United_States_Army',
93
+ 'Abner_W._Sibal | battles | World_War_II',
94
+ 'World_War_II | commander | Chiang_Kai-shek']]},
95
+ 'shape': '(X (X) (X (X)))',
96
+ 'shape_type': 'mixed',
97
+ 'size': 3}
98
+ ```
99
+
100
+ ### Data Fields
101
+
102
+ The following fields can be found in the instances:
103
+
104
+ - `category`: the category of the DBpedia entites present in the RDF triples.
105
+ - `eid`: an example ID, only unique per split per category.
106
+ - `size`: number of RDF triples in the set.
107
+ - `shape`: (for v3 only) Each set of RDF-triples is a tree, which is characterised by its shape and shape type. `shape`
108
+ is a string representation of the tree with nested parentheses where X is a node (
109
+ see [Newick tree format](https://en.wikipedia.org/wiki/Newick_format))
110
+ - `shape_type`: (for v3 only) is a type of the tree shape, which can be: `chain` (the object of one triple is the
111
+ subject of the other); `sibling` (triples with a shared subject); `mixed` (both chain and sibling types present).
112
+ - `2017_test_category`: (for `webnlg_challenge_2017`) tells whether the set of RDF triples was present in the training
113
+ set or not.
114
+ - `lex`: the lexicalizations, with:
115
+ - `text`: the text to be predicted.
116
+ - `lid`: a lexicalizayion ID, unique per example.
117
+ - `comment`: the lexicalizations were rated by crowd workers are either `good` or `bad`
118
+
119
+ ### Data Splits
120
+
121
+ The `en` version has `train`, `test` and `dev` splits; the `de` version, only `train` and `dev`.
122
+
123
+ ## Dataset Creation
124
+
125
+ ### Curation Rationale
126
+
127
+ Natural Language Generation (NLG) is the process of automatically converting non-linguistic data into a linguistic output format (Reiter andDale, 2000; Gatt and Krahmer, 2018). Recently, the field has seen an increase in the number of available focused data resources as E2E (Novikova et al., 2017), ROTOWIRE(Wise-man et al., 2017) and WebNLG (Gardent et al.,2017a,b) corpora. Although theses recent releases are highly valuable resources for the NLG community in general,nall of them were designed to work with end-to-end NLG models. Hence, they consist of a collection of parallel raw representations and their corresponding textual realizations. No intermediate representations are available so researchersncan straight-forwardly use them to develop or evaluate popular tasks in NLG pipelines (Reiter and Dale, 2000), such as Discourse Ordering, Lexicalization, Aggregation, Referring Expression Generation, among others. Moreover, these new corpora, like many other resources in Computational Linguistics more in general, are only available in English, limiting the development of NLG-applications to other languages.
128
+
129
+
130
+ ### Source Data
131
+
132
+ #### Initial Data Collection and Normalization
133
+
134
+ [More Information Needed]
135
+
136
+ #### Who are the source language producers?
137
+
138
+ [More Information Needed]
139
+
140
+ ### Annotations
141
+
142
+ #### Annotation process
143
+
144
+ [More Information Needed]
145
+
146
+ #### Who are the annotators?
147
+
148
+ [More Information Needed]
149
+
150
+ ### Personal and Sensitive Information
151
+
152
+ [More Information Needed]
153
+
154
+ ## Considerations for Using the Data
155
+
156
+ ### Social Impact of Dataset
157
+
158
+ [More Information Needed]
159
+
160
+ ### Discussion of Biases
161
+
162
+ [More Information Needed]
163
+
164
+ ### Other Known Limitations
165
+
166
+ [More Information Needed]
167
+
168
+ ## Additional Information
169
+
170
+ ### Dataset Curators
171
+
172
+ [More Information Needed]
173
+
174
+ ### Licensing Information
175
+
176
+ The dataset uses the `cc-by-nc-sa-4.0` license. The source DBpedia project uses the `cc-by-sa-3.0` and `gfdl-1.1`
177
+ licenses.
178
+
179
+ ### Citation Information
180
+
181
+ - If you use the Enriched WebNLG corpus, cite:
182
+
183
+ ```
184
+ @InProceedings{ferreiraetal2018,
185
+ author = "Castro Ferreira, Thiago
186
+ and Moussallem, Diego
187
+ and Wubben, Sander
188
+ and Krahmer, Emiel",
189
+ title = "Enriching the WebNLG corpus",
190
+ booktitle = "Proceedings of the 11th International Conference on Natural Language Generation",
191
+ year = "2018",
192
+ series = {INLG'18},
193
+ publisher = "Association for Computational Linguistics",
194
+ address = "Tilburg, The Netherlands",
195
+ }
196
+
197
+ @inproceedings{web_nlg,
198
+ author = {Claire Gardent and
199
+ Anastasia Shimorina and
200
+ Shashi Narayan and
201
+ Laura Perez{-}Beltrachini},
202
+ editor = {Regina Barzilay and
203
+ Min{-}Yen Kan},
204
+ title = {Creating Training Corpora for {NLG} Micro-Planners},
205
+ booktitle = {Proceedings of the 55th Annual Meeting of the Association for Computational
206
+ Linguistics, {ACL} 2017, Vancouver, Canada, July 30 - August 4, Volume
207
+ 1: Long Papers},
208
+ pages = {179--188},
209
+ publisher = {Association for Computational Linguistics},
210
+ year = {2017},
211
+ url = {https://doi.org/10.18653/v1/P17-1017},
212
+ doi = {10.18653/v1/P17-1017}
213
+ }
214
+ ```
dataset_infos.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"en": {"description": "WebNLG is a valuable resource and benchmark for the Natural Language Generation (NLG) community. However, as other NLG benchmarks, it only consists of a collection of parallel raw representations and their corresponding textual realizations. This work aimed to provide intermediate representations of the data for the development and evaluation of popular tasks in the NLG pipeline architecture (Reiter and Dale, 2000), such as Discourse Ordering, Lexicalization, Aggregation and Referring Expression Generation.\n", "citation": "@InProceedings{ferreiraetal2018,\n author = \t\"Castro Ferreira, Thiago and Moussallem, Diego and Wubben, Sander and Krahmer, Emiel\",\n title = \t\"Enriching the WebNLG corpus\",\n booktitle = \t\"Proceedings of the 11th International Conference on Natural Language Generation\",\n year = \t\"2018\",\n series = {INLG'18},\n publisher = \t\"Association for Computational Linguistics\",\n address = \t\"Tilburg, The Netherlands\",\n}\n", "homepage": "https://github.com/ThiagoCF05/webnlg", "license": "CC Attribution-Noncommercial-Share Alike 4.0 International", "features": {"category": {"dtype": "string", "id": null, "_type": "Value"}, "size": {"dtype": "int32", "id": null, "_type": "Value"}, "eid": {"dtype": "string", "id": null, "_type": "Value"}, "original_triple_sets": {"feature": {"otriple_set": {"feature": {"dtype": "string", "id": null, "_type": "Value"}, "length": -1, "id": null, "_type": "Sequence"}}, "length": -1, "id": null, "_type": "Sequence"}, "modified_triple_sets": {"feature": {"mtriple_set": {"feature": {"dtype": "string", "id": null, "_type": "Value"}, "length": -1, "id": null, "_type": "Sequence"}}, "length": -1, "id": null, "_type": "Sequence"}, "shape": {"dtype": "string", "id": null, "_type": "Value"}, "shape_type": {"dtype": "string", "id": null, "_type": "Value"}, "lex": {"feature": {"comment": {"dtype": "string", "id": null, "_type": "Value"}, "lid": {"dtype": "string", "id": null, "_type": "Value"}, "text": {"dtype": "string", "id": null, "_type": "Value"}, "template": {"dtype": "string", "id": null, "_type": "Value"}, "sorted_triple_sets": {"feature": {"dtype": "string", "id": null, "_type": "Value"}, "length": -1, "id": null, "_type": "Sequence"}, "lexicalization": {"dtype": "string", "id": null, "_type": "Value"}}, "length": -1, "id": null, "_type": "Sequence"}}, "post_processed": null, "supervised_keys": null, "builder_name": "enriched_web_nlg", "config_name": "en", "version": {"version_str": "0.0.0", "description": null, "major": 0, "minor": 0, "patch": 0}, "splits": {"train": {"name": "train", "num_bytes": 14665155, "num_examples": 6940, "dataset_name": "enriched_web_nlg"}, "dev": {"name": "dev", "num_bytes": 1843787, "num_examples": 872, "dataset_name": "enriched_web_nlg"}, "test": {"name": "test", "num_bytes": 3931381, "num_examples": 1862, "dataset_name": "enriched_web_nlg"}}, "download_checksums": {"https://github.com/ThiagoCF05/webnlg/archive/12ca34880b225ebd1eb9db07c64e8dd76f7e5784.zip": {"num_bytes": 44284508, "checksum": "624f8c4bc1ef9f59851d92dec1456607ad2b2dc9242e107a4cb62dad774f68cb"}}, "download_size": 44284508, "post_processing_size": null, "dataset_size": 20440323, "size_in_bytes": 64724831}, "de": {"description": "WebNLG is a valuable resource and benchmark for the Natural Language Generation (NLG) community. However, as other NLG benchmarks, it only consists of a collection of parallel raw representations and their corresponding textual realizations. This work aimed to provide intermediate representations of the data for the development and evaluation of popular tasks in the NLG pipeline architecture (Reiter and Dale, 2000), such as Discourse Ordering, Lexicalization, Aggregation and Referring Expression Generation.\n", "citation": "@InProceedings{ferreiraetal2018,\n author = \t\"Castro Ferreira, Thiago and Moussallem, Diego and Wubben, Sander and Krahmer, Emiel\",\n title = \t\"Enriching the WebNLG corpus\",\n booktitle = \t\"Proceedings of the 11th International Conference on Natural Language Generation\",\n year = \t\"2018\",\n series = {INLG'18},\n publisher = \t\"Association for Computational Linguistics\",\n address = \t\"Tilburg, The Netherlands\",\n}\n", "homepage": "https://github.com/ThiagoCF05/webnlg", "license": "CC Attribution-Noncommercial-Share Alike 4.0 International", "features": {"category": {"dtype": "string", "id": null, "_type": "Value"}, "size": {"dtype": "int32", "id": null, "_type": "Value"}, "eid": {"dtype": "string", "id": null, "_type": "Value"}, "original_triple_sets": {"feature": {"otriple_set": {"feature": {"dtype": "string", "id": null, "_type": "Value"}, "length": -1, "id": null, "_type": "Sequence"}}, "length": -1, "id": null, "_type": "Sequence"}, "modified_triple_sets": {"feature": {"mtriple_set": {"feature": {"dtype": "string", "id": null, "_type": "Value"}, "length": -1, "id": null, "_type": "Sequence"}}, "length": -1, "id": null, "_type": "Sequence"}, "shape": {"dtype": "string", "id": null, "_type": "Value"}, "shape_type": {"dtype": "string", "id": null, "_type": "Value"}, "lex": {"feature": {"comment": {"dtype": "string", "id": null, "_type": "Value"}, "lid": {"dtype": "string", "id": null, "_type": "Value"}, "text": {"dtype": "string", "id": null, "_type": "Value"}, "template": {"dtype": "string", "id": null, "_type": "Value"}, "sorted_triple_sets": {"feature": {"dtype": "string", "id": null, "_type": "Value"}, "length": -1, "id": null, "_type": "Sequence"}}, "length": -1, "id": null, "_type": "Sequence"}}, "post_processed": null, "supervised_keys": null, "builder_name": "enriched_web_nlg", "config_name": "de", "version": "0.0.0", "splits": {"train": {"name": "train", "num_bytes": 9748193, "num_examples": 6940, "dataset_name": "enriched_web_nlg"}, "dev": {"name": "dev", "num_bytes": 1238609, "num_examples": 872, "dataset_name": "enriched_web_nlg"}}, "download_checksums": {"https://github.com/ThiagoCF05/webnlg/archive/12ca34880b225ebd1eb9db07c64e8dd76f7e5784.zip": {"num_bytes": 44284508, "checksum": "624f8c4bc1ef9f59851d92dec1456607ad2b2dc9242e107a4cb62dad774f68cb"}}, "download_size": 44284508, "post_processing_size": null, "dataset_size": 10986802, "size_in_bytes": 55271310}}
dummy/de/0.0.0/dummy_data.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:da93454c2c4dce776b7124e74eb70d2cd25c95e1748df91b3a5ecc5c52ce3311
3
+ size 18916
dummy/en/0.0.0/dummy_data.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1c11de10af8b20527fb166dc38116714b79458f64d0aa2835a8d07b3072c473c
3
+ size 34122
enriched_web_nlg.py ADDED
@@ -0,0 +1,237 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2020 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
+ """The Enriched WebNLG corpus"""
16
+
17
+ from __future__ import absolute_import, division, print_function
18
+
19
+ import itertools
20
+ import os
21
+ import xml.etree.cElementTree as ET
22
+ from collections import defaultdict
23
+ from glob import glob
24
+ from os.path import join as pjoin
25
+
26
+ import datasets
27
+
28
+
29
+ _CITATION = """\
30
+ @InProceedings{ferreiraetal2018,
31
+ author = "Castro Ferreira, Thiago and Moussallem, Diego and Wubben, Sander and Krahmer, Emiel",
32
+ title = "Enriching the WebNLG corpus",
33
+ booktitle = "Proceedings of the 11th International Conference on Natural Language Generation",
34
+ year = "2018",
35
+ series = {INLG'18},
36
+ publisher = "Association for Computational Linguistics",
37
+ address = "Tilburg, The Netherlands",
38
+ }
39
+ """
40
+
41
+ _DESCRIPTION = """\
42
+ WebNLG is a valuable resource and benchmark for the Natural Language Generation (NLG) community. However, as other NLG benchmarks, it only consists of a collection of parallel raw representations and their corresponding textual realizations. This work aimed to provide intermediate representations of the data for the development and evaluation of popular tasks in the NLG pipeline architecture (Reiter and Dale, 2000), such as Discourse Ordering, Lexicalization, Aggregation and Referring Expression Generation.
43
+ """
44
+
45
+ _HOMEPAGE = "https://github.com/ThiagoCF05/webnlg"
46
+
47
+ _LICENSE = "CC Attribution-Noncommercial-Share Alike 4.0 International"
48
+
49
+ _SHA = "12ca34880b225ebd1eb9db07c64e8dd76f7e5784"
50
+
51
+ _URL = f"https://github.com/ThiagoCF05/webnlg/archive/{_SHA}.zip"
52
+
53
+ _FILE_PATHS = {
54
+ "en": {
55
+ "train": [f"webnlg-{_SHA}/data/v1.5/en/train/{i}triples/" for i in range(1, 8)],
56
+ "dev": [f"webnlg-{_SHA}/data/v1.5/en/dev/{i}triples/" for i in range(1, 8)],
57
+ "test": [f"webnlg-{_SHA}/data/v1.5/en/test/{i}triples/" for i in range(1, 8)],
58
+ },
59
+ "de": {
60
+ "train": [f"webnlg-{_SHA}/data/v1.5/de/train/{i}triples/" for i in range(1, 8)],
61
+ "dev": [f"webnlg-{_SHA}/data/v1.5/de/dev/{i}triples/" for i in range(1, 8)],
62
+ },
63
+ }
64
+
65
+
66
+ def et_to_dict(tree):
67
+ """Takes the xml tree within a dataset file and returns a dictionary with entry data"""
68
+ dct = {tree.tag: {} if tree.attrib else None}
69
+ children = list(tree)
70
+ if children:
71
+ dd = defaultdict(list)
72
+ for dc in map(et_to_dict, children):
73
+ for k, v in dc.items():
74
+ dd[k].append(v)
75
+ dct = {tree.tag: dd}
76
+ if tree.attrib:
77
+ dct[tree.tag].update((k, v) for k, v in tree.attrib.items())
78
+ if tree.text:
79
+ text = tree.text.strip()
80
+ if children or tree.attrib:
81
+ if text:
82
+ dct[tree.tag]["text"] = text
83
+ else:
84
+ dct[tree.tag] = text
85
+ return dct
86
+
87
+
88
+ def parse_entry(entry, config_name):
89
+ """Takes the dictionary corresponding to an entry and returns a dictionary with:
90
+ - Proper feature naming
91
+ - Default values
92
+ - Proper typing"""
93
+ res = {}
94
+ otriple_set_list = entry["originaltripleset"]
95
+ res["original_triple_sets"] = [{"otriple_set": otriple_set["otriple"]} for otriple_set in otriple_set_list]
96
+ mtriple_set_list = entry["modifiedtripleset"]
97
+ res["modified_triple_sets"] = [{"mtriple_set": mtriple_set["mtriple"]} for mtriple_set in mtriple_set_list]
98
+ res["category"] = entry["category"]
99
+ res["eid"] = entry["eid"]
100
+ res["size"] = int(entry["size"])
101
+ lex = entry["lex"]
102
+ # Some entries are misformed, with None instead of the sorted triplet information.
103
+ entry_triples = [
104
+ ex["sortedtripleset"][0] if ex["sortedtripleset"][0] is not None else {"sentence": []} for ex in lex
105
+ ]
106
+ # the xml structure is inconsistent; sorted triplets are often separated in several dictionaries, so we sum them.
107
+ sorted_triples = [
108
+ list(itertools.chain.from_iterable(item.get("striple", []) for item in entry["sentence"]))
109
+ for entry in entry_triples
110
+ ]
111
+ res["lex"] = {
112
+ "comment": [ex.get("comment", "") for ex in lex],
113
+ "lid": [ex.get("lid", "") for ex in lex],
114
+ # all of the sequence are within their own 1-element sublist, thus the [0]
115
+ "text": [ex.get("text", [""])[0] for ex in lex],
116
+ "template": [ex.get("template", [""])[0] for ex in lex],
117
+ "sorted_triple_sets": sorted_triples,
118
+ }
119
+ # only present in the en version
120
+ if config_name == "en":
121
+ res["lex"]["lexicalization"] = [ex.get("lexicalization", [""])[0] for ex in lex]
122
+ res["shape"] = entry.get("shape", "")
123
+ res["shape_type"] = entry.get("shape_type", "")
124
+ return res
125
+
126
+
127
+ def xml_file_to_examples(filename, config_name):
128
+ tree = ET.parse(filename).getroot()
129
+ examples = et_to_dict(tree)["benchmark"]["entries"][0]["entry"]
130
+ return [parse_entry(entry, config_name) for entry in examples]
131
+
132
+
133
+ class EnrichedWebNlg(datasets.GeneratorBasedBuilder):
134
+ """The WebNLG corpus"""
135
+
136
+ VERSION = datasets.Version("1.5.0")
137
+
138
+ BUILDER_CONFIGS = [
139
+ datasets.BuilderConfig(name="en", description="Enriched English version of the WebNLG data"),
140
+ datasets.BuilderConfig(name="de", description="Enriched German version of the WebNLG data"),
141
+ ]
142
+
143
+ def _info(self):
144
+ if self.config.name == "en":
145
+ features = datasets.Features(
146
+ {
147
+ "category": datasets.Value("string"),
148
+ "size": datasets.Value("int32"),
149
+ "eid": datasets.Value("string"),
150
+ "original_triple_sets": datasets.Sequence(
151
+ {"otriple_set": datasets.Sequence(datasets.Value("string"))}
152
+ ),
153
+ "modified_triple_sets": datasets.Sequence(
154
+ {"mtriple_set": datasets.Sequence(datasets.Value("string"))}
155
+ ),
156
+ "shape": datasets.Value("string"),
157
+ "shape_type": datasets.Value("string"),
158
+ "lex": datasets.Sequence(
159
+ {
160
+ "comment": datasets.Value("string"),
161
+ "lid": datasets.Value("string"),
162
+ "text": datasets.Value("string"),
163
+ "template": datasets.Value("string"),
164
+ "sorted_triple_sets": datasets.Sequence(datasets.Value("string")),
165
+ # only present in the en version
166
+ "lexicalization": datasets.Value("string"),
167
+ }
168
+ ),
169
+ }
170
+ )
171
+ else:
172
+ features = datasets.Features(
173
+ {
174
+ "category": datasets.Value("string"),
175
+ "size": datasets.Value("int32"),
176
+ "eid": datasets.Value("string"),
177
+ "original_triple_sets": datasets.Sequence(
178
+ {"otriple_set": datasets.Sequence(datasets.Value("string"))}
179
+ ),
180
+ "modified_triple_sets": datasets.Sequence(
181
+ {"mtriple_set": datasets.Sequence(datasets.Value("string"))}
182
+ ),
183
+ "shape": datasets.Value("string"),
184
+ "shape_type": datasets.Value("string"),
185
+ "lex": datasets.Sequence(
186
+ {
187
+ "comment": datasets.Value("string"),
188
+ "lid": datasets.Value("string"),
189
+ "text": datasets.Value("string"),
190
+ "template": datasets.Value("string"),
191
+ "sorted_triple_sets": datasets.Sequence(datasets.Value("string")),
192
+ }
193
+ ),
194
+ }
195
+ )
196
+ return datasets.DatasetInfo(
197
+ # This is the description that will appear on the datasets page.
198
+ description=_DESCRIPTION,
199
+ # This defines the different columns of the dataset and their types
200
+ features=features, # Here we define them above because they are different between the two configurations
201
+ # If there's a common (input, target) tuple from the features,
202
+ # specify them here. They'll be used if as_supervised=True in
203
+ # builder.as_dataset.
204
+ supervised_keys=None,
205
+ # Homepage of the dataset for documentation
206
+ homepage=_HOMEPAGE,
207
+ citation=_CITATION,
208
+ license=_LICENSE,
209
+ )
210
+
211
+ def _split_generators(self, dl_manager):
212
+ """Returns SplitGenerators."""
213
+ data_dir = dl_manager.download_and_extract(_URL)
214
+ # Downloading the repo adds the current commit sha to the directory, so we can't specify the directory
215
+ # name in advance.
216
+ split_files = {
217
+ split: [os.path.join(data_dir, dir_suf) for dir_suf in dir_suffix_list]
218
+ for split, dir_suffix_list in _FILE_PATHS[self.config.name].items()
219
+ }
220
+ return [
221
+ datasets.SplitGenerator(
222
+ name=split,
223
+ # These kwargs will be passed to _generate_examples
224
+ gen_kwargs={"filedirs": filedirs},
225
+ )
226
+ for split, filedirs in split_files.items()
227
+ ]
228
+
229
+ def _generate_examples(self, filedirs):
230
+ """ Yields examples. """
231
+
232
+ id_ = 0
233
+ for xml_location in filedirs:
234
+ for xml_file in sorted(glob(pjoin(xml_location, "*.xml"))):
235
+ for exple_dict in xml_file_to_examples(xml_file, self.config.name):
236
+ id_ += 1
237
+ yield id_, exple_dict