-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_stats.py
79 lines (67 loc) · 2.16 KB
/
get_stats.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import json
import re
def get_relations_gpt(data):
relations = set()
for row in data:
triples = row["chat-gpt"]
for triple in triples:
relations.add(triple[1])
return len(relations)
def get_entities_gpt(data):
count = 0
for row in data:
entities = set()
triples = row["chat-gpt"]
for triple in triples:
entities.add(triple[0])
entities.add(triple[2])
count += len(entities)
return count
def get_relations_rebel(data):
relations = set()
for row in data:
triples = row["gpt_answer"]
for triple in triples:
item_lst = re.findall(r'<([^>]*)>', triple[0])
relations.add(item_lst[1])
return len(relations)
def get_entities_rebel(data):
count = 0
for row in data:
entities = set()
triples = row["gpt_answer"]
for triple in triples:
item_lst = re.findall(r'<([^>]*)>', triple[0])
entities.add(item_lst[0])
entities.add(item_lst[2])
count += len(entities)
return count
def get_relations_rebel_filtered(data):
relations = set()
for row in data:
triples = row["gpt_answer"]
for triple in triples:
if triple[1]==1:
item_lst = re.findall(r'<([^>]*)>', triple[0])
relations.add(item_lst[1])
return len(relations)
def get_entities_rebel_filtered(data):
count = 0
for row in data:
entities = set()
triples = row["gpt_answer"]
for triple in triples:
if triple[1]==1:
item_lst = re.findall(r'<([^>]*)>', triple[0])
entities.add(item_lst[0])
entities.add(item_lst[2])
count += len(entities)
return count
gpt_data = json.load(open("data/data_gpt4.json", "r", encoding="utf-8"))
rebel_data = json.load(open("results/results_final.json", "r", encoding="utf-8"))
print(get_relations_gpt(gpt_data))
print(get_relations_rebel(rebel_data))
print(get_relations_rebel_filtered(rebel_data))
print(get_entities_gpt(gpt_data))
print(get_entities_rebel(rebel_data))
print(get_entities_rebel_filtered(rebel_data))