Repository navigation
Expand file tree
/
Copy pathtesting.py
More file actions
52 lines (37 loc) · 1.56 KB
/
Copy pathtesting.py
File metadata and controls
52 lines (37 loc) · 1.56 KB
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
from answer import *
def testAnswer():
article = open("data/set5/a5.txt", "r", encoding="UTF-8").read()
questions = open("data/set5/q5.txt", "r", encoding="UTF-8").read()
correctAnswers = open("data/set5/a5_correct.txt", encoding="UTF-8").read().splitlines()
answer = Answer(article, questions)
answer.preprocess()
qsObjLst = answer.similarity(distFunc=cosine, k = 1, model="distilroberta-base-msmarco-v2")
scoring = []
noAns = 0
for qInd in range(len(qsObjLst)):
qObj = qsObjLst[qInd]
# Scoring answer
answerScore = None
actualAnswerSent = correctAnswers[qInd]
# Get question
orgQuestion = qObj.raw_question
print("Question {}: {}".format(qInd, qObj.raw_question))
print("Correct Answer: {}".format(actualAnswerSent))
for i in range(len(qObj.answers)):
# Get answer
orgAnswer = qObj.answers[i]
print("Answer {}: {}".format(i, orgAnswer))
print("Found Answer:")
print(answer.answerQuestion(orgQuestion, orgAnswer))
print("\n")
if orgAnswer.text == actualAnswerSent:
answerScore = i
if answerScore is None:
scoring.append("No Answer")
noAns += 1
else:
scoring.append(str(answerScore))
print("\n")
return scoring, len(scoring) - noAns # list of index where answer is found, if any (No Answer o/w) and the number correct
if __name__ == "__main__":
print(testAnswer())