asahi417 commited on
Commit
6818f83
1 Parent(s): 7fe48b5
check_predicate.py DELETED
File without changes
create_split.py ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import numpy as np
3
+
4
+ with open("data/t_rex.filter.jsonl") as f:
5
+ data = [json.loads(i) for i in f.read().split('\n') if len(i) > 0]
6
+
7
+ p, c = np.unique([i['predicate'] for i in data], return_counts=True)
8
+ d = dict(zip(p.tolist(), c.tolist()))
9
+ with open("data/t_rex.filter.predicate.json", 'w') as f:
10
+ json.dump(d, f)
data/t_rex.filter.predicate.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"CEO": 171, "CPU": 29, "Communist Party Secretary": 2, "HQ": 20, "ISA": 6, "Indian reservation": 38, "OS": 665, "TV channel": 32, "TV presenter": 2, "abolished": 14, "academic discipline": 3, "active in": 24, "actor": 1748, "actress": 1181, "adapted from": 10, "adjacent to": 622, "administered by": 8, "administrative centre": 158, "advisor": 3, "affiliate of": 130, "affiliated with": 2, "agent": 1, "aircraft operated": 1, "airline alliance": 34, "airline hub": 2, "allegiance": 1, "alma mater": 33, "alphabet": 544, "alumni of": 6, "alumnus of": 27, "amalgamation of": 17, "ammunition": 1, "ancestral home": 1, "anthem": 252, "appears in": 1, "appointed by": 46, "approved by": 34, "architect": 388, "architectural style": 4, "area of responsibility": 1, "arena": 61, "art collection": 1, "artery": 4, "artist": 50, "artists": 25, "as of": 1, "aspect": 1, "aspect of": 6, "assassin": 28, "assassinated by": 19, "assembly": 53, "assembly of": 16, "athlete": 4, "athletes": 10, "author": 1696, "authority": 5, "award": 1117, "awarded": 1698, "awarded by": 52, "awards": 851, "ballpark": 28, "band": 4566, "based on": 401, "battle": 286, "began": 122, "beginning": 24, "belongs to": 26, "bestowed by": 3, "birth date": 4, "birth place": 5, "birthdate": 1, "birthday": 11, "birthplace": 417, "book by": 78, "book publisher": 2, "border": 32989, "bordered by": 4294, "borders": 26776, "born at": 316, "born in": 3262, "born on": 476, "boyfriend": 13, "branch": 19, "brand": 6, "bridge over": 156, "broadcast on": 571, "builder": 3, "built by": 535, "built from": 4, "burial place": 17, "buried in": 77, "business division": 2, "candidate": 94, "capital": 14043, "capital city": 2401, "capital of": 6560, "capital town": 34, "captain": 2, "career": 2306, "carries": 17, "cartridge": 7, "cast member": 51, "cathedral": 42, "cause": 69, "cause of": 29, "cause of death": 2, "caused by": 123, "central bank": 23, "central processing unit": 2, "chairman": 83, "chairperson": 8, "chairwoman": 1, "champion": 448, "chancellor": 10, "channel": 343, "characters": 257, "chief executive": 18, "chief executive officer": 12, "children": 738, "choreographer": 16, "chromosome": 3, "cinematographer": 42, "citizen of": 89, "citizenship": 140, "city": 47533, "city council": 24, "city of license": 1, "claimed by": 231, "closed": 5, "club manager": 1, "co-driver": 3, "coach": 360, "coat of arms": 55, "coined by": 15, "collection": 18, "color": 9, "colour": 10, "comes from": 1, "commander of": 41, "commemorates": 1, "commissioned by": 7, "competitor": 1, "compiled by": 3, "composed by": 384, "composed of": 469, "composer": 745, "computing platform": 2, "concubine": 14, "conflict": 75, "connected with": 5, "connects with": 2, "consequence": 1, "conservation status": 6, "consort": 999, "constellation": 394, "constituency": 1, "constructed": 1, "constructed by": 1, "constructed from": 5, "contained within": 14, "contains": 672, "continent": 521, "contributing factor": 1, "convicted of": 7, "coolant": 1, "coordinates": 1, "copy of": 2, "costume designer": 8, "council": 86, "country": 14268, "country of origin": 3, "county seat": 262, "county seat of": 39, "craft": 43, "created": 97, "created by": 1628, "created from": 8, "created out of": 1, "creator": 709, "crew member": 2, "crosses": 197, "crystal system": 8, "cuisine": 19, "culture": 19, "curator": 1, "currency": 594, "dad": 3, "date": 1, "daughter": 3841, "daughters": 394, "dead": 27, "death": 1002, "death place": 2, "deathplace": 1, "dedicated to": 18, "dedication": 1, "degree": 1, "deity of": 13, "denomination": 42, "depiction of": 1, "depicts": 8, "derived from": 32, "designation": 119, "designed by": 221, "designer": 114, "developed by": 2440, "developer": 337, "dialect": 212, "die from": 1, "died in": 594, "died on": 292, "diet": 10, "diocese": 16, "diplomatic relation": 6, "directed by": 9270, "director": 1583, "director of photography": 4, "disappeared": 6, "disciple": 62, "disciple of": 39, "disciples": 30, "discipline": 32, "discography": 4, "discovered by": 46, "discoverer": 31, "disease": 1, "disestablished": 3, "disorder": 10, "distinct from": 13, "distributed by": 74, "distribution": 14, "distributor": 21, "district council": 1, "divided into": 443, "division": 937, "divisions": 12, "docking port": 2, "doctoral advisor": 1, "drafted by": 28, "drain": 208, "dynasty": 1404, "edibility": 1, "edited by": 61, "edition of": 12, "editions": 24, "editor": 146, "educated at": 222, "education": 137, "effect": 3, "effect of": 2, "emperor": 35, "employed by": 8, "employer": 1, "employment": 24, "enacted by": 4, "enclave within": 7, "endemic to": 8, "ending": 9, "engine": 23, "engineer": 2, "entered service": 1, "epoch": 4, "eponym": 2, "era": 37, "established": 133, "ethnic group": 5, "ethnicity": 12, "etymology": 1, "event": 142, "exclave of": 34, "executed by": 2, "executive body": 9, "executive branch": 10, "executive producer": 22, "faith": 167, "family": 109, "family name": 1, "famous works": 21, "father": 2872, "female": 2, "fields": 82, "film director": 274, "film editor": 7, "film genre": 13, "film producer": 62, "film starring": 2411, "film studio": 8, "filming location": 2, "finish": 2, "first broadcast": 10, "first described by": 4, "first flight": 2, "first language": 4, "first name": 1, "first performance": 7, "flag": 300, "fleet": 37, "followed by": 290, "follows": 114, "fork of": 8, "forked from": 2, "form of government": 4, "formation": 148, "formed from": 38, "formed out of": 8, "foundation": 9, "founded": 126, "founded by": 803, "founded in": 205, "founder": 2555, "founding date": 1, "fruit of": 6, "funded by": 5, "game engine": 17, "game mode": 1, "gameplay": 9, "garrison": 5, "gauge": 359, "gender": 2, "general manager": 6, "genre": 914, "girlfriend": 39, "given by": 58, "given name": 2, "goal scored by": 1, "godfather": 2, "government": 135, "graduate of": 147, "graduated from": 239, "ground": 298, "group": 1310, "guidance system": 1, "happens in": 5, "head coach": 191, "head of government": 8, "head of state": 106, "heir": 10, "highest judicial authority": 1, "highest peak": 305, "highest point": 194, "highway system": 4, "history": 316, "home field": 47, "home ground": 143, "home port": 2, "home venue": 22, "homeport": 1, "homeworld": 2, "honorary title": 1, "honors": 60, "honours": 13, "hostess": 1, "house": 75, "hub": 194, "hub airport": 2, "husband": 1890, "ideology": 68, "illness": 1, "illustrated by": 49, "illustration by": 1, "illustrator": 9, "imprisoned in": 3, "inaugurated": 8, "inception": 2, "include": 933, "includes": 802, "includes part": 27, "incorporated": 8, "incumbent": 6, "indigenous to": 4, "industry": 296, "inflow": 8, "inflows": 2, "influenced by": 155, "informed by": 4, "ingredient": 8, "inspiration": 5, "inspired by": 4, "instance of": 18, "instruction set": 25, "instrument": 167, "interaction": 2, "intersex": 12, "invented by": 47, "inventor": 78, "investors": 2, "is a": 120191, "is a type of": 383, "is an": 14384, "is in": 84, "is in the borough of": 16, "is in the city of": 57, "is in the county of": 5, "is in the district of": 31, "is in the local government area of": 2, "is in the municipality of": 29, "is in the parish of": 17, "is in the province of": 42, "is in the region of": 4, "is in the state of": 16, "is in the town of": 48, "is in the village of": 63, "is located in": 17021, "is not": 9, "is on": 43, "is owned by": 683, "island": 2860, "issued by": 1, "jail": 1, "job": 70, "jurisdiction": 292, "kids": 11, "killed by": 19, "killer": 8, "kind of": 90, "king": 121, "known for": 406, "label": 6500, "land": 5186, "landing site": 2, "language": 115, "language official": 7, "language spoken": 4, "latitude": 113, "launch date": 4, "launch vehicle": 9, "leader": 573, "league": 4343, "legal holiday": 2, "legislative body": 64, "legislature": 578, "level below": 1, "librettist": 34, "libretto by": 145, "licence": 5, "license": 130, "life partner": 21, "listing": 17, "literary genre": 2, "literary works": 20, "lived in": 37, "local government area": 2, "locality": 8492, "located in": 366, "location": 8, "longitude": 113, "lover": 79, "lowest point": 18, "lyricist": 30, "lyrics by": 161, "made by": 269, "made from": 58, "made of": 36, "maiden flight": 4, "maintained by": 74, "maintenance": 12, "major works": 7, "maker": 66, "makes": 10, "male": 4, "man": 5, "managed by": 43, "manager": 2, "manufactured by": 702, "manufacturer": 480, "manufactures": 19, "married to": 539, "marry": 269, "mascot": 37, "master": 24, "mayor": 64, "measured by": 1, "medals": 6, "medical condition": 1, "medium": 4, "member": 2832, "member of": 2934, "members": 2471, "memorial to": 6, "mentor": 19, "merged into": 37, "merged with": 41, "mistress": 175, "mode": 20, "monarch": 65, "month": 6, "mother": 1024, "mother house": 1, "mother tongue": 6, "motif": 3, "motto": 1, "movement": 378, "movie director": 10, "municipal council": 4, "murdered by": 8, "murderer": 6, "music by": 375, "music genre": 44, "music group": 51, "musical artist": 4, "musical score by": 5, "musician": 433, "named after": 777, "named for": 187, "namesake": 65, "narrator": 1, "nation": 2665, "national holiday": 9, "nationality": 40, "native language": 3, "native to": 7, "network": 903, "next to": 444, "noble family": 11, "nominated for": 1989, "nominee for": 13, "not to be confused with": 3, "notable work": 4, "occupation": 44, "occupied by": 6, "of jurisdiction": 1, "of team": 12, "office held": 8, "official language": 636, "official residence": 73, "on lake": 1, "on shore of": 1, "on the coast of": 92, "on the shore of": 55, "opened": 66, "operated": 68, "operated by": 1867, "operates": 16, "operating system": 190, "operator": 540, "operator of": 1, "orbit": 159, "orbited by": 1, "orbits": 240, "ore": 19, "organiser": 1, "organizer": 3, "original channel": 1, "original language": 5, "original network": 1, "originates from": 4, "outflow": 134, "outflows": 1, "outlet": 65, "overlies": 5, "owned by": 2201, "owner": 404, "owner of": 6, "owns": 1, "painter": 50, "painting of": 8, "parent": 8, "parent club": 1, "parent company": 186, "parent company of": 46, "parent organization": 1, "parent team": 2, "parliament": 936, "part of": 4728, "participant": 8, "participant in": 26, "participant of": 30, "partner": 117, "partner city": 2, "parts": 621, "party": 62, "passed by": 9, "patron": 13, "patron saint": 75, "patron saint of": 5, "pendant of": 4, "performer": 57, "period": 76, "pet": 5, "place of birth": 4, "place of death": 4, "place of origin": 1, "planet": 148, "platform": 304, "platforms": 229, "played by": 11, "played for": 2085, "player": 59, "plays": 396, "plays for": 1782, "political ideology": 2, "political party": 311, "port of registry": 1, "portrait of": 10, "portrayed by": 5, "position held": 1, "powerplant": 2, "precedes": 27, "predecessor": 40, "premier": 44, "premiere": 14, "prequel of": 1, "presented by": 51, "presenter": 55, "president": 156, "prime minister": 78, "principal place": 2, "printed by": 1, "prison": 32, "producer": 374, "produces": 28, "product": 104, "production company": 33, "production designer": 13, "production house": 3, "profession": 65, "professor": 16, "programmer": 3, "programming language": 134, "promotion to": 5, "protected area": 1, "protection": 123, "protocol": 6, "public holiday": 12, "public office": 18, "publication": 2, "published": 36, "published in": 11, "publisher": 151, "publishing house": 10, "pupil": 84, "pupil of": 66, "pupils": 17, "purpose": 9, "queen": 11, "race": 4, "radio format": 2, "radio network": 5, "radio station": 8, "railway line": 106, "rank": 33, "ratified by": 1, "record label": 974, "record producer": 9, "recorded at": 1, "regulatory body": 7, "relative": 9, "release date": 1, "released": 326, "relegation to": 6, "religion": 339, "religious affiliation": 1, "religious order": 22, "repealed by": 1, "replaced": 69, "replaced by": 31, "replaces": 1, "representative": 2, "representative body": 7, "represented by": 10, "residence": 29, "resident in": 7, "resting place": 16, "result": 14, "result of": 4, "river mouth": 13, "rocket engine": 2, "royal house": 14, "runs on": 4, "same as": 1, "satellite": 103, "school": 126, "scientific discipline": 2, "screenplay by": 121, "screenwriter": 234, "script": 779, "scriptwriter": 3, "sculptor": 41, "seat": 200, "seceded from": 1, "section of": 310, "sector": 23, "senior coach": 12, "sentence": 2, "separated from": 14, "sequel is": 1, "sequel of": 8, "series": 2499, "service branch": 2, "service operated": 1, "set of": 81, "sex": 5, "shape": 4, "shareholder": 68, "shares border with": 39, "ship class": 2, "signatory": 3, "signed by": 5, "significant works": 6, "since": 39, "singer": 2756, "sister city": 39, "slain by": 2, "solid solution series with": 8, "son": 9674, "songwriter": 69, "sons": 1374, "sovereign state": 156, "spacecraft": 1, "species": 1, "spin-off": 95, "spin-offs": 1, "split from": 17, "sport": 2307, "sports": 2201, "sports league": 6, "spouse": 104, "square": 17, "stadium": 646, "starring": 15585, "starting": 10, "state": 68073, "stock exchange": 15, "street": 16, "student": 84, "student of": 47, "students": 51, "studied at": 248, "studied under": 20, "studies": 222, "studio": 3, "subclass of": 8, "subdivided into": 53, "subject": 11, "subject of": 8, "subsidiary": 116, "subsidiary company": 11, "subsidiary of": 809, "subsystem of": 3, "successor": 181, "superpartner of": 1, "supervisor": 3, "symptoms": 5, "system of": 95, "takes place in": 5, "taxonomic rank": 3, "teacher": 124, "teacher of": 45, "team": 5774, "team manager": 5, "teams played for": 14, "teleplay by": 3, "television channel": 50, "tenant": 6, "terminus": 110, "territory claimed by": 9, "theme music": 2, "theme song": 3, "therapy": 1, "time": 46, "time zone": 30, "timezone": 2, "tomb": 103, "tonality": 4, "took part": 83, "took part in": 69, "top level domain": 1, "topic": 5, "topic of": 2, "toponym": 2, "town": 65907, "track gauge": 2, "tracklist": 2, "translation of": 56, "translator": 1, "treatment": 283, "treats": 8, "tributary": 1440, "tributary of": 2320, "tunnel under": 12, "twin cities": 2, "twin city": 18, "type of": 990, "type species": 10, "unit of": 4, "universe": 153, "use": 114, "used by": 9, "used for": 27, "used for treatment": 4, "used in": 40, "user": 7, "uses": 11, "utility": 7, "venue": 101, "victory": 1, "video game publisher": 14, "voice actor": 8, "voice type": 1, "voiced by": 84, "war": 908, "weapon": 3, "wife": 7798, "winner": 591, "winners": 229, "woman": 15, "won by": 110, "words by": 3, "work": 825, "working for": 37, "works": 697, "works at": 4, "worshipped by": 1, "writer": 756, "writing system": 45, "written by": 2244, "year": 34, "year of birth": 1}
filtering_purify.py CHANGED
@@ -12,16 +12,14 @@ from matplotlib import pyplot as plt
12
 
13
  from datasets import Dataset
14
 
 
 
15
  sns.set_theme(style="whitegrid")
16
 
17
  # load filtered data
18
  with open(f"data/t_rex.filter.jsonl") as f:
19
- _tmp = [json.loads(i) for i in f.read().split('\n') if len(i) > 0]
20
- tmp += _tmp
21
- splits += [s] * len(_tmp)
22
- data = Dataset.from_list(tmp)
23
- df_main = data.to_pandas()
24
- df_main['split'] = splits
25
 
26
 
27
  def is_entity(token):
@@ -71,7 +69,6 @@ def main(min_entity_freq, max_pairs_predicate, min_pairs_predicate: int = 3, ran
71
  [g if len(g) <= max_pairs_predicate else g.sort_values(by='count_sum', ascending=False).head(max_pairs_predicate) for _, g in
72
  df_filter.groupby("predicate") if len(g) >= min_pairs_predicate])
73
 
74
-
75
  df_balanced.pop("count_subject")
76
  df_balanced.pop("count_object")
77
  df_balanced.pop("count_sum")
@@ -89,24 +86,19 @@ if __name__ == '__main__':
89
  e_dist_full = []
90
  data_size_full = []
91
  config = []
92
- candidates = list(product([4, 8, 12, 16], [100, 50, 25, 10]))
93
 
94
  # run filtering with different configs
95
  for min_e_freq, max_p_freq in candidates:
96
- p_dist, e_dist, data_size, new_data = main(min_entity_freq=min_e_freq, max_pairs_predicate=max_p_freq, random_sampling=False)
 
97
  p_dist_full.append(p_dist)
98
  e_dist_full.append(e_dist)
99
  data_size_full.append(data_size)
100
  config.append([min_e_freq, max_p_freq])
101
  # save data
102
- out = {}
103
- for s in ['train', 'validation', 'test']:
104
- out[s] = [i for i in new_data if i['split'] == s]
105
- for s, v in out.items():
106
- for i in v:
107
- i.pop('split')
108
- with open(f"data/t_rex.clean.min_entity_{min_e_freq}_max_predicate_{max_p_freq}.{s}.jsonl", 'w') as f:
109
- f.write('\n'.join([json.dumps(i) for i in new_data_s]))
110
 
111
  # check statistics
112
  print("- Data Size")
 
12
 
13
  from datasets import Dataset
14
 
15
+ parameters_min_e_freq = [4, 8, 12, 16]
16
+ parameters_max_p_freq = [100, 50, 25, 10]
17
  sns.set_theme(style="whitegrid")
18
 
19
  # load filtered data
20
  with open(f"data/t_rex.filter.jsonl") as f:
21
+ data = Dataset.from_list([json.loads(i) for i in f.read().split('\n') if len(i) > 0])
22
+ df_main = data.to_pandas()
 
 
 
 
23
 
24
 
25
  def is_entity(token):
 
69
  [g if len(g) <= max_pairs_predicate else g.sort_values(by='count_sum', ascending=False).head(max_pairs_predicate) for _, g in
70
  df_filter.groupby("predicate") if len(g) >= min_pairs_predicate])
71
 
 
72
  df_balanced.pop("count_subject")
73
  df_balanced.pop("count_object")
74
  df_balanced.pop("count_sum")
 
86
  e_dist_full = []
87
  data_size_full = []
88
  config = []
89
+ candidates = list(product(parameters_min_e_freq, parameters_max_p_freq))
90
 
91
  # run filtering with different configs
92
  for min_e_freq, max_p_freq in candidates:
93
+ p_dist, e_dist, data_size, new_data = main(
94
+ min_entity_freq=min_e_freq, max_pairs_predicate=max_p_freq, random_sampling=False)
95
  p_dist_full.append(p_dist)
96
  e_dist_full.append(e_dist)
97
  data_size_full.append(data_size)
98
  config.append([min_e_freq, max_p_freq])
99
  # save data
100
+ with open(f"data/t_rex.filter.min_entity_{min_e_freq}_max_predicate_{max_p_freq}.jsonl", 'w') as f:
101
+ f.write('\n'.join([json.dumps(i) for i in new_data]))
 
 
 
 
 
 
102
 
103
  # check statistics
104
  print("- Data Size")