-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpretrainedGrader.py
More file actions
executable file
·68 lines (45 loc) · 2.46 KB
/
pretrainedGrader.py
File metadata and controls
executable file
·68 lines (45 loc) · 2.46 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
''' Given a question, a reference answer, and a student response, this
pretrained grader computes a score in % for the student answer based on
how semantically similar it is to the reference answer. '''
from featureExtraction import *
import numpy as np
def extract_features(question, ref_answer, student_response):
sim_alignment, cov_alignment, parse_results = \
sts_alignment(ref_answer, student_response)
q_demoted_sim_alignment, q_demoted_cov_alignment, _ = \
sts_alignment(ref_answer, student_response,
parse_results,
question)
sim_cvm = sts_cvm(ref_answer, student_response, parse_results)
q_demoted_sim_cvm = sts_cvm(ref_answer, student_response,
parse_results,
question)
lr = length_ratio(ref_answer, student_response, parse_results)
feature_vector = (sim_alignment, cov_alignment,
q_demoted_sim_alignment, q_demoted_cov_alignment,
sim_cvm,
q_demoted_sim_cvm,
lr)
return feature_vector
def grade(question, ref_answer, student_response):
feature_vector = extract_features(question, ref_answer, student_response)
''' The following weights are learned from the dataset (all examples)
reported by Mohler, Bunescu, and Mihalcea in their 2011 paper "Learning
to Grade Short Answer Questions using Semantic Similarity Measures and
Dependency Graph Alignments" '''
w = [.572813656856, .06392481, .04797512, .00484819, .19755009,
.07454364, .13800417, .00385674]
score = np.dot(w, [1]+list(feature_vector))
score = min(1, score)
score = max(0, score)
score *= 100
return int((score * 100) + 0.5) / 100.0
''' below is an example of grading an answer '''
question = "How are infix expressions evaluated by computers?"
ref_answer = "First, they are converted into postfix form, " + \
"followed by an evaluation of the postfix expression."
student_response = "computers usually convert infix expressions to postfix " +\
"expression and evaluate them using a stack."
score = grade(question, ref_answer, student_response)
print
print 'score for this student response = ' + str(score) + '%'