forked from mailong25/bert-vietnamese-question-answering
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
32 lines (23 loc) · 1022 Bytes
/
main.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
from gg_search import GoogleSearch
ggsearch = GoogleSearch()
from relevance_ranking import rel_ranking
from reader import Reader
reader = Reader()
if __name__ == "__main__":
question = 'ai là người giàu nhất Việt Nam'
#Using google to find relevant documents
links, documents = ggsearch.search(question)
#Find relevant passages from documents
passages = rel_ranking(question,documents)
# Select top 40 paragraphs
passages = passages[:40]
#Using reading comprehend model (BERT) to extract answer for each passage
answers = reader.getPredictions(question,passages)
#Reranking passages by answer score
answers = [[passages[i], answers[i][0],answers[i][1]] for i in range(0,len(answers))]
answers = [a for a in answers if a[1] != '']
answers.sort(key = lambda x : x[2],reverse=True)
print("Final result: ")
print("Passage: ", answers[0][0])
print("Answer : ", answers[0][1])
print("Score : ", answers[0][2])