asahi417 commited on
Commit
8196f05
1 Parent(s): e2c3b09

Update process.py

Browse files
Files changed (1) hide show
  1. process.py +4 -38
process.py CHANGED
@@ -7,8 +7,8 @@ import pandas as pd
7
  from datasets import load_dataset
8
 
9
 
10
- def process(name, split, output):
11
- data = load_dataset("relbert/t_rex", name, split=split)
12
  df = data.to_pandas()
13
  df.pop('text')
14
  df.pop('title')
@@ -22,43 +22,9 @@ def process(name, split, output):
22
  f.write('\n'.join([json.dumps(i) for i in rel_sim_data]))
23
 
24
 
25
- parameters_min_e_freq = [1, 2, 3, 4]
26
- parameters_max_p_freq = [100, 50, 25, 10]
27
  os.makedirs("data", exist_ok=True)
28
 
29
- for min_e_freq, max_p_freq in product(parameters_min_e_freq, parameters_max_p_freq):
30
- for s in ['train', 'validation']:
31
- process(
32
- name=f"filter_unified.min_entity_{min_e_freq}_max_predicate_{max_p_freq}",
33
- split=s,
34
- output=f"data/filter_unified.min_entity_{min_e_freq}_max_predicate_{max_p_freq}.{s}.jsonl")
35
 
36
- process(
37
- name=f"filter_unified.min_entity_{min_e_freq}_max_predicate_{max_p_freq}",
38
- split='test',
39
- output=f"data/filter_unified.test.jsonl")
40
-
41
-
42
- stats = []
43
- for min_e_freq, max_p_freq in product(parameters_min_e_freq, parameters_max_p_freq):
44
- stats_tmp = {"data": f"filter_unified.min_entity_{min_e_freq}_max_predicate_{max_p_freq}"}
45
- for s in ['train', 'validation']:
46
- with open(f"data/filter_unified.min_entity_{min_e_freq}_max_predicate_{max_p_freq}.{s}.jsonl") as f:
47
- tmp = [json.loads(i) for i in f.read().split('\n') if len(i) > 0]
48
- stats_tmp[f'num of relation types ({s})'] = len(tmp)
49
- stats_tmp[f'average num of positive pairs ({s})'] = round(mean([len(i['positives']) for i in tmp]))
50
- stats_tmp[f'average num of negative pairs ({s})'] = round(mean([len(i['negatives']) for i in tmp]))
51
- stats.append(stats_tmp)
52
- df_stats = pd.DataFrame(stats)
53
- df_stats.index = df_stats.pop('data')
54
- print(df_stats.to_markdown())
55
-
56
- stats_tmp = {}
57
- with open("data/filter_unified.test.jsonl") as f:
58
- tmp = [json.loads(i) for i in f.read().split('\n') if len(i) > 0]
59
- stats_tmp[f'num of relation types (test)'] = len(tmp)
60
- stats_tmp[f'average num of positive pairs (test)'] = round(mean([len(i['positives']) for i in tmp]))
61
- stats_tmp[f'average num of negative pairs (test)'] = round(mean([len(i['negatives']) for i in tmp]))
62
- df_stats_test = pd.DataFrame([stats_tmp])
63
- print(df_stats_test.to_markdown(index=False))
64
 
 
7
  from datasets import load_dataset
8
 
9
 
10
+ def process(split, output):
11
+ data = load_dataset("relbert/t_rex", split=split)
12
  df = data.to_pandas()
13
  df.pop('text')
14
  df.pop('title')
 
22
  f.write('\n'.join([json.dumps(i) for i in rel_sim_data]))
23
 
24
 
 
 
25
  os.makedirs("data", exist_ok=True)
26
 
27
+ for s in ['train', 'validation', 'test']:
28
+ process(split=s, output=f"data/filter_unified.{s}.jsonl")
 
 
 
 
29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30