Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
ease
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
ease
Commits
9c16fbbe
Commit
9c16fbbe
authored
Jun 13, 2014
by
gradyward
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Finalized consistent Error Checking, and added myself to the AUTHORS document
parent
0a4d39d7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
58 additions
and
24 deletions
+58
-24
AUTHORS
+2
-0
ease/create.py
+1
-1
ease/errors.py
+39
-6
ease/essay_set.py
+2
-1
ease/feature_extractor.py
+8
-2
ease/grade.py
+6
-5
ease/util_functions.py
+0
-9
No files found.
AUTHORS
View file @
9c16fbbe
...
...
@@ -4,3 +4,4 @@ John Jarvis <jarv@edx.org>
James Tauber <jtauber@jtauber.com>
Nate Aune <naune@edx.org>
John Kern <kern3020@gmail.com>
Grady Ward <gward@brandeis.edu>
\ No newline at end of file
ease/create.py
View file @
9c16fbbe
...
...
@@ -69,7 +69,7 @@ def create(examples, scores, prompt_string, dump_data=False):
# Create an essay set object that encapsulates all the essays and alternate representations (tokens, etc)
try
:
essay_set
=
_create_essay_set
(
examples
,
scores
,
prompt_string
)
except
(
EssaySetRequestError
,
ExampleCreationInternalError
)
as
ex
:
except
EssaySetRequestError
as
ex
:
msg
=
"Essay Set Creation failed (likely due to an error in essay cleaning/parsing) {}"
.
format
(
ex
)
results
[
'errors'
]
.
append
(
msg
)
log
.
exception
(
msg
)
...
...
ease/errors.py
View file @
9c16fbbe
...
...
@@ -2,20 +2,52 @@
Errors for the EASE repository
"""
class
E
ssaySetRequest
Error
(
Exception
):
class
E
ase
Error
(
Exception
):
pass
class
ExampleCreationInternalError
(
Exception
):
class
EssaySetRequestError
(
EaseError
):
"""
There was a problem with a request sent to the Essay Set module.
"""
pass
class
EaseError
(
Exception
):
class
GradingRequestError
(
EaseError
):
"""
There was a problem with a request sent to the Grading module.
"""
pass
class
GradingRequestError
(
Exception
):
class
ClassifierTrainingInternalError
(
EaseError
):
"""
An unexpected error occurred when training a classifier.
"""
pass
class
ClassifierTrainingInternalError
(
Exception
):
class
CreateRequestError
(
EaseError
):
"""
There was a problem with a request sent to the Create Module.
"""
pass
class
CreateRequestError
(
Exception
):
class
FeatureExtractionInternalError
(
EaseError
):
"""
An unexpected error occurred while extracting features from an essay.
"""
pass
class
InputError
(
EaseError
):
"""
The user supplied an argument which was incorrect.
"""
def
__init__
(
self
,
expr
,
msg
):
self
.
expr
=
expr
self
.
msg
=
msg
def
__str__
(
self
):
"An input error occurred at '{0}': {1}"
.
format
(
self
.
expr
,
self
.
msg
)
\ No newline at end of file
ease/essay_set.py
View file @
9c16fbbe
...
...
@@ -8,6 +8,7 @@ import sys
import
random
import
os
import
logging
from
ease.errors
import
InputError
from
errors
import
*
base_path
=
os
.
path
.
dirname
(
__file__
)
...
...
@@ -171,7 +172,7 @@ class EssaySet(object):
if
isinstance
(
prompt_text
,
basestring
):
self
.
_prompt
=
util_functions
.
sub_chars
(
prompt_text
)
else
:
raise
util_functions
.
InputError
(
prompt_text
,
"Invalid prompt. Need to enter a string value."
)
raise
InputError
(
'prompt_text'
,
"Invalid prompt. Need to enter a string value."
)
return
self
.
_prompt
def
generate_additional_essays
(
self
,
original_essay
,
original_score
,
to_generate
=
3
):
...
...
ease/feature_extractor.py
View file @
9c16fbbe
...
...
@@ -11,6 +11,7 @@ import os
from
itertools
import
chain
import
operator
import
logging
from
errors
import
*
base_path
=
os
.
path
.
dirname
(
__file__
)
sys
.
path
.
append
(
base_path
)
...
...
@@ -100,9 +101,9 @@ class FeatureExtractor(object):
# Average index of how "topical" essays are
self
.
_mean_topical_index
=
feature_row_sum
/
float
(
sum
([
len
(
t
)
for
t
in
essay_set
.
_cleaned_essays
]))
else
:
raise
util_functions
.
InputError
(
essay_set
,
"needs to be an essay set of the train
type."
)
raise
InputError
(
'essay_set'
,
"The EssaySet provided needs to be an EssaySet of the 'train'
type."
)
else
:
raise
util_functions
.
InputError
(
essay_set
,
"wrong input. need an essay s
et object."
)
raise
InputError
(
'essay_set'
,
"Wrong input provided, it must provide an EssayS
et object."
)
def
generate_features
(
self
,
essay_set
):
"""
...
...
@@ -117,9 +118,14 @@ class FeatureExtractor(object):
- Vocabulary Features (both Normal and Stemmed Vocabulary)
- Prompt Features
"""
try
:
vocabulary_features
=
self
.
_generate_vocabulary_features
(
essay_set
)
length_features
=
self
.
_generate_length_features
(
essay_set
)
prompt_features
=
self
.
_generate_prompt_features
(
essay_set
)
except
Exception
as
ex
:
msg
=
"An unexpected error occurred during feature extraction: {}"
.
format
(
ex
)
log
.
exception
(
msg
)
raise
FeatureExtractionInternalError
(
msg
)
# Lumps them all together, copies to solidify, and returns
overall_features
=
numpy
.
concatenate
((
length_features
,
prompt_features
,
vocabulary_features
),
axis
=
1
)
...
...
ease/grade.py
View file @
9c16fbbe
...
...
@@ -2,10 +2,12 @@
Functions to score specified data using specified ML models
"""
import
sys
import
os
import
logging
import
sys
# Append sys to base path to import the following modules
base_path
=
os
.
path
.
dirname
(
__file__
)
sys
.
path
.
append
(
base_path
)
...
...
@@ -52,18 +54,17 @@ def grade(grader_data, submission):
try
:
grader_set
.
add_essay
(
str
(
submission
),
0
)
grader_set
.
update_prompt
(
str
(
grader_data
[
'prompt'
]))
except
:
except
(
EssaySetRequestError
,
InputError
)
:
error_message
=
"Essay could not be added to essay set:{0}"
.
format
(
submission
)
log
.
exception
(
error_message
)
results
[
'errors'
]
.
append
(
error_message
)
# Tries to extract features from submission and assign score via the model
grader_features
=
None
try
:
grader_features
=
extractor
.
generate_features
(
grader_set
)
results
[
'score'
]
=
int
(
model
.
predict
(
grader_features
)[
0
])
except
:
error_message
=
"Could not extract features and score essay
."
except
FeatureExtractionInternalError
as
ex
:
error_message
=
"Could not extract features and score essay
: {ex}"
.
format
(
ex
=
ex
)
log
.
exception
(
error_message
)
results
[
'errors'
]
.
append
(
error_message
)
...
...
ease/util_functions.py
View file @
9c16fbbe
...
...
@@ -200,15 +200,6 @@ def get_vocab(essays, scores, max_features_pass_1=750, max_features_pass_2=200):
return
vocab
class
InputError
(
Exception
):
"""
A class to report to the user that one of their inputs was incorrect.
"""
def
__init__
(
self
,
expr
,
msg
):
self
.
expr
=
expr
self
.
msg
=
msg
def
gen_cv_preds
(
clf
,
arr
,
sel_score
,
num_chunks
=
3
):
"""
Generates cross validated predictions using an input classifier and data.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment