Commit 152e23d6 by Vik Paruchuri

Change feedback generation, and change off topic indicator

parent d718322b
...@@ -12,6 +12,7 @@ import os ...@@ -12,6 +12,7 @@ import os
from itertools import chain from itertools import chain
import copy import copy
import operator import operator
import logging
base_path = os.path.dirname(__file__) base_path = os.path.dirname(__file__)
sys.path.append(base_path) sys.path.append(base_path)
...@@ -21,6 +22,8 @@ import util_functions ...@@ -21,6 +22,8 @@ import util_functions
if not base_path.endswith("/"): if not base_path.endswith("/"):
base_path=base_path+"/" base_path=base_path+"/"
log = logging.getLogger(__name__)
class FeatureExtractor(object): class FeatureExtractor(object):
def __init__(self): def __init__(self):
...@@ -46,7 +49,7 @@ class FeatureExtractor(object): ...@@ -46,7 +49,7 @@ class FeatureExtractor(object):
self._grammar_errors_per_character=1-(sum(self._get_grammar_errors self._grammar_errors_per_character=1-(sum(self._get_grammar_errors
(e_set._pos,e_set._text,e_set._tokens)[0])/float(sum([len(t) for t in e_set._text]))) (e_set._pos,e_set._text,e_set._tokens)[0])/float(sum([len(t) for t in e_set._text])))
bag_feats=self.gen_bag_feats(e_set) bag_feats=self.gen_bag_feats(e_set)
f_row_sum=numpy.sum(bag_feats[:,:])/bag_feats.shape[0] f_row_sum=numpy.sum(bag_feats[:,:])
self._mean_f_prop=f_row_sum/float(sum([len(t) for t in e_set._text])) self._mean_f_prop=f_row_sum/float(sum([len(t) for t in e_set._text]))
ret = "ok" ret = "ok"
else: else:
...@@ -224,7 +227,7 @@ class FeatureExtractor(object): ...@@ -224,7 +227,7 @@ class FeatureExtractor(object):
if features is not None: if features is not None:
f_row_sum=numpy.sum(features[m,12:]) f_row_sum=numpy.sum(features[m,12:])
f_row_prop=f_row_sum/len(e_set._text[m]) f_row_prop=f_row_sum/len(e_set._text[m])
if f_row_prop<(self._mean_f_prop): if f_row_prop<(self._mean_f_prop/1.5) or len(e_set._text[m])<20:
individual_feedback['topicality']="Essay may be off topic." individual_feedback['topicality']="Essay may be off topic."
markup_string=" ".join(markup_tokens) markup_string=" ".join(markup_tokens)
individual_feedback['markup_text']=markup_string individual_feedback['markup_text']=markup_string
......
...@@ -74,7 +74,8 @@ error_template = u""" ...@@ -74,7 +74,8 @@ error_template = u"""
def grade(grader_path,grader_config,submission,sandbox=None): def grade(grader_path,grader_config,submission,sandbox=None):
if not grader_path.endswith(".p"): if not grader_path.endswith(".p"):
model_path+=".p" grader_path+=".p"
log.debug("Grader path: {0}\n Submission: {1}".format(grader_path,submission)) log.debug("Grader path: {0}\n Submission: {1}".format(grader_path,submission))
results = {'errors': [],'tests': [],'correct': False,'score': 0, 'feedback' : ""} results = {'errors': [],'tests': [],'correct': False,'score': 0, 'feedback' : ""}
...@@ -100,7 +101,7 @@ def grade(grader_path,grader_config,submission,sandbox=None): ...@@ -100,7 +101,7 @@ def grade(grader_path,grader_config,submission,sandbox=None):
#Try to extract features from submission and assign score via the model #Try to extract features from submission and assign score via the model
try: try:
grader_feats=grader_data['extractor'].gen_feats(grader_set) grader_feats=grader_data['extractor'].gen_feats(grader_set)
feedback=grader_data['extractor'].gen_feedback(grader_set)[0] feedback=grader_data['extractor'].gen_feedback(grader_set,grader_feats)[0]
results['score']=int(grader_data['model'].predict(grader_feats)[0]) results['score']=int(grader_data['model'].predict(grader_feats)[0])
except : except :
results['errors'].append("Could not extract features and score essay.") results['errors'].append("Could not extract features and score essay.")
...@@ -130,4 +131,5 @@ def grade(grader_path,grader_config,submission,sandbox=None): ...@@ -130,4 +131,5 @@ def grade(grader_path,grader_config,submission,sandbox=None):
return results return results
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment