patriziobellan commited on
Commit
0d0350d
1 Parent(s): 6de4ab8

Upload 2 files

Browse files
Files changed (2) hide show
  1. PETv11.py +234 -0
  2. README.md +64 -1
PETv11.py ADDED
@@ -0,0 +1,234 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import csv
2
+ import json
3
+ import os
4
+
5
+ import datasets
6
+
7
+
8
+ # Find for instance the citation on arxiv or on the dataset repo/website
9
+ _CITATION = """\
10
+ @inproceedings{DBLP:conf/bpm/BellanADGP22,
11
+ author = {Patrizio Bellan and
12
+ Han van der Aa and
13
+ Mauro Dragoni and
14
+ Chiara Ghidini and
15
+ Simone Paolo Ponzetto},
16
+ editor = {Cristina Cabanillas and
17
+ Niels Frederik Garmann{-}Johnsen and
18
+ Agnes Koschmider},
19
+ title = {{PETv11:} An Annotated Dataset for Process Extraction from Natural Language
20
+ Text Tasks},
21
+ booktitle = {Business Process Management Workshops - {BPM} 2022 International Workshops,
22
+ M{\"{u}}nster, Germany, September 11-16, 2022, Revised Selected
23
+ Papers},
24
+ series = {Lecture Notes in Business Information Processing},
25
+ volume = {460},
26
+ pages = {315--321},
27
+ publisher = {Springer},
28
+ year = {2022},
29
+ url = {https://doi.org/10.1007/978-3-031-25383-6\_23},
30
+ doi = {10.1007/978-3-031-25383-6\_23},
31
+ timestamp = {Tue, 14 Feb 2023 09:47:10 +0100},
32
+ biburl = {https://dblp.org/rec/conf/bpm/BellanADGP22.bib},
33
+ bibsource = {dblp computer science bibliography, https://dblp.org}
34
+ }
35
+ @inproceedings{DBLP:conf/aiia/BellanGDPA22,
36
+ author = {Patrizio Bellan and
37
+ Chiara Ghidini and
38
+ Mauro Dragoni and
39
+ Simone Paolo Ponzetto and
40
+ Han van der Aa},
41
+ editor = {Debora Nozza and
42
+ Lucia C. Passaro and
43
+ Marco Polignano},
44
+ title = {Process Extraction from Natural Language Text: the {PETv11} Dataset and
45
+ Annotation Guidelines},
46
+ booktitle = {Proceedings of the Sixth Workshop on Natural Language for Artificial
47
+ Intelligence {(NL4AI} 2022) co-located with 21th International Conference
48
+ of the Italian Association for Artificial Intelligence (AI*IA 2022),
49
+ Udine, November 30th, 2022},
50
+ series = {{CEUR} Workshop Proceedings},
51
+ volume = {3287},
52
+ pages = {177--191},
53
+ publisher = {CEUR-WS.org},
54
+ year = {2022},
55
+ url = {https://ceur-ws.org/Vol-3287/paper18.pdf},
56
+ timestamp = {Fri, 10 Mar 2023 16:23:01 +0100},
57
+ biburl = {https://dblp.org/rec/conf/aiia/BellanGDPA22.bib},
58
+ bibsource = {dblp computer science bibliography, https://dblp.org}
59
+ }
60
+
61
+ """
62
+
63
+ # You can copy an official description
64
+ _DESCRIPTION = """\
65
+ Abstract. Although there is a long tradition of work in NLP on extracting entities and relations from text, to date there exists little work on the acquisition of business processes from unstructured data such as textual corpora of process descriptions. With this work we aim at filling this gap and establishing the first steps towards bridging data-driven information extraction methodologies from Natural Language Processing and the model-based formalization that is aimed from Business Process Management. For this, we develop the first corpus of business process descriptions annotated with activities, gateways, actors and flow information. We present our new resource, including a detailed overview of the annotation schema and guidelines, as well as a variety of baselines to benchmark the difficulty and challenges of business process extraction from text.
66
+ """
67
+
68
+ _HOMEPAGE = "https://pdi.fbk.eu/pet-dataset/"
69
+
70
+ _LICENSE = "MIT"
71
+
72
+ _URL_11 = "https://raw.githubusercontent.com/patriziobellan86/PETv1.1/master/"
73
+ _URL_10 = "https://pdi.fbk.eu/pet/PETHuggingFace/"
74
+ _TEST_FILE_11 = "PETv1.1-entities.jsonl"
75
+ # _TEST_FILE_10 = "test.json"
76
+ _TEST_FILE_RELATIONS_11 = "PETv1.1-relations.json"
77
+ # _TEST_FILE_RELATIONS_10 = 'PETrelations.json'
78
+
79
+ _NER = 'token-classification'
80
+ # _NER_11 = 'token-classification-v1.1'
81
+ _RELATIONS_EXTRACTION = 'relations-extraction'
82
+ # _RELATIONS_EXTRACTION_11 = 'relations-extraction-v1.1'
83
+
84
+ _NER_TAGS = [ "O",
85
+ "B-Actor",
86
+ "I-Actor",
87
+ "B-Activity",
88
+ "I-Activity",
89
+ "B-Activity Data",
90
+ "I-Activity Data",
91
+ "B-Further Specification",
92
+ "I-Further Specification",
93
+ "B-XOR Gateway",
94
+ "I-XOR Gateway",
95
+ "B-Condition Specification",
96
+ "I-Condition Specification",
97
+ "B-AND Gateway",
98
+ "I-AND Gateway"]
99
+
100
+ _STR_PET = """\n
101
+ _______ _ _ _______ _____ _______ _______ ______ _______ _______ _______ _______ _______ _______
102
+ | |_____| |______ |_____] |______ | | \ |_____| | |_____| |______ |______ |
103
+ | | | |______ | |______ | |_____/ | | | | | ______| |______ |
104
+
105
+ Discover more at: [https://pdi.fbk.eu/pet-dataset/]
106
+ """
107
+
108
+
109
+ class PETConfig(datasets.BuilderConfig):
110
+ """The PETv11 Dataset."""
111
+
112
+ def __init__(self, **kwargs):
113
+ """BuilderConfig for PETv11.
114
+ Args:
115
+ **kwargs: keyword arguments forwarded to super.
116
+ """
117
+ super(PETConfig, self).__init__(**kwargs)
118
+
119
+
120
+ class PETv11(datasets.GeneratorBasedBuilder):
121
+ """PETv11 DATASET."""
122
+
123
+ features_ner = {
124
+ "document name": datasets.Value("string"),
125
+ "sentence-ID": datasets.Value("int8"),
126
+ "tokens": datasets.Sequence(datasets.Value("string")),
127
+ "ner-tags": datasets.Sequence(datasets.features.ClassLabel(names=_NER_TAGS)),
128
+ }
129
+
130
+ features_relations = datasets.Sequence(
131
+ datasets.Features(
132
+
133
+ {
134
+ 'source-head-sentence-ID': datasets.Value("int8"),
135
+ 'source-head-word-ID': datasets.Value("int8"),
136
+ 'relation-type': datasets.Value("string"),
137
+ 'target-head-sentence-ID': datasets.Value("int8"),
138
+ 'target-head-word-ID' : datasets.Value("int8"),
139
+ }
140
+ ))
141
+ BUILDER_CONFIGS = [ PETConfig(
142
+ name=_NER,
143
+ version=datasets.Version("1.1.0"),
144
+ description="The PETv11 Dataset for Token Classification"
145
+ ),
146
+ PETConfig(
147
+ name=_RELATIONS_EXTRACTION,
148
+ version=datasets.Version("1.1.0"),
149
+ description="The PETv11 Dataset for Relation Extraction"
150
+ ),
151
+
152
+ ]
153
+
154
+ DEFAULT_CONFIG_NAME = _RELATIONS_EXTRACTION
155
+
156
+ def _info(self):
157
+ print(_STR_PET)
158
+ if self.config.name == _NER:
159
+ features = datasets.Features(self.features_ner)
160
+ else:
161
+ features = datasets.Features(
162
+ {
163
+ "document name": datasets.Value("string"),
164
+ 'tokens':datasets.Sequence(datasets.Value("string")),
165
+ 'tokens-IDs':datasets.Sequence(datasets.Value("int8")),
166
+ 'ner_tags': datasets.Sequence(datasets.Value("string")),
167
+ 'sentence-IDs':datasets.Sequence(datasets.Value("int8")),
168
+ "relations": self.features_relations
169
+ }
170
+ )
171
+ # print(features)
172
+ return datasets.DatasetInfo(
173
+ description=_DESCRIPTION,
174
+ features=datasets.Features(features),
175
+ homepage=_HOMEPAGE,
176
+ license=_LICENSE,
177
+ citation=_CITATION,
178
+ )
179
+
180
+ def _split_generators(self, dl_manager):
181
+ print(f"{self.config.version}")
182
+ if self.config.name == _NER:
183
+ urls_to_download = {
184
+ "test": f"{_URL_11}{_TEST_FILE_11}",
185
+ }
186
+
187
+ downloaded_files = dl_manager.download_and_extract(urls_to_download)
188
+ return [datasets.SplitGenerator(
189
+ name=datasets.Split.TEST,
190
+ # These kwargs will be passed to _generate_examples
191
+ gen_kwargs={
192
+ "filepath": downloaded_files["test"],
193
+ "split": "test"
194
+ },
195
+ )]
196
+
197
+ else:
198
+ urls_to_download = {
199
+ "test": f"{_URL_11}{_TEST_FILE_RELATIONS_11}",
200
+ }
201
+
202
+ downloaded_files = dl_manager.download_and_extract(urls_to_download)
203
+ return [datasets.SplitGenerator(
204
+ name=datasets.Split.TEST,
205
+ # These kwargs will be passed to _generate_examples
206
+ gen_kwargs={
207
+ "filepath": downloaded_files["test"],
208
+ "split": "test"
209
+ },
210
+ )]
211
+
212
+
213
+ def _generate_examples(self, filepath, split):
214
+ if self.config.name == _NER:
215
+ with open(filepath, encoding="utf-8", mode='r') as f:
216
+ for key, row in enumerate(f):
217
+ row = json.loads(row)
218
+ yield key, {
219
+ "document name": row["document name"],
220
+ "sentence-ID": row["sentence-ID"],
221
+ "tokens": row["tokens"],
222
+ "ner-tags": row["ner-tags"]
223
+ }
224
+ else:
225
+ with open(filepath, encoding="utf-8", mode='r') as f:
226
+ for key, row in enumerate(json.load(f)):
227
+ yield key, {"document name": row["document name"],
228
+ 'tokens': row["tokens"],
229
+ 'tokens-IDs': row["tokens-IDs"],
230
+ 'ner_tags': row["ner_tags"],
231
+ 'sentence-IDs': row["sentence-IDs"],
232
+
233
+ "relations": row["relations"]
234
+ }
README.md CHANGED
@@ -1,3 +1,66 @@
1
  ---
2
- license: mit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  ---
 
1
  ---
2
+ dataset_info:
3
+ - config_name: token-classification
4
+ features:
5
+ - name: document name
6
+ dtype: string
7
+ - name: sentence-ID
8
+ dtype: int8
9
+ - name: tokens
10
+ sequence: string
11
+ - name: ner-tags
12
+ sequence:
13
+ class_label:
14
+ names:
15
+ '0': O
16
+ '1': B-Actor
17
+ '2': I-Actor
18
+ '3': B-Activity
19
+ '4': I-Activity
20
+ '5': B-Activity Data
21
+ '6': I-Activity Data
22
+ '7': B-Further Specification
23
+ '8': I-Further Specification
24
+ '9': B-XOR Gateway
25
+ '10': I-XOR Gateway
26
+ '11': B-Condition Specification
27
+ '12': I-Condition Specification
28
+ '13': B-AND Gateway
29
+ '14': I-AND Gateway
30
+ splits:
31
+ - name: test
32
+ num_bytes: 132893
33
+ num_examples: 417
34
+ download_size: 187158
35
+ dataset_size: 132893
36
+ - config_name: relations-extraction
37
+ features:
38
+ - name: document name
39
+ dtype: string
40
+ - name: tokens
41
+ sequence: string
42
+ - name: tokens-IDs
43
+ sequence: int8
44
+ - name: ner_tags
45
+ sequence: string
46
+ - name: sentence-IDs
47
+ sequence: int8
48
+ - name: relations
49
+ sequence:
50
+ - name: source-head-sentence-ID
51
+ dtype: int8
52
+ - name: source-head-word-ID
53
+ dtype: int8
54
+ - name: relation-type
55
+ dtype: string
56
+ - name: target-head-sentence-ID
57
+ dtype: int8
58
+ - name: target-head-word-ID
59
+ dtype: int8
60
+ splits:
61
+ - name: test
62
+ num_bytes: 203379
63
+ num_examples: 45
64
+ download_size: 760012
65
+ dataset_size: 203379
66
  ---