-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathexpert_linking.py
62 lines (46 loc) · 1.55 KB
/
expert_linking.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
import os
import torch
import torch.nn as nn
import json
from data_processer import newsProcessor
from model_init import expertLinking
import tqdm
def is_chinese(uchar):
if uchar >= u'\u4e00' and uchar<=u'\u9fa5':
return True
else:
return False
# Load essential files
# Pre-align authors in news to the candidates in AMiner.
with open("news2aminer2aid.json", 'r') as files:
name2aid2pid = json.load(files)
# Paper information
with open("aminer_pub_dict.json", 'r') as files:
pub_dict = json.load(files)
# News information
with open("news_info.json", 'r') as files:
process_news = json.load(files)
mention2res = []
for news_id, attr in process_news.items():
mentions = attr["mention2result"]
for author_name, attr in mentions.items():
try:
name_alias = attr["alias"]
except:
name_alias = ""
# Ground truth to evaluate predictions.
aminer_id = "---".join(attr["ids"])
tag = is_chinese(author_name)
if(tag == False):
mention2res.append((author_name, author_name, aminer_id, news_id))
else:
mention2res.append((author_name, name_alias, aminer_id, news_id))
# Device
local_device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
data_pro = newsProcessor(local_device)
# Process text info
test_news, test_info = data_pro.generate_test_news(mention2res, process_news, name2aid2pid, pub_dict)
# load model
linking_model = expertLinking(local_device)
# perform linking
linking_model.perform_linking(test_news, test_info)