-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathhuman_FB13_data.py
45 lines (34 loc) · 1.41 KB
/
human_FB13_data.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
import numpy as np
idx = np.random.choice(23733, 50)
ent2txt = {}
with open("data/FB13/entity2text_capital.txt", "r") as f:
lines = f.readlines()
for line in lines:
tmp = line.strip().split("\t")
ent2txt[tmp[0]] = tmp[1]
rel2txt = {}
with open("data/FB13/relation2text.txt", "r") as f:
lines = f.readlines()
for line in lines:
tmp = line.strip().split("\t")
rel2txt[tmp[0]] = tmp[1]
lines_to_write = []
with open("data/FB13/test.tsv", "r") as f:
lines = f.readlines()
for i in idx:
pos_line = lines[2*i]
tmp = pos_line.strip().split("\t")
prompt = "Is this true: " + ent2txt[tmp[0]] + " " + rel2txt[tmp[1]] + " " + ent2txt[tmp[2]] + "?"
response = ""
triple_txt = ent2txt[tmp[0]] + " " + rel2txt[tmp[1]] + " " + ent2txt[tmp[2]]
print(tmp[3] + "\t" + prompt)
lines_to_write.append(tmp[3] + "\t" + prompt + "\n")
neg_line = lines[2*i + 1]
tmp = neg_line.strip().split("\t")
prompt = "Is this true: " + ent2txt[tmp[0]] + " " + rel2txt[tmp[1]] + " " + ent2txt[tmp[2]] + "?"
response = ""
triple_txt = ent2txt[tmp[0]] + " " + rel2txt[tmp[1]] + " " + ent2txt[tmp[2]]
print(tmp[3] + "\t" + prompt)
lines_to_write.append(tmp[3] + "\t" + prompt + "\n")
with open("data/FB13/FB13_test_human.tsv", "w") as f:
f.writelines(lines_to_write)