Datasets:

Modalities:
Text
Languages:
English
Libraries:
Datasets
License:
asahi417 commited on
Commit
373bd8e
1 Parent(s): 42d8b59

fix readme

Browse files
.gitattributes CHANGED
@@ -79,3 +79,4 @@ data/t_rex.filter.min_entity_12_max_predicate_10.jsonl filter=lfs diff=lfs merge
79
  data/t_rex.filter.min_entity_16_max_predicate_100.jsonl filter=lfs diff=lfs merge=lfs -text
80
  data/t_rex.filter.min_entity_4_max_predicate_25.jsonl filter=lfs diff=lfs merge=lfs -text
81
  data/t_rex.filter.min_entity_8_max_predicate_25.jsonl filter=lfs diff=lfs merge=lfs -text
 
 
79
  data/t_rex.filter.min_entity_16_max_predicate_100.jsonl filter=lfs diff=lfs merge=lfs -text
80
  data/t_rex.filter.min_entity_4_max_predicate_25.jsonl filter=lfs diff=lfs merge=lfs -text
81
  data/t_rex.filter.min_entity_8_max_predicate_25.jsonl filter=lfs diff=lfs merge=lfs -text
82
+ data/t_rex.filter_unified.jsonl filter=lfs diff=lfs merge=lfs -text
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ data_raw
README.md CHANGED
@@ -21,12 +21,13 @@ We split the raw T-REX dataset into train/validation/test split by the ratio of
21
  ### Filtering to Remove Noise
22
 
23
  We apply filtering to keep triples with alpha-numeric subject and object, as well as triples with at least either of subject or object is a named-entity.
 
24
 
25
- | Dataset | Raw | Filter |
26
- |--------:|----:|-------:|
27
- | Triples | 941,663 | 662,482 |
28
- | Predicate| 931 | 818 |
29
- | Entity | 270,801 | 197,302 |
30
 
31
  ### Filtering to Purify the Dataset
32
  We reduce the size of the dataset by applying filtering based on the number of predicates and entities in the triples.
@@ -54,11 +55,11 @@ we choose top-`max predicate` triples based on the frequency of the subject and
54
 
55
  - distribution of entities
56
 
57
- <img src="https://huggingface.co/datasets/relbert/t_rex/resolve/main/data/stats.entity_distribution.png" alt="" width="500" style="margin-left:'auto' margin-right:'auto' display:'block'"/>
58
 
59
  - distribution of predicates
60
 
61
- <img src="https://huggingface.co/datasets/relbert/t_rex/resolve/main/data/stats.predicate_distribution.png" alt="" width="500" style="margin-left:'auto' margin-right:'auto' display:'block'"/>
62
 
63
 
64
  ## Dataset Structure
 
21
  ### Filtering to Remove Noise
22
 
23
  We apply filtering to keep triples with alpha-numeric subject and object, as well as triples with at least either of subject or object is a named-entity.
24
+ After the filtering, we manually remove too vague and noisy predicate, and unify same predicates with different names.
25
 
26
+ | Dataset | Raw | Filter | Unification |
27
+ |----------:|----------:|----------:|--------------:|
28
+ | Triples | 941,663 | 583,333 | 432,795 |
29
+ | Predicate | 931 | 659 | 247 |
30
+ | Entity | 270,801 | 197,163 | 149,172 |
31
 
32
  ### Filtering to Purify the Dataset
33
  We reduce the size of the dataset by applying filtering based on the number of predicates and entities in the triples.
 
55
 
56
  - distribution of entities
57
 
58
+ <img src="https://huggingface.co/datasets/relbert/t_rex/resolve/main/data/stats.entity_distribution.png" alt="" width="600" style="margin-left:'auto' margin-right:'auto' display:'block'"/>
59
 
60
  - distribution of predicates
61
 
62
+ <img src="https://huggingface.co/datasets/relbert/t_rex/resolve/main/data/stats.predicate_distribution.png" alt="" width="600" style="margin-left:'auto' margin-right:'auto' display:'block'"/>
63
 
64
 
65
  ## Dataset Structure
check_predicate.py DELETED
@@ -1,11 +0,0 @@
1
- import json
2
- import pandas as pd
3
-
4
- with open("data/t_rex.filter.jsonl") as f:
5
- data = pd.DataFrame([json.loads(i) for i in f.read().split('\n') if len(i) > 0])
6
- freq = data.groupby("predicate").count()['title']
7
- data['freq'] = [freq.loc[i] for i in data['predicate']]
8
- tmp = data.groupby("predicate").sample(10, replace=True)
9
- tmp = tmp.drop_duplicates()
10
- tmp.to_csv("data/t_rex.filter.predicate_check_sample.csv", index=False)
11
-
 
 
 
 
 
 
 
 
 
 
 
 
data/t_rex.filter.jsonl CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:1b80224241efafb2b053bc630288a3adfbaf69422454b57c620c6f810da20aee
3
- size 603995857
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ce5fdbf59ad4aaa7de18198863aa1d1b9e451386748f0a854b3b7ab1bff7f79f
3
+ size 502849464
data/t_rex.filter_unified.jsonl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c0aeaa043780559579cc3326e9eb923e09de1842590add1b1d92e4b19454f586
3
+ size 408520515
filtering_denoise.py DELETED
@@ -1,47 +0,0 @@
1
- import json
2
- import string
3
- import re
4
-
5
- stopwords = ["he", "she", "they", "it"]
6
- list_alnum = string.ascii_lowercase + '0123456789 '
7
-
8
-
9
- def filtering(entry):
10
-
11
- def _subfilter(token):
12
- if len(re.findall(rf'[^{list_alnum}]+', token)) != 0:
13
- return False
14
- if token in stopwords:
15
- return False
16
- if token.startswith("www"):
17
- return False
18
- if token.startswith("."):
19
- return False
20
- if token.startswith(","):
21
- return False
22
- if token.startswith("$"):
23
- return False
24
- if token.startswith("+"):
25
- return False
26
- if token.startswith("#"):
27
- return False
28
- return True
29
-
30
- if not _subfilter(entry["object"].lower()):
31
- return False
32
- if not _subfilter(entry["subject"].lower()):
33
- return False
34
-
35
- if entry['object'].islower() and entry['subject'].islower():
36
- return False
37
-
38
- return True
39
-
40
-
41
- with open(f"data/t_rex.raw.jsonl") as f:
42
- data = [json.loads(i) for i in f.read().split('\n') if len(i) > 0]
43
- print(f"[before]: {len(data)}")
44
- data = [i for i in data if filtering(i)]
45
- print(f"[after] : {len(data)}")
46
- with open(f"data/t_rex.filter.jsonl", 'w') as f:
47
- f.write('\n'.join([json.dumps(i) for i in data]))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
predicate_manual_check.csv ADDED
@@ -0,0 +1,660 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ unique predicates,ok,pretty relation name,pretty relation name is reverse,same as,reverse of,remove (noisy),remove (too vague)
2
+ abolished,,,,ending,,,
3
+ academic discipline,,,,discipline,,,
4
+ studies,x,[Academic Subject] studies [Topic],,,,,
5
+ actor,,,,film starring,,,
6
+ actress,,,,film starring,,,
7
+ signatory,x,[Act] is signed by [Person],,,,,
8
+ adjacent to,,,,next to,,,
9
+ administered by,,,,maintained by,,,
10
+ maiden flight,x,[Aircraft] makes the maiden flight on [Date],,,,,
11
+ advisor,,,,studied at,,,
12
+ hub,x,[Airline] has a hub in [Location],,,,,
13
+ airline alliance,x,[Airline] is in [Airline Alliance],,,,,
14
+ alma mater,,,,studied at,,,
15
+ fleet,x,[Army] has [Fleet],,,,,
16
+ alumni of,,,,studied at,,,
17
+ alumnus of,,,,studied at,,,
18
+ amalgamation of,,,,,,x,
19
+ garrison,x,[Army] is based in [Location],,,,,
20
+ series,x,[Art Work] follows after [Art Work],,,,,
21
+ painting of,x,[Art Work] is a painting of [Person],,,,,
22
+ architect,,,,architectural style,,,
23
+ translation of,x,[Art Work] is a translation of [Art Work],,,,,
24
+ arena,,,,home field,,,
25
+ artery,,,,,,x,
26
+ artist,,,,,,x,
27
+ artists,,,,,,x,
28
+ aspect of,,,,,,x,
29
+ assassin,,,,murdered by,,,
30
+ assassinated by,,,,murdered by,,,
31
+ adapted from,x,[Art Work] is adapted from [Art Work],,,,,
32
+ assembly of,,,,,assembly,,
33
+ director,x,[Art Work] is directed by [Person],,,,,
34
+ painter,x,[Art Work] is painted by [Person],,,,,
35
+ published in,x,[Art Work] is published in [Magazine],,,,,
36
+ authority,,,,council,,,
37
+ published,x,[Art Work] is published on [Date],,,,,
38
+ awarded,,,,award,,,
39
+ awarded by,,,,,award,,
40
+ awards,,,,award,,,
41
+ sculptor,x,[Art Work] is sculpted by [Person],,,,,
42
+ band,,,,music by,,,
43
+ based on,,,,series,,,
44
+ battle,,,,war,,,
45
+ began,,,,starting,,,
46
+ beginning,,,,starting,,,
47
+ belongs to,,,,,divisions,,
48
+ bestowed by,,,,founder,,,
49
+ author,x,[Art Work] is written by [Person],,,,,
50
+ engine,x,[Artifact] has [Engine],,,,,
51
+ birthday,,,,birth place,,,
52
+ birthplace,,,,birth date,,,
53
+ book by,,,,author,,,
54
+ border,,,,next to,,,
55
+ bordered by,,,,next to,,,
56
+ borders,,,,next to,,,
57
+ born at,,,,birth place,,,
58
+ born in,,,,birth place,,,
59
+ born on,,,,birth date,,,
60
+ boyfriend,,,,,husband,,
61
+ branch,,,,sector,,,
62
+ brand,,,,,product,,
63
+ shape,x,[Artifact] has a shape of [Shape],,,,,
64
+ coat of arms,x,[Artifact] is a coat of arms of [Group],x,,,,
65
+ motif,x,[Artifact] is a motif for [Art Work],x,,,,
66
+ built by,,,,builder,,,
67
+ built from,,,,constructed from,,,
68
+ burial place,,,,tomb,,,
69
+ buried in,,,,tomb,,,
70
+ patron saint,x,[Artifact] is a patron saint of [Country],x,,,,
71
+ capital,,,,,capital of,,
72
+ capital city,,,,,capital of,,
73
+ result,x,[Artifact] is a result of [Artifact],,,,,
74
+ type of,x,[Artifact] is a type of [Type],,,,,
75
+ career,,,,job,,,
76
+ edition of,x,[Artifact] is a version of [Artifact],,,,,
77
+ cartridge,,,,,,x,
78
+ cast member,,,,film starring,,,
79
+ established,x,[Artifact] is built on [Date],,,,,
80
+ cause,,,,caused by,,,
81
+ cause of,,,,,caused by,,
82
+ discoverer,x,[Artifact] is discovered by [Person],,,,,
83
+ formation,x,[Artifact] is formation of [Army],,,,,
84
+ CEO,,,,chief executive,,,
85
+ formed from,x,[Artifact] is formed from [Artifact],,,,,
86
+ chairperson,,,,chairman,,,
87
+ contained within,x,[Artifact] is found in [Artifact],,,,,
88
+ colour,x,[Artifact] is in [Color],,,,,
89
+ channel,,,,broadcast on,,,
90
+ influenced by,x,[Artifact] is influenced by [Artifact],,,,,
91
+ listing,x,[Artifact] is listed in [List],,,,,
92
+ chief executive officer,,,,chief executive,,,
93
+ children,,,,,father,,
94
+ maintained by,x,[Artifact] is maintained by [Company],,,,,
95
+ chromosome,,,,,,x,
96
+ manufacturer,x,[Artifact] is manufactured by [Company],,,,,
97
+ citizen of,,,,residence,,,
98
+ citizenship,,,,residence,,,
99
+ named for,x,[Artifact] is name of [Artifact],,,,,
100
+ city council,,,,council,,,
101
+ named after,x,[Artifact] is named after [Person],,,,,
102
+ operating system,x,[Artifact] is the OS of [Software],,,,,
103
+ co-driver,,,,,,x,
104
+ coach,,,,head coach,,,
105
+ platform,x,[Artifact] is the platform of [Game],x,,,,
106
+ used by,x,[Artifact] is used by [Person],,,,,
107
+ namesake,x,[Artifact] is used for its namesake of [Artifact],,,,,
108
+ color,,,,colour,,,
109
+ producer,x,[Artist] is produced by [Person],,,,,
110
+ movement,x,[Artists] leads [Movement],,,,,
111
+ commissioned by,,,,producer,,,
112
+ compiled by,,,,,,x,
113
+ composed by,,,,music by,,,
114
+ athletes,x,[Athlete] joins [Competition],x,,,,
115
+ composer,,,,music by,,,
116
+ presented by,x,[Award] is presented by [Company],,,,,
117
+ conflict,,,,,,x,
118
+ connected with,,,,,,x,
119
+ conservation status,,,,,,x,
120
+ central bank,x,[Bank] is the central bank of [Country],x,,,,
121
+ carries,x,[Bridge] crosses [Artifact],,,,,
122
+ bridge over,x,[Bridge] crosses [River],,,,,
123
+ architectural style,x,[Building] has an architectural style of [Person],,,,,
124
+ contains,,,,is in,,,
125
+ constructed from,x,[Building] is built from [Material],,,,,
126
+ cathedral,x,[Cathedral] is in [City],x,,,,
127
+ costume designer,,,,,work,,
128
+ ore,x,[Chemical Material] is made from [Stone],,,,,
129
+ country,,,,,made from,,
130
+ country of origin,,,,,,x,
131
+ capital town,x,[City] is a capital town of [Country],x,,,,
132
+ county seat of,,,,,county seat,,
133
+ twin city,x,[City] is a twin city of [City],,,,,
134
+ craft,,,,job,,,
135
+ city,x,[City] is in [Country],,,,,
136
+ created by,,,,,work,,
137
+ created from,,,,formed from,,,
138
+ creator,,,,,work,,
139
+ crosses,,,,,carries,,
140
+ capital of,x,[City] is the capital of [Country],,,,,
141
+ HQ,x,[Company] has the headquarter in [Location],,,,,
142
+ divisions,x,[Company] is a subsidiary of [Company],x,,,,
143
+ sector,x,[Company] is in a sector of [Sector],,,,,
144
+ dad,,,,father,,,
145
+ daughter,,,,,father,,
146
+ daughters,,,,,father,,
147
+ dead,,,,died on,,,
148
+ death,,,,died on,,,
149
+ operated by,x,[Company] operates [Vehicle],,,,,
150
+ product,x,[Company] owns [Product],,,,,
151
+ publisher,x,[Company] publishes [Art Work],,,,,
152
+ depicts,,,,painting of,,,
153
+ derived from,,,,,,x,
154
+ designation,,,x,,,,
155
+ designed by,,,,,work,,
156
+ designer,,,,,work,,
157
+ sport,x,[Competition] is a league of [Sport],,,,,
158
+ developer,,,,developed by,,,
159
+ topic,x,[Conference] is about [Topic],,,,,
160
+ council,x,[Council] is the council of [Country],x,,,,
161
+ claimed by,x,[Country] claims [City],x,,,,
162
+ diet,,,,,,x,
163
+ diocese,,,,,,x,
164
+ diplomatic relation,,,,,,x,
165
+ directed by,,,,director,,,
166
+ history,x,[Country] has [History],,,,,
167
+ director of photography,,,,director,,,
168
+ assembly,x,[Country] is [Political Party] assembly,,,,,
169
+ disciple,,,,,student of,,
170
+ disciple of,,,,student of,,,
171
+ disciples,,,,,student of,,
172
+ member of,x,[Country] is a member of [Group],,,,,
173
+ discography,,,,,,x,
174
+ discovered by,,,,discoverer,,,
175
+ enclave within,x,[Country] is enclaved by [Country],,,,,
176
+ disestablished,,,,,,x,
177
+ continent,x,[Country] is in [Continent],,,,,
178
+ distinct from,,,,,,x,
179
+ distributed by,,,,film studio,,,
180
+ distribution,,,,,,x,
181
+ distributor,,,,film studio,,,
182
+ divided into,,,,,city,,
183
+ division,,,,sports league,,,
184
+ athlete,x,[Country] joins [War],x,,,,
185
+ county seat,x,[Country]'s county seat is [Location],,,,,
186
+ flag,x,[Country]'s flag is [Artifact],,,,,
187
+ culture,x,[Culture] is originated in [Country],x,,,,
188
+ edited by,,,,author,,,
189
+ currency,x,[Currency] is used in [Country],x,,,,
190
+ editions,,,,,,x,
191
+ editor,,,,author,,,
192
+ educated at,,,,studied at,,,
193
+ education,,,,studied at,,,
194
+ effect,,,,,,x,
195
+ symptoms,x,[Disease] has [Symptoms],,,,,
196
+ employed by,,,,works at,,,
197
+ employment,,,,job,,,
198
+ caused by,x,[Disease] is caused by [Virus],,,,,
199
+ precedes,x,[Era] comes before [Era],,,,,
200
+ endemic to,,,,,,x,
201
+ ending,x,[Event] ends on [Date],,,,,
202
+ time,x,[Event] happens on [Date],,,,,
203
+ epoch,,,,era,,,
204
+ since,x,[Event] is since [Date],,,,,
205
+ starting,x,[Event] starts on [Date],,,,,
206
+ ethnic group,,,,,,x,
207
+ ethnicity,,,,nationality,,,
208
+ event,,,,took part,,,
209
+ took part,x,[Event] takes place at [Location],x,,,,
210
+ executive body,,,,government,,,
211
+ executive branch,,,,government,,,
212
+ executive producer,,,,film studio,,,
213
+ faith,,,,religion,,,
214
+ family,,,,,,x,
215
+ famous works,,,,work,,,
216
+ mascot,x,[Fictional Character] is a mascot of [Sport Team],x,,,,
217
+ fields,,,,discipline,,,
218
+ film director,,,,director,,,
219
+ film editor,,,,author,,,
220
+ characters,x,[Fictional Character] is from [Art Work] ,x,,,,
221
+ film producer,,,,film studio,,,
222
+ made from,x,[Food] is made from [Ingredient],,,,,
223
+ cuisine,x,[Food] is originated in [Country],,,,,
224
+ fruit of,x,[Fruit] is [Type],,,,,
225
+ video game publisher,x,[Game] is produced by [Company],,,,,
226
+ first language,,,,native language,,,
227
+ deity of,x,[God] is the god of [Religion],,,,,
228
+ government,x,[Government] is the government of [Country],x,,,,
229
+ jurisdiction,x,[Government] is the jurisdiction of [City],,,,,
230
+ followed by,,,,,series,,
231
+ follows,,,,series,,,
232
+ fork of,,,,,,x,
233
+ form of government,,,,government,,,
234
+ section of,x,[Group] has a section of [Group],,,,,
235
+ religion,x,[Group] is [Religion],,,,,
236
+ formed out of,,,,,,x,
237
+ successor,x,[Group] is a predecessor of [Group],,,,,
238
+ founded,,,,foundation,,,
239
+ founded by,,,,founder,,,
240
+ religious order,x,[Group] is a religious order of [Group],,,,,
241
+ created,x,[Group] is created on [Date],,,,,
242
+ founded in,x,[Group] is founded at [Location],,,,,
243
+ founder,x,[Group] is founded by [Person],,,,,
244
+ game engine,,,,video game publisher,,,
245
+ gameplay,,,,,,x,
246
+ foundation,x,[Group] is founded on [Date],,,,,
247
+ gauge,,,,,,x,
248
+ general manager,,,,team manager,,,
249
+ funded by,x,[Group] is funded by [Person],,,,,
250
+ girlfriend,,,,husband,,,
251
+ given by,,,,presented by,,,
252
+ legislative body,x,[Group] is legislative body of [Country],x,,,,
253
+ graduate of,,,,studied at,,,
254
+ graduated from,,,,studied at,,,
255
+ ground,,,,home field,,,
256
+ group,,,,music by,,,
257
+ happens in,,,,,,x,
258
+ legislature,x,[Group] is legislature of [Country],x,,,,
259
+ merged into,x,[Group] is merged into [Group],,,,,
260
+ parliament,x,[Group] is the parliament of [Country],x,,,,
261
+ heir,,,,,,x,
262
+ official language,x,[Group] speaks [Language],,,,,
263
+ highest point,,,,highest peak,,,
264
+ highway system,,,,,,x,
265
+ leader,x,[Group]'s leader is [Person],,,,,
266
+ appointed by,x,[Head of Government] is appointed by [Head of Government],,,,,
267
+ home ground,,,,home field,,,
268
+ home venue,,,,home field,,,
269
+ honors,,,,award,,,
270
+ honours,,,,award,,,
271
+ public holiday,x,[Holiday] is a national holiday of [Country],x,,,,
272
+ island,x,[Island] is [Country],,,,,
273
+ head of state,x,[Job] is the head of state in [Location],x,,,,
274
+ land,x,[Land] is [Country],,,,,
275
+ alphabet,x,[Language] consists of [Alphabet],,,,,
276
+ illustrated by,,,,,work,,
277
+ illustrator,,,,,work,,
278
+ imprisoned in,,,,prison,,,
279
+ inaugurated,,,,established,,,
280
+ include,,,,,is in,,
281
+ includes,,,,,is in,,
282
+ includes part,,,,,,x,
283
+ incorporated,,,,established,,,
284
+ incumbent,,,,,,x,
285
+ dialect,x,[Language] is a dialect of [Language],x,,,,
286
+ indigenous to,,,,culture,,,
287
+ industry,,,,sector,,,
288
+ inflow,,,,,,x,
289
+ enacted by,x,[Law] is enacted by [Group],,,,,
290
+ informed by,,,,,,x,
291
+ ingredient,,,,made from,,,
292
+ inspiration,,,,influenced by,,,
293
+ inspired by,,,,influenced by,,,
294
+ instance of,,,,is a,,,
295
+ instruction set,,,,,,x,
296
+ instrument,,,,plays,,,
297
+ intersex,,,,male,,,
298
+ invented by,,,,,work,,
299
+ inventor,,,,,work,,
300
+ is a,,,,,,,x
301
+ is a type of,,,,is a,,,
302
+ is an,,,,is a,,,
303
+ is in,,,,,,,x
304
+ is in the borough of,,,,town,,,
305
+ is in the city of,,,,city,,,
306
+ is in the county of,,,,town,,,
307
+ is in the district of,,,,town,,,
308
+ is in the municipality of,,,,town,,,
309
+ is in the parish of,,,,,,x,
310
+ is in the province of,,,,state,,,
311
+ is in the region of,,,,is in,,,
312
+ is in the state of,,,,state,,,
313
+ is in the town of,,,,state,,,
314
+ is in the village of,,,,town,,,
315
+ is located in,,,,is in,,,
316
+ is not,,,,,,x,
317
+ is on,,,,,,x,
318
+ is owned by,,,,,product,,
319
+ ISA,,,,,,x,
320
+ approved by,x,[License] is approved by [Organization],,,,,
321
+ ballpark,x,[Location] is a ballpark of [Sport Team],x,,,,
322
+ river mouth,x,[Location] is a river mouth of [Bay],,,,,
323
+ kids,,,,,father,,
324
+ killed by,,,,murdered by,,,
325
+ killer,,,,murdered by,,,
326
+ kind of,,,,is a,,,
327
+ sovereign state,x,[Location] is a sovereign state of [Location],,,,,
328
+ known for,,,,work,,,
329
+ label,,,,record label,,,
330
+ administrative centre,x,[Location] is an administrative center of [Location],,,,,
331
+ language,,,,native language,,,
332
+ language official,,,,native language,,,
333
+ language spoken,,,,native language,,,
334
+ latitude,,,,is in,,,
335
+ launch date,,,,established,,,
336
+ launch vehicle,,,,,,x,
337
+ Indian reservation,x,[Location] is an Indian reservation in [Country],,,,,
338
+ league,,,,sports league,,,
339
+ closed,x,[Location] is closed on [Date],,,,,
340
+ exclave of,x,[Location] is exclave of [Country],,,,,
341
+ librettist,,,,libretto by,,,
342
+ planet,x,[Location] is in [Planet],,,,,
343
+ licence,,,,license,,,
344
+ next to,x,[Location] is next to [Location],,,,,
345
+ life partner,,,,,husband,,
346
+ on the coast of,x,[Location] is on the coast of [Ocean],,,,,
347
+ literary works,,,,work,,,
348
+ lived in,,,,residence,,,
349
+ locality,,,,city,,,
350
+ located in,,,,is in,,,
351
+ location,,,,,,x,
352
+ longitude,,,,,,x,
353
+ lover,,,,husband,,,
354
+ split from,x,[Location] is split from [Location],,,,,
355
+ lyricist,,,,music by,,,
356
+ lyrics by,,,,music by,,,
357
+ made by,,,,,product,,
358
+ highest peak,x,[Location] is the highest peak in [Country],x,,,,
359
+ made of,,,,made from,,,
360
+ lowest point,x,[Location] is the lowest point of [Location],x,,,,
361
+ crystal system,x,[Material]'s crystal system is [Crystal System],,,,,
362
+ maintenance,,,,maintained by,,,
363
+ major works,,,,work,,,
364
+ maker,,,,,product,,
365
+ makes,,,,product,,,
366
+ treats,x,[Medication] is for [Disease],,,,,
367
+ man,,,,male,,,
368
+ managed by,,,,maintained by,,,
369
+ manufactured by,,,,manufacturer,,,
370
+ used for treatment,x,[Medicine] is for [Disease],x,,,,
371
+ manufactures,,,,,manufacturer,,
372
+ married to,,,,marry,,,
373
+ film genre,x,[Movie] is [Genre],,,,,
374
+ libretto by,x,[Movie] is a libretto by [Person],,,,,
375
+ master,,,,student of,,,
376
+ spin-off,x,[Movie] is a spinoff of [Movie],x,,,,
377
+ medals,,,,,,x,
378
+ medium,,,,made from,,,
379
+ member,,,,composed of,,,
380
+ first broadcast,x,[Movie] is first broadcast on [Date],,,,,
381
+ members,,,,composed of,,,
382
+ universe,x,[Movie] is in the universe of [Art Work],,,,,
383
+ mentor,,,,student of,,,
384
+ film studio,x,[Movie] is produced by [Company],,,,,
385
+ merged with,,,,merged into,,,
386
+ screenplay by,x,[Movie] is screenplayed by [Person],,,,,
387
+ mode,,,,,,x,
388
+ film starring,x,[Movie] stars [Actor],,,,,
389
+ month,,,,,,x,
390
+ mother,,,,father,,,
391
+ mother tongue,,,,native language,,,
392
+ collection,x,[Museum] has [Collection of Work],x,,,,
393
+ dedicated to,x,[Museum] is dedicated to [Person],,,,,
394
+ movie director,,,,director,,,
395
+ municipal council,,,,council,,,
396
+ memorial to,x,[Museum] is memorial to [Event],,,,,
397
+ murderer,,,,murdered by,,,
398
+ genre,x,[Music Artist] is [Genre],,,,,
399
+ music genre,,,,genre,,,
400
+ music group,,,,music by,,,
401
+ musical artist,,,,music by,,,
402
+ musical score by,,,,music by,,,
403
+ musician,,,,music by,,,
404
+ anthem,x,[Music] is an anthem of [Country],x,,,,
405
+ music by,x,[Music] is made by [Artist],,,,,
406
+ studio,x,[Music] is recorded at [Studio],,,,,
407
+ nation,,,,city,,,
408
+ national holiday,,,,public holiday,,,
409
+ released,x,[Music] is released on [Date],,,,,
410
+ official residence,x,[Occupation] lives in [Location],,,,,
411
+ native to,,,,culture,,,
412
+ network,,,,broadcast on,,,
413
+ ideology,x,[Organization]'s ideology is [Ideology],,,,,
414
+ noble family,,,,,,x,
415
+ nominated for,,,,award,,,
416
+ nominee for,,,,award,,,
417
+ not to be confused with,,,,,,x,
418
+ notable work,,,,,author,,
419
+ occupation,,,,job,,,
420
+ occupied by,,,,maintained by,,,
421
+ of team,,,,played for,,,
422
+ office held,,,,,,x,
423
+ CPU,x,[PC]'s cpu is [CPU],,,,,
424
+ marry,x,[Person] and [Person] are married,,,,,
425
+ political party,x,[Person] belongs to [Political Party],,,,,
426
+ on the shore of,,,,on the coast of,,,
427
+ opened,,,,starting,,,
428
+ operated,,,,operated by,,,
429
+ record label,x,[Person] belongs to [Record Label],,,,,
430
+ operates,,,,operated by,,,
431
+ builder,x,[Person] built [Artifact],x,,,,
432
+ operator,,,,operated by,,,
433
+ war,x,[Person] causes [War],,,,,
434
+ orbits,,,,orbit,,,
435
+ choreographer,x,[Person] choreographs [Play],x,,,,
436
+ organizer,,,,maintained by,,,
437
+ original language,,,,native language,,,
438
+ originates from,,,,,,x,
439
+ OS,,,,operating system,,,
440
+ coined by,x,[Person] coins [Artifact],x,,,,
441
+ outlet,,,,outflow,,,
442
+ overlies,,,,,,x,
443
+ owned by,,,,,divisions,,
444
+ owner,,,,,divisions,,
445
+ owner of,,,,divisions,,,
446
+ work,x,[Person] creates [Work],,,,,
447
+ died in,x,[Person] dies at [Location],,,,,
448
+ parent,,,,father,,,
449
+ parent company,,,,,divisions,,
450
+ parent company of,,,,divisions,,,
451
+ died on,x,[Person] dies on [Date],,,,,
452
+ part of,,,,is in,,,
453
+ participant,,,,player,,,
454
+ participant in,,,,,player,,
455
+ participant of,,,,,player,,
456
+ partner,,,,,husband,,
457
+ parts,,,,is in,,,
458
+ party,,,,,,x,
459
+ passed by,,,,signatory,,,
460
+ disappeared,x,[Person] disappears on [Date],,,,,
461
+ first described by,x,[Person] first finds [Disease],x,,,,
462
+ patron saint of,,,,,patron saint,,
463
+ pendant of,,,,,,x,
464
+ disorder,x,[Person] has [Diseases],,,,,
465
+ period,,,,era,,,
466
+ house,x,[Person] has a house in [Location],,,,,
467
+ place of birth,,,,birth place,,,
468
+ place of death,,,,died in,,,
469
+ job,x,[Person] is [Occupation],,,,,
470
+ rank,x,[Person] is [Rank],,,,,
471
+ platforms,,,,platform,,,
472
+ male,x,[Person] is [Sex],,,,,
473
+ candidate,x,[Person] is a candidate of [Election],x,,,,
474
+ chancellor,x,[Person] is a chancellor of [Country],x,,,,
475
+ chief executive,x,[Person] is a chief executive of [Company],x,,,,
476
+ plays for,,,,played for,,,
477
+ father,x,[Person] is a child of [Person],,,,,
478
+ portrait of,,,,painting of,,,
479
+ portrayed by,,,,,work,,
480
+ cinematographer,x,[Person] is a cinematographer of [Movie],x,,,,
481
+ predecessor,,,,,successor,,
482
+ head coach,x,[Person] is a coach of [Sport Team],x,,,,
483
+ premiere,,,,first performance,,,
484
+ commander of,x,[Person] is a commander of [Army],,,,,
485
+ concubine,x,[Person] is a concubine of [Person],x,,,,
486
+ consort,x,[Person] is a consort of [Person],,,,,
487
+ husband,x,[Person] is a husband of [Person],,,,,
488
+ team manager,x,[Person] is a manager of [Sport Team],x,,,,
489
+ composed of,x,[Person] is a member of [Music Group],x,,,,
490
+ produces,,,,producer,,,
491
+ mistress,x,[Person] is a mistress of [Person],x,,,,
492
+ production company,,,,film studio,,,
493
+ production designer,,,,,work,,
494
+ production house,,,,film studio,,,
495
+ profession,,,,job,,,
496
+ professor,,,,student of,,,
497
+ programmer,,,,,,x,
498
+ patron,x,[Person] is a patron of [Person],,,,,
499
+ promotion to,,,,,,x,
500
+ protection,,,,,,x,
501
+ protocol,,,,,,x,
502
+ premier,x,[Person] is a premier of [Group],x,,,,
503
+ public office,,,,,,x,
504
+ presenter,x,[Person] is a presenter of [TV show],x,,,,
505
+ student of,x,[Person] is a student of [Person],,,,,
506
+ active in,x,[Person] is active in [Location],,,,,
507
+ publishing house,,,,publisher,,,
508
+ pupil,,,,student of,,,
509
+ pupil of,,,,student of,,,
510
+ pupils,,,,student of,,,
511
+ purpose,,,,use,,,
512
+ award,x,[Person] is awarded by [Award],,,,,
513
+ race,,,,nationality,,,
514
+ nationality,x,[Person] is born in [Country],,,,,
515
+ radio station,,,,radio network,,,
516
+ birth place,x,[Person] is born in [Location],,,,,
517
+ birth date,x,[Person] is born on [Date],,,,,
518
+ tomb,x,[Person] is buried at [Tomb],,,,,
519
+ record producer,,,,producer,,,
520
+ regulatory body,,,,,,x,
521
+ relative,,,,,,x,
522
+ convicted of,x,[Person] is convicted of [Crime],,,,,
523
+ relegation to,,,,,,x,
524
+ drafted by,x,[Person] is drafted by [Group],,,,,
525
+ era,x,[Person] is from [Era],,,,,
526
+ replaced,,,,,successor,,
527
+ replaced by,,,,,successor,,
528
+ representative body,,,,,,x,
529
+ represented by,,,,head of government,,,
530
+ prison,x,[Person] is in [Prison],,,,,
531
+ resident in,,,,residence,,,
532
+ resting place,,,,tomb,,,
533
+ murdered by,x,[Person] is killed by [Person],,,,,
534
+ result of,,,,,result,,
535
+ played for,x,[Person] is played at [Group],,,,,
536
+ royal house,,,,dynasty,,,
537
+ runs on,,,,,,x,
538
+ chairman,x,[Person] is the chair of [Group],x,,,,
539
+ school,,,,studied at,,,
540
+ emperor,x,[Person] is the emperor of [Country],x,,,,
541
+ screenwriter,,,,screenplay by,,,
542
+ script,,,,alphabet,,,
543
+ scriptwriter,,,,,,x,
544
+ head of government,x,[Person] is the head of government of [Country],x,,,,
545
+ seat,,,,county seat,,,
546
+ king,x,[Person] is the king of [Country],x,,,,
547
+ dynasty,x,[Person] is the leader of [Dynasty],,,,,
548
+ senior coach,,,,head coach,,,
549
+ separated from,,,,,,x,
550
+ sequel of,,,,series,,,
551
+ mayor,x,[Person] is the mayor of [City],x,,,,
552
+ set of,,,,,,x,
553
+ sex,,,,male,,,
554
+ monarch,x,[Person] is the monarch of [Country],x,,,,
555
+ shareholder,,,,,,x,
556
+ shares border with,,,,next to,,,
557
+ president,x,[Person] is the president of [Country],x,,,,
558
+ signed by,,,,signatory,,,
559
+ significant works,,,,work,,,
560
+ prime minister,x,[Person] is the prime minister of [Country],x,,,,
561
+ singer,,,,music by,,,
562
+ sister city,,,,twin city,,,
563
+ solid solution series with,,,,,,x,
564
+ son,,,,,father,,
565
+ songwriter,,,,author,,,
566
+ sons,,,,,father,,
567
+ queen,x,[Person] is the queen of [Country] ,x,,,,
568
+ residence,x,[Person] live in [Location],,,,,
569
+ played by,x,[Person] plays [Fictional Character],x,,,,
570
+ plays,x,[Person] plays [Instrument],,,,,
571
+ sports,,,,sport,,,
572
+ voice actor,x,[Person] plays in [Movie],,,,,
573
+ spouse,,,,,husband,,
574
+ square,,,,is in,,,
575
+ stadium,,,,home field,,,
576
+ starring,,,,film starring,,,
577
+ team,x,[Person] plays in [Sport Team],,,,,
578
+ native language,x,[Person] speaks [Language],,,,,
579
+ stock exchange,,,,,,x,
580
+ discipline,x,[Person] studies [Academic Subject],,,,,
581
+ student,,,,,student of,,
582
+ studied at,x,[Person] studies at [School],,,,,
583
+ students,,,,,student of,,
584
+ works at,x,[Person] works at [Group],,,,,
585
+ studied under,,,,student of,,,
586
+ pet,x,[Pet] is a pet of [Person],x,,,,
587
+ satellite,x,[Planet] is a satellite of [Planet],x,,,,
588
+ subclass of,,,,is a,,,
589
+ subdivided into,,,,,city,,
590
+ subject,,,,,,x,
591
+ subject of,,,,,,x,
592
+ subsidiary,,,,divisions,,,
593
+ subsidiary company,,,,divisions,,,
594
+ subsidiary of,,,,divisions,,,
595
+ subsystem of,,,,,,x,
596
+ orbit,x,[Planet] is in the orbit of [Orbit],,,,,
597
+ honours,,,,studied at,,,
598
+ type species,x,[Plant] is [Type],,,,,
599
+ first performance,x,[Play] is first performed on [Date],,,,,
600
+ takes place in,,,,,,x,
601
+ taxonomic rank,,,,,,x,
602
+ teacher,,,,student of,,,
603
+ teacher of,,,,,student of,,
604
+ performer,x,[Play] is performed by [Person],,,,,
605
+ radio network,x,[Radio Program] is broadcasted on [Radio Channel],,,,,
606
+ teams played for,,,,played for,,,
607
+ teleplay by,,,,,,x,
608
+ television channel,,,,broadcast on,,,
609
+ tenant,,,,,,x,
610
+ railway line,x,[Railway] is in [Location],x,,,,
611
+ territory claimed by,,,,claimed by,,,
612
+ theme song,,,,music by,,,
613
+ denomination,x,[Religion] is a denomination by [Artifact],,,,,
614
+ drain,x,[River] drains [Location],,,,,
615
+ tributary of,x,[River] is a tributary of [River],,,,,
616
+ tonality,,,,,,x,
617
+ outflow,x,[River] outflows to [Location],,,,,
618
+ took part in,,,,took part,,,
619
+ developed by,x,[Software] is developed by [Company],,,,,
620
+ license,x,[Software] is under license of [License],,,,,
621
+ use,x,[Software] is used for [Purpose],,,,,
622
+ treatment,,,,treats,,,
623
+ programming language,x,[Software] is written in [Programming Language],,,,,
624
+ tributary,,,,,tributary of,,
625
+ affiliate of,x,[Sport Team] is an affiliate of [Sport Team],,,,,
626
+ tunnel under,,,,bridge over,,,
627
+ TV channel,,,,broadcast on,,,
628
+ sports league,x,[Sport Team] plays at [Competition],,,,,
629
+ player,x,[Sport Team] plays in [Competition],x,,,,
630
+ champion,x,[Sport Team] wins [Competition],x,,,,
631
+ unit of,,,,,,x,
632
+ home field,x,[Sport Team]'s home field is [Location],,,,,
633
+ constellation,x,[Star] is a [Constellation],,,,,
634
+ state,x,[State] is a state of [Country],,,,,
635
+ used for,,,,use,,,
636
+ terminus,x,[Station] is the terminus of [Railway],x,,,,
637
+ used in,,,,use,,,
638
+ user,,,,,,x,
639
+ uses,,,,,use,,
640
+ utility,,,,use,,,
641
+ venue,,,,,took part,,
642
+ street,x,[Street] is in the street of [Location],,,,,
643
+ system of,x,[System] is a system in [Artifact],,,,,
644
+ voiced by,,,,voice actor,,,
645
+ time zone,x,[Timezone] is a timezon in [Country],x,,,,
646
+ town,x,[Town] is in [Location],,,,,
647
+ wife,,,,,husband,,
648
+ winner,,,,champion,,,
649
+ winners,,,,champion,,,
650
+ woman,,,,male,,,
651
+ won by,,,,champion,,,
652
+ words by,,,,author,,,
653
+ broadcast on,x,[TV Series] is broadcasted on [TV Channel],,,,,
654
+ working for,,,,works at,,,
655
+ works,,,,work,,,
656
+ weapon,x,[Weapon] is used by [Person],x,,,,
657
+ writer,,,,author,,,
658
+ writing system,,,,alphabet,,,
659
+ written by,,,,author,,,
660
+ year,,,,time,,,
process.py CHANGED
@@ -1,33 +1,87 @@
1
- """
 
 
2
  wget https://figshare.com/ndownloader/files/8760241
3
  unzip 8760241
 
4
  """
5
 
6
  import json
 
 
7
  import os
8
  from glob import glob
9
  from tqdm import tqdm
10
- # from random import shuffle, seed
11
-
12
- os.makedirs('data', exist_ok=True)
13
- f_writer = open('data/t_rex.raw.jsonl', 'w')
14
- for i in tqdm(glob("*.json")):
15
- with open(i) as f:
16
- data = json.load(f)
17
- for _data in data:
18
- for triple in _data['triples']:
19
- p = triple['predicate']['surfaceform']
20
- o = triple['object']['surfaceform']
21
- s = triple['subject']['surfaceform']
22
- if p is None or o is None or s is None:
23
- continue
24
- out = {"predicate": p, "object": o, "subject": s, "title": _data["title"], "text": _data["text"]}
25
- f_writer.write(json.dumps(out) + "\n")
26
- f_writer.close()
27
-
28
-
29
- with open('data/t_rex.raw.jsonl') as f:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  data = [json.loads(i) for i in f.read().split('\n') if len(i) > 0]
31
- s = {i['subject'] for i in data}
32
- o = {i['object'] for i in data}
33
- s.update(o)
 
 
 
 
 
 
 
 
 
 
 
1
+ """ Process raw T-Rex file.
2
+ mkdir data_raw
3
+ cd data_raw
4
  wget https://figshare.com/ndownloader/files/8760241
5
  unzip 8760241
6
+ cd ../
7
  """
8
 
9
  import json
10
+ import string
11
+ import re
12
  import os
13
  from glob import glob
14
  from tqdm import tqdm
15
+
16
+ import pandas as pd
17
+
18
+ # process raw data
19
+ if not os.path.exists('data/t_rex.raw.jsonl'):
20
+ os.makedirs('data', exist_ok=True)
21
+ f_writer = open('data/t_rex.raw.jsonl', 'w')
22
+ for i in tqdm(glob("data_raw/*.json")):
23
+ with open(i) as f:
24
+ data = json.load(f)
25
+ for _data in data:
26
+ for triple in _data['triples']:
27
+ p = triple['predicate']['surfaceform']
28
+ o = triple['object']['surfaceform']
29
+ s = triple['subject']['surfaceform']
30
+ if p is None or o is None or s is None:
31
+ continue
32
+ out = {"predicate": p, "object": o, "subject": s, "title": _data["title"], "text": _data["text"]}
33
+ f_writer.write(json.dumps(out) + "\n")
34
+ f_writer.close()
35
+
36
+ # apply filtering to remove noisy instances
37
+ stopwords = ["he", "she", "they", "it"]
38
+ list_alnum = string.ascii_lowercase + '0123456789 '
39
+
40
+
41
+ def filtering(entry):
42
+
43
+ def _subfilter(token):
44
+ if len(re.findall(rf'[^{list_alnum}]+', token)) != 0:
45
+ return False
46
+ if token in stopwords:
47
+ return False
48
+ if token.startswith("www"):
49
+ return False
50
+ if token.startswith("."):
51
+ return False
52
+ if token.startswith(","):
53
+ return False
54
+ if token.startswith("$"):
55
+ return False
56
+ if token.startswith("+"):
57
+ return False
58
+ if token.startswith("#"):
59
+ return False
60
+ return True
61
+
62
+ if not _subfilter(entry["object"].lower()):
63
+ return False
64
+ if not _subfilter(entry["subject"].lower()):
65
+ return False
66
+
67
+ if entry['object'].islower() and entry['subject'].islower():
68
+ return False
69
+
70
+ return True
71
+
72
+
73
+ with open(f"data/t_rex.raw.jsonl") as f:
74
  data = [json.loads(i) for i in f.read().split('\n') if len(i) > 0]
75
+ print(f"[before]: {len(data)}")
76
+ data = [i for i in data if filtering(i)]
77
+ df = pd.DataFrame(data)
78
+ count = df.groupby("predicate")['title'].count()
79
+ df = df[[count[p] >= 3 for p in df['predicate']]]
80
+ df = df.drop_duplicates()
81
+ print(f"[after] : {len(df)}")
82
+ print(f"[entity]: {len(set(df['object'].unique().tolist() + df['subject'].unique().tolist()))}")
83
+ _df = df[['object', 'subject']]
84
+ data = [i.to_dict() for _, i in df.iterrows()]
85
+
86
+ with open(f"data/t_rex.filter.jsonl", 'w') as f:
87
+ f.write('\n'.join([json.dumps(i) for i in data]))
t_rex.py CHANGED
@@ -5,7 +5,7 @@ import datasets
5
  logger = datasets.logging.get_logger(__name__)
6
  _DESCRIPTION = """T-Rex dataset."""
7
  _NAME = "t_rex"
8
- _VERSION = "0.0.3"
9
  _CITATION = """
10
  @inproceedings{elsahar2018t,
11
  title={T-rex: A large scale alignment of natural language with knowledge base triples},
@@ -17,8 +17,9 @@ _CITATION = """
17
 
18
  _HOME_PAGE = "https://github.com/asahi417/relbert"
19
  _URL = f'https://huggingface.co/datasets/relbert/{_NAME}/resolve/main/data'
20
- _TYPES = ["raw", "filter"]
21
- _URLS = {i: {str(datasets.Split.TRAIN): [f'{_URL}/t_rex.{i}.jsonl']} if i in ['raw', 'filter'] else {
 
22
  str(datasets.Split.TRAIN): [f'{_URL}/t_rex.{i}.train.jsonl'],
23
  str(datasets.Split.VALIDATION): [f'{_URL}/t_rex.{i}.validation.jsonl'],
24
  str(datasets.Split.TEST): [f'{_URL}/t_rex.{i}.test.jsonl']}
@@ -46,7 +47,7 @@ class TREX(datasets.GeneratorBasedBuilder):
46
 
47
  def _split_generators(self, dl_manager):
48
  downloaded_file = dl_manager.download_and_extract(_URLS[self.config.name])
49
- if self.config.name in ['raw', 'filter']:
50
  return [datasets.SplitGenerator(
51
  name=datasets.Split.TRAIN,
52
  gen_kwargs={"filepaths": downloaded_file[str(datasets.Split.TRAIN)]})]
 
5
  logger = datasets.logging.get_logger(__name__)
6
  _DESCRIPTION = """T-Rex dataset."""
7
  _NAME = "t_rex"
8
+ _VERSION = "0.0.4"
9
  _CITATION = """
10
  @inproceedings{elsahar2018t,
11
  title={T-rex: A large scale alignment of natural language with knowledge base triples},
 
17
 
18
  _HOME_PAGE = "https://github.com/asahi417/relbert"
19
  _URL = f'https://huggingface.co/datasets/relbert/{_NAME}/resolve/main/data'
20
+ _TYPES = ["raw", "filter", "filter_unified"]
21
+ _NON_SPLITS = ["raw", "filter", "filter_unified"]
22
+ _URLS = {i: {str(datasets.Split.TRAIN): [f'{_URL}/t_rex.{i}.jsonl']} if i in _NON_SPLITS else {
23
  str(datasets.Split.TRAIN): [f'{_URL}/t_rex.{i}.train.jsonl'],
24
  str(datasets.Split.VALIDATION): [f'{_URL}/t_rex.{i}.validation.jsonl'],
25
  str(datasets.Split.TEST): [f'{_URL}/t_rex.{i}.test.jsonl']}
 
47
 
48
  def _split_generators(self, dl_manager):
49
  downloaded_file = dl_manager.download_and_extract(_URLS[self.config.name])
50
+ if self.config.name in _NON_SPLITS:
51
  return [datasets.SplitGenerator(
52
  name=datasets.Split.TRAIN,
53
  gen_kwargs={"filepaths": downloaded_file[str(datasets.Split.TRAIN)]})]
unify_predicate.py ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # import json
2
+ # import pandas as pd
3
+ #
4
+ # with open("data/t_rex.filter.jsonl") as f:
5
+ # data = pd.DataFrame([json.loads(i) for i in f.read().split('\n') if len(i) > 0])
6
+ # freq = data.groupby("predicate").count()['title']
7
+ # data['freq'] = [freq.loc[i] for i in data['predicate']]
8
+ # data = data[data['freq'] >= 3]
9
+ # tmp = data.groupby("predicate").sample(10, replace=True)
10
+ # tmp = tmp.drop_duplicates()
11
+ # tmp.to_csv("data/t_rex.filter.predicate_check_sample.csv", index=False)
12
+
13
+ import json
14
+ import pandas as pd
15
+
16
+ # load manual check sheet
17
+ df_predicate = pd.read_csv('predicate_manual_check.csv')
18
+ df_predicate = df_predicate[df_predicate['remove (noisy)'] != 'x']
19
+ df_predicate = df_predicate[df_predicate['remove (too vague)'] != 'x']
20
+ predicate_main = df_predicate[df_predicate['ok'] == 'x']['unique predicates'].tolist()
21
+ df_sub = df_predicate[df_predicate['ok'] != 'x']
22
+ df_sub_same = df_sub[['unique predicates', 'same as']].dropna()
23
+ df_sub_same = df_sub_same[[i in predicate_main for i in df_sub_same['same as']]]
24
+ df_sub_same.index = df_sub_same.pop('unique predicates')
25
+ sub_same = df_sub_same['same as'].to_dict()
26
+ df_sub_rev = df_sub[['unique predicates', 'reverse of']].dropna()
27
+ df_sub_rev = df_sub_rev[[i in predicate_main for i in df_sub_rev['reverse of']]]
28
+ df_sub_rev.index = df_sub_rev.pop('unique predicates')
29
+ sub_rev = df_sub_rev['reverse of'].to_dict()
30
+
31
+ # load data and filter based on manual predicate check sheet
32
+ with open(f"data/t_rex.filter.jsonl") as f:
33
+ data = pd.DataFrame([json.loads(i) for i in f.read().split('\n') if len(i) > 0])
34
+ data['predicate'] = [sub_same[i] if i in sub_same else i for i in data['predicate']]
35
+ data['reverse'] = [i in sub_rev for i in data['predicate']]
36
+ data['predicate'] = [sub_rev[i] if i in sub_rev else i for i in data['predicate']]
37
+ data_filter = data[[i in predicate_main for i in data['predicate']]]
38
+
39
+ data_filter_rev = data_filter[data_filter['reverse']].copy()
40
+ o = data_filter_rev.pop("object")
41
+ s = data_filter_rev.pop("subject")
42
+ data_filter_rev["subject"] = o
43
+ data_filter_rev["object"] = s
44
+ data_filter[data_filter['reverse']] = data_filter_rev[data_filter.columns]
45
+ data_filter.pop("reverse")
46
+
47
+ df_main = df_predicate[df_predicate['ok'] == 'x'][['unique predicates', 'pretty relation name', 'pretty relation name is reverse']]
48
+ df_main['reverse'] = [i == 'x' for i in df_main.pop('pretty relation name is reverse')]
49
+ df_main['predicate'] = df_main.pop('unique predicates')
50
+
51
+ data_filter_join = data_filter.merge(df_main, how='inner', on='predicate')
52
+ data_filter_join_rev = data_filter_join[data_filter_join['reverse']].copy()
53
+ o = data_filter_join_rev.pop("object")
54
+ s = data_filter_join_rev.pop("subject")
55
+ data_filter_join_rev["subject"] = o
56
+ data_filter_join_rev["object"] = s
57
+ data_filter_join[data_filter_join['reverse']] = data_filter_join_rev[data_filter_join.columns]
58
+ data_filter_join.pop("reverse")
59
+ data_filter_join.pop("predicate")
60
+ data_filter_join['predicate'] = data_filter_join.pop("pretty relation name")
61
+
62
+ print(f"[after] : {len(data_filter_join)}")
63
+ print(f"[entity]: {len(set(data_filter_join['object'].unique().tolist() + data_filter_join['subject'].unique().tolist()))}")
64
+ print(f"[predicate]: {len(data_filter_join['predicate'].unique())}")
65
+
66
+
67
+ data = [i.to_dict() for _, i in data_filter_join.iterrows()]
68
+ with open(f"data/t_rex.filter_unified.jsonl", 'w') as f:
69
+ f.write('\n'.join([json.dumps(i) for i in data]))