Commit 51d33f29 by VikParuchuri

Merge pull request #9 from MITx/vik/deployment_work

Vik/deployment work
parents ed930658 18fdc2ab
......@@ -3,3 +3,4 @@ __pycache__/
models/
*.pyc
*~
tests/
aspell
\ No newline at end of file
"""
Functions that create a machine learning model from training data
"""
import os
import sys
import logging
log = logging.getLogger(__name__)
from statsd import statsd
import numpy
#Define base path and add to sys path
base_path = os.path.dirname(__file__)
sys.path.append(base_path)
one_up_path = os.path.abspath(os.path.join(os.path.dirname(__file__),'..'))
sys.path.append(one_up_path)
#Import modules that are dependent on the base path
import model_creator
import util_functions
import predictor_set
import predictor_extractor
from statsd import statsd
#Make a log
log = logging.getLogger(__name__)
@statsd.timed('open_ended_assessment.machine_learning.creator.time')
def create(text,score,prompt_string,model_path):
def create(text,score,prompt_string):
"""
Creates a machine learning model from input text, associated scores, a prompt, and a path to the model
TODO: Remove model path argument, it is needed for now to support legacy code
text - A list of strings containing the text of the essays
score - a list of integers containing score values
prompt_string - the common prompt for the set of essays
"""
#Initialize a results dictionary to return
results = {'errors': [],'success' : False, 'cv_kappa' : 0, 'cv_mean_absolute_error': 0,
'feature_ext' : "", 'classifier' : ""}
'feature_ext' : "", 'classifier' : "", 'algorithm' : util_functions.AlgorithmTypes.classification,
'score' : score, 'text' : text, 'prompt' : prompt_string}
if len(text)!=len(score):
msg = "Target and text lists must be same length."
......@@ -28,18 +44,30 @@ def create(text,score,prompt_string,model_path):
log.exception(msg)
return results
#Decide what algorithm to use (regression or classification)
try:
if len(util_functions.f7(list(score)))>5:
type = util_functions.AlgorithmTypes.regression
else:
type = util_functions.AlgorithmTypes.classification
except:
type = util_functions.AlgorithmTypes.regression
try:
#Create an essay set object that encapsulates all the essays and alternate representations (tokens, etc)
e_set = model_creator.create_essay_set(text, score, prompt_string)
except:
msg = "essay set creation failed."
results['errors'].append(msg)
log.exception(msg)
try:
feature_ext, classifier, cv_error_results = model_creator.extract_features_and_generate_model(e_set)
#Gets features from the essay set and computes error
feature_ext, classifier, cv_error_results = model_creator.extract_features_and_generate_model(e_set, type=type)
results['cv_kappa']=cv_error_results['kappa']
results['cv_mean_absolute_error']=cv_error_results['mae']
results['feature_ext']=feature_ext
results['classifier']=classifier
results['algorithm'] = type
results['success']=True
except:
msg = "feature extraction and model creation failed."
......@@ -53,7 +81,17 @@ def create(text,score,prompt_string,model_path):
return results
def create_generic(numeric_values, textual_values, target, model_path, algorithm = util_functions.AlgorithmTypes.regression):
def create_generic(numeric_values, textual_values, target, algorithm = util_functions.AlgorithmTypes.regression):
"""
Creates a model from a generic list numeric values and text values
numeric_values - A list of lists that are the predictors
textual_values - A list of lists that are the predictors
(each item in textual_values corresponds to the similarly indexed counterpart in numeric_values)
target - The variable that we are trying to predict. A list of integers.
algorithm - the type of algorithm that will be used
"""
#Initialize a result dictionary to return.
results = {'errors': [],'success' : False, 'cv_kappa' : 0, 'cv_mean_absolute_error': 0,
'feature_ext' : "", 'classifier' : "", 'algorithm' : algorithm}
......@@ -64,6 +102,7 @@ def create_generic(numeric_values, textual_values, target, model_path, algorithm
return results
try:
#Initialize a predictor set object that encapsulates all of the text and numeric predictors
pset = predictor_set.PredictorSet(type="train")
for i in xrange(0, len(numeric_values)):
pset.add_row(numeric_values[i], textual_values[i], target[i])
......@@ -73,6 +112,7 @@ def create_generic(numeric_values, textual_values, target, model_path, algorithm
log.exception(msg)
try:
#Extract all features and then train a classifier with the features
feature_ext, classifier, cv_error_results = model_creator.extract_features_and_generate_model_predictors(pset, algorithm)
results['cv_kappa']=cv_error_results['kappa']
results['cv_mean_absolute_error']=cv_error_results['mae']
......
cv_pred actual
\ No newline at end of file
sudo apt-get update
sudo apt-get upgrade gcc
sudo xargs -a apt-packages.txt apt-get install
sudo pip install virtualenv
sudo mkdir /opt/edx
source /opt/edx/bin/activate
cd /opt/wwc/machine-learning
pip install numpy
pip install scipy
pip install -r requirements.txt
cd opt/wwc/machine-learning
pup install -r requirements.txt
python -m nltk.downloader maxent_treebank_pos_tagger wordnet
sudo mv /path/to/nltk_data /usr/share
\ No newline at end of file
......@@ -77,7 +77,10 @@ class EssaySet(object):
self._id.append(max_id + 1)
self._score.append(essay_score)
# Clean text by removing non digit/work/punctuation characters
essay_text=str(essay_text.encode('ascii', 'ignore'))
try:
essay_text=str(essay_text.encode('ascii', 'ignore'))
except:
essay_text = (essay_text.decode('utf-8','replace')).encode('ascii','ignore')
cleaned_essay=util_functions.sub_chars(essay_text).lower()
if(len(cleaned_essay)>MAXIMUM_ESSAY_LENGTH):
cleaned_essay=cleaned_essay[0:MAXIMUM_ESSAY_LENGTH]
......
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
The names of its contributors may not be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JEET SUKUMARAN OR MARK T. HOLDER BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\ No newline at end of file
......@@ -24,6 +24,9 @@ if not base_path.endswith("/"):
log = logging.getLogger(__name__)
#Paths to needed data files
NGRAM_PATH = base_path + "data/good_pos_ngrams.p"
ESSAY_CORPUS_PATH = util_functions.ESSAY_CORPUS_PATH
class FeatureExtractor(object):
def __init__(self):
......@@ -41,17 +44,26 @@ class FeatureExtractor(object):
"""
if(hasattr(e_set, '_type')):
if(e_set._type == "train"):
#normal text (unstemmed) useful words/bigrams
nvocab = util_functions.get_vocab(e_set._text, e_set._score, max_feats2 = max_feats2)
#stemmed and spell corrected vocab useful words/ngrams
svocab = util_functions.get_vocab(e_set._clean_stem_text, e_set._score, max_feats2 = max_feats2)
#dictionary trained on proper vocab
self._normal_dict = CountVectorizer(ngram_range=(1,2), vocabulary=nvocab)
#dictionary trained on proper vocab
self._stem_dict = CountVectorizer(ngram_range=(1,2), vocabulary=svocab)
self.dict_initialized = True
#Average spelling errors in set. needed later for spelling detection
self._mean_spelling_errors=sum(e_set._spelling_errors)/float(len(e_set._spelling_errors))
self._spell_errors_per_character=sum(e_set._spelling_errors)/float(sum([len(t) for t in e_set._text]))
#Gets the number and positions of grammar errors
good_pos_tags,bad_pos_positions=self._get_grammar_errors(e_set._pos,e_set._text,e_set._tokens)
self._grammar_errors_per_character=(sum(good_pos_tags)/float(sum([len(t) for t in e_set._text])))
#Generate bag of words features
bag_feats=self.gen_bag_feats(e_set)
#Sum of a row of bag of words features (topical words in an essay)
f_row_sum=numpy.sum(bag_feats[:,:])
#Average index of how "topical" essays are
self._mean_f_prop=f_row_sum/float(sum([len(t) for t in e_set._text]))
ret = "ok"
else:
......@@ -65,13 +77,13 @@ class FeatureExtractor(object):
Gets a list of gramatically correct part of speech sequences from an input file called essaycorpus.txt
Returns the list and caches the file
"""
if(os.path.isfile(base_path + "good_pos_ngrams.p")):
good_pos_ngrams = pickle.load(open(base_path + 'good_pos_ngrams.p', 'rb'))
elif os.path.isfile(base_path + "essaycorpus.txt"):
essay_corpus = open(base_path + "essaycorpus.txt").read()
if(os.path.isfile(NGRAM_PATH)):
good_pos_ngrams = pickle.load(open(NGRAM_PATH, 'rb'))
elif os.path.isfile(ESSAY_CORPUS_PATH):
essay_corpus = open(ESSAY_CORPUS_PATH).read()
essay_corpus = util_functions.sub_chars(essay_corpus)
good_pos_ngrams = util_functions.regenerate_good_tokens(essay_corpus)
pickle.dump(good_pos_ngrams, open(base_path + 'good_pos_ngrams.p', 'wb'))
pickle.dump(good_pos_ngrams, open(NGRAM_PATH, 'wb'))
else:
#Hard coded list in case the needed files cannot be found
good_pos_ngrams=['NN PRP', 'NN PRP .', 'NN PRP . DT', 'PRP .', 'PRP . DT', 'PRP . DT NNP', '. DT',
......@@ -85,6 +97,9 @@ class FeatureExtractor(object):
def _get_grammar_errors(self,pos,text,tokens):
"""
Internal function to get the number of grammar errors in given text
pos - part of speech tagged text (list)
text - normal text (list)
tokens - list of lists of tokenized text
"""
word_counts = [max(len(t),1) for t in tokens]
good_pos_tags = []
......@@ -121,6 +136,7 @@ class FeatureExtractor(object):
Generates length based features from an essay set
Generally an internal function called by gen_feats
Returns an array of length features
e_set - EssaySet object
"""
text = e_set._text
lengths = [len(e) for e in text]
......@@ -144,6 +160,7 @@ class FeatureExtractor(object):
Generates bag of words features from an input essay set and trained FeatureExtractor
Generally called by gen_feats
Returns an array of features
e_set - EssaySet object
"""
if(hasattr(self, '_stem_dict')):
sfeats = self._stem_dict.transform(e_set._clean_stem_text)
......@@ -157,6 +174,7 @@ class FeatureExtractor(object):
"""
Generates bag of words, length, and prompt features from an essay set object
returns an array of features
e_set - EssaySet object
"""
bag_feats = self.gen_bag_feats(e_set)
length_feats = self.gen_length_feats(e_set)
......@@ -171,6 +189,7 @@ class FeatureExtractor(object):
Generates prompt based features from an essay set object and internal prompt variable.
Generally called internally by gen_feats
Returns an array of prompt features
e_set - EssaySet object
"""
prompt_toks = nltk.word_tokenize(e_set._prompt)
expand_syns = []
......@@ -206,6 +225,7 @@ class FeatureExtractor(object):
features - optionally, pass in a matrix of features extracted from e_set using FeatureExtractor
in order to get off topic feedback.
Returns a list of lists (one list per essay in e_set)
e_set - EssaySet object
"""
#Set ratio to modify thresholds for grammar/spelling errors
......@@ -220,9 +240,9 @@ class FeatureExtractor(object):
all_feedback=[]
for m in xrange(0,len(e_set._text)):
#Be very careful about changing these messages!
individual_feedback={'grammar' : "Grammar: Ok.", 'spelling' : "Spelling: Ok.",
'topicality' : "Topicality: Ok.", 'markup_text' : "",
'prompt_overlap' : "Prompt Overlap: Ok.",
individual_feedback={'grammar' : "Grammar: Ok.",
'spelling' : "Spelling: Ok.",
'markup_text' : "",
'grammar_per_char' : set_grammar_per_character[m],
'spelling_per_char' : set_spell_errors_per_character[m],
'too_similar_to_prompt' : False,
......
#Grader called by pyxserver_wsgi.py
#Loads a grader file, which is a dict containing the prompt of the question,
#a feature extractor object, and a trained model.
#Extracts features and runs trained model on the submission to produce a final score.
#Correctness determined by ratio of score to max possible score.
#Requires aspell to be installed and added to the path.
"""
Functions to score specified data using specified ML models
"""
import sys
import pickle
......@@ -12,9 +9,11 @@ import numpy
import logging
from statsd import statsd
#Append sys to base path to import the following modules
base_path = os.path.dirname(__file__)
sys.path.append(base_path)
#Depend on base path to be imported
from essay_set import EssaySet
import predictor_extractor
import predictor_set
......@@ -28,18 +27,31 @@ import math
log = logging.getLogger(__name__)
@statsd.timed('open_ended_assessment.machine_learning.grader.time')
def grade(grader_data,grader_config,submission):
def grade(grader_data,submission):
"""
Grades a specified submission using specified models
grader_data - A dictionary:
{
'model' : trained model,
'extractor' : trained feature extractor,
'prompt' : prompt for the question,
'algorithm' : algorithm for the question,
}
submission - The student submission (string)
"""
#Initialize result dictionary
results = {'errors': [],'tests': [],'score': 0, 'feedback' : "", 'success' : False, 'confidence' : 0}
has_error=False
#Try to find and load the model file
grader_set=EssaySet(type="test")
#Try to add essays to essay set object
#This is to preserve legacy functionality
if 'algorithm' not in grader_data:
grader_data['algorithm'] = util_functions.AlgorithmTypes.classification
try:
#Try to add essay to essay set object
grader_set.add_essay(str(submission),0)
grader_set.update_prompt(str(grader_data['prompt']))
except:
......@@ -57,17 +69,14 @@ def grade(grader_data,grader_config,submission):
#Try to determine confidence level
try:
min_score=min(numpy.asarray(grader_data['score']))
max_score=max(numpy.asarray(grader_data['score']))
raw_confidence=grader_data['model'].predict_proba(grader_feats)[0,(results['score']-min_score)]
#TODO: Normalize confidence somehow here
results['confidence']=raw_confidence
results['confidence'] = get_confidence_value(grader_data['algorithm'], grader_data['model'], grader_feats, results['score'], grader_data['score'])
except:
#If there is an error getting confidence, it is not a show-stopper, so just log
log.exception("Problem generating confidence value")
if not has_error:
#If the essay is just a copy of the prompt, return a 0 as the score
if(feedback['too_similar_to_prompt']):
results['score']=0
results['correct']=False
......@@ -75,24 +84,23 @@ def grade(grader_data,grader_config,submission):
results['success']=True
#Generate short form output--number of problem areas identified in feedback
problem_areas=0
for tag in feedback:
if tag in ['topicality', 'prompt-overlap', 'spelling', 'grammar']:
problem_areas+=len(feedback[tag])>5
#Add feedback to results
results['feedback']={
'topicality' : feedback['topicality'],
'prompt-overlap' : feedback['prompt_overlap'],
}
if results['score']/float(max_score)<.33:
results['feedback'].update(
{'spelling' : feedback['spelling'],
'grammar' : feedback['grammar'],
'markup-text' : feedback['markup_text'],
#Add feedback to results if available
results['feedback'] = {}
if 'topicality' in feedback and 'prompt_overlap' in feedback:
results['feedback'].update({
'topicality' : feedback['topicality'],
'prompt-overlap' : feedback['prompt_overlap'],
})
results['feedback'].update(
{
'spelling' : feedback['spelling'],
'grammar' : feedback['grammar'],
'markup-text' : feedback['markup_text'],
}
)
else:
#If error, success is False.
results['success']=False
......@@ -103,7 +111,17 @@ def grade(grader_data,grader_config,submission):
return results
def grade_generic(grader_data, grader_config, numeric_features, textual_features):
def grade_generic(grader_data, numeric_features, textual_features):
"""
Grades a set of numeric and textual features using a generic model
grader_data -- dictionary containing:
{
'algorithm' - Type of algorithm to use to score
}
numeric_features - list of numeric features to predict on
textual_features - list of textual feature to predict on
"""
results = {'errors': [],'tests': [],'score': 0, 'success' : False, 'confidence' : 0}
has_error=False
......@@ -129,16 +147,7 @@ def grade_generic(grader_data, grader_config, numeric_features, textual_features
#Try to determine confidence level
try:
min_score=min(numpy.asarray(grader_data['score']))
max_score=max(numpy.asarray(grader_data['score']))
if grader_data['algorithm'] == util_functions.AlgorithmTypes.classification:
raw_confidence=grader_data['model'].predict_proba(grader_feats)[0,(results['score']-min_score)]
#TODO: Normalize confidence somehow here
results['confidence']=raw_confidence
else:
raw_confidence = grader_data['model'].predict(grader_feats)[0]
confidence = max(raw_confidence - math.floor(raw_confidence), math.ceil(raw_confidence) - raw_confidence)
results['confidence'] = confidence
results['confidence'] = get_confidence_value(grader_data['algorithm'], grader_data['model'], grader_feats, results['score'])
except:
#If there is an error getting confidence, it is not a show-stopper, so just log
log.exception("Problem generating confidence value")
......@@ -151,3 +160,25 @@ def grade_generic(grader_data, grader_config, numeric_features, textual_features
results['success'] = True
return results
def get_confidence_value(algorithm,model,grader_feats,score, scores):
"""
Determines a confidence in a certain score, given proper input parameters
algorithm- from util_functions.AlgorithmTypes
model - a trained model
grader_feats - a row of features used by the model for classification/regression
score - The score assigned to the submission by a prior model
"""
min_score=min(numpy.asarray(scores))
max_score=max(numpy.asarray(scores))
if algorithm == util_functions.AlgorithmTypes.classification:
#If classification, predict with probability, which gives you a matrix of confidences per score point
raw_confidence=model.predict_proba(grader_feats)[0,(score-min_score)]
#TODO: Normalize confidence somehow here
confidence=raw_confidence
else:
raw_confidence = model.predict(grader_feats)[0]
confidence = max(raw_confidence - math.floor(raw_confidence), math.ceil(raw_confidence) - raw_confidence)
return confidence
python-pip
python-scipy
python-mysqldb
ipython
nginx
git
redis-server
libmysqlclient-dev
gfortran
libblas3gf
libblas-dev
liblapack3gf
liblapack-dev
libatlas-base-dev
libxml2-dev
libxslt1-dev
libreadline6
libreadline6-dev
build-essential
curl
aspell
python
\ No newline at end of file
......@@ -87,10 +87,16 @@ def create_essay_set(text, score, prompt_string, generate_additional=True):
return x
def get_cv_error(clf,feats,scores):
"""
Gets cross validated error for a given classifier, set of features, and scores
clf - classifier
feats - features to feed into the classified and cross validate over
scores - scores associated with the features -- feature row 1 associates with score 1, etc.
"""
results={'success' : False, 'kappa' : 0, 'mae' : 0}
try:
cv_preds=util_functions.gen_cv_preds(clf,feats,scores)
err=numpy.mean(numpy.abs(cv_preds-scores))
err=numpy.mean(numpy.abs(numpy.array(cv_preds)-scores))
kappa=util_functions.quadratic_weighted_kappa(list(cv_preds),scores)
results['mae']=err
results['kappa']=kappa
......@@ -103,15 +109,11 @@ def get_cv_error(clf,feats,scores):
return results
def extract_features_and_generate_model_predictors(predictor_set, type=util_functions.AlgorithmTypes.regression):
if(algorithm not in [util_functions.AlgorithmTypes.regression, util_functions.AlgorithmTypes.classification]):
algorithm = util_functions.AlgorithmTypes.regression
f = predictor_extractor.PredictorExtractor()
f.initialize_dictionaries(predictor_set)
train_feats = f.gen_feats(predictor_set)
def get_algorithms(type):
"""
Gets two classifiers for each type of algorithm, and returns them. First for predicting, second for cv error.
type - one of util_functions.AlgorithmTypes
"""
if type == util_functions.AlgorithmTypes.classification:
clf = sklearn.ensemble.GradientBoostingClassifier(n_estimators=100, learn_rate=.05,
max_depth=4, random_state=1,min_samples_leaf=3)
......@@ -122,7 +124,24 @@ def extract_features_and_generate_model_predictors(predictor_set, type=util_func
max_depth=4, random_state=1,min_samples_leaf=3)
clf2=sklearn.ensemble.GradientBoostingRegressor(n_estimators=100, learn_rate=.05,
max_depth=4, random_state=1,min_samples_leaf=3)
return clf, clf2
def extract_features_and_generate_model_predictors(predictor_set, type=util_functions.AlgorithmTypes.regression):
"""
Extracts features and generates predictors based on a given predictor set
predictor_set - a PredictorSet object that has been initialized with data
type - one of util_functions.AlgorithmType
"""
if(algorithm not in [util_functions.AlgorithmTypes.regression, util_functions.AlgorithmTypes.classification]):
algorithm = util_functions.AlgorithmTypes.regression
f = predictor_extractor.PredictorExtractor()
f.initialize_dictionaries(predictor_set)
train_feats = f.gen_feats(predictor_set)
clf,clf2 = get_algorithms(type)
cv_error_results=get_cv_error(clf2,train_feats,predictor_set._target)
try:
......@@ -137,7 +156,7 @@ def extract_features_and_generate_model_predictors(predictor_set, type=util_func
return f, clf, cv_error_results
def extract_features_and_generate_model(essays,additional_array=None):
def extract_features_and_generate_model(essays, type=util_functions.AlgorithmTypes.regression):
"""
Feed in an essay set to get feature vector and classifier
essays must be an essay set object
......@@ -149,20 +168,18 @@ def extract_features_and_generate_model(essays,additional_array=None):
f.initialize_dictionaries(essays)
train_feats = f.gen_feats(essays)
if(additional_array!=None and type(additional_array)==type(numpy.array([1]))):
if(additional_array.shape[0]==train_feats.shape[0]):
train_feats=numpy.concatenate((train_feats,additional_array),axis=1)
clf = sklearn.ensemble.GradientBoostingClassifier(n_estimators=100, learn_rate=.05,
max_depth=4, random_state=1,min_samples_leaf=3)
set_score = numpy.asarray(essays._score, dtype=numpy.int)
if len(util_functions.f7(list(set_score)))>5:
type = util_functions.AlgorithmTypes.regression
else:
type = util_functions.AlgorithmTypes.classification
clf2=sklearn.ensemble.GradientBoostingClassifier(n_estimators=100, learn_rate=.05,
max_depth=4, random_state=1,min_samples_leaf=3)
clf,clf2 = get_algorithms(type)
cv_error_results=get_cv_error(clf2,train_feats,essays._score)
try:
set_score = numpy.asarray(essays._score, dtype=numpy.int)
clf.fit(train_feats, set_score)
except ValueError:
log.exception("Not enough classes (0,1,etc) in sample.")
......
"""
Extracts features for an arbitrary set of textual and numeric inputs
"""
import numpy
import re
import nltk
......@@ -12,6 +16,7 @@ import logging
import math
from feature_extractor import FeatureExtractor
#Append to path and then import things that depend on path
base_path = os.path.dirname(__file__)
sys.path.append(base_path)
from essay_set import EssaySet
......@@ -28,6 +33,10 @@ class PredictorExtractor(object):
self._initialized = False
def initialize_dictionaries(self, p_set):
"""
Initialize dictionaries with the textual inputs in the PredictorSet object
p_set - PredictorSet object that has had data fed in
"""
success = False
if not (hasattr(p_set, '_type')):
error_message = "needs to be an essay set of the train type."
......@@ -43,6 +52,7 @@ class PredictorExtractor(object):
if div_length==0:
div_length=1
#Ensures that even with a large amount of input textual features, training time stays reasonable
max_feats2 = int(math.floor(200/div_length))
for i in xrange(0,len(p_set._essay_sets)):
self._extractors.append(FeatureExtractor())
......@@ -52,6 +62,10 @@ class PredictorExtractor(object):
return success
def gen_feats(self, p_set):
"""
Generates features based on an iput p_set
p_set - PredictorSet
"""
if self._initialized!=True:
error_message = "Dictionaries have not been initialized."
log.exception(error_message)
......
#!/usr/bin/python
#------------------------------------------------------------
# Run me with (may need su privilege for logging):
# gunicorn -w 4 -b 127.0.0.1:3031 pyxserver_wsgi:application
#------------------------------------------------------------
import cgi # for the escape() function
import json
import logging
import os
import os.path
import sys
from time import localtime, strftime
script_dir = os.path.dirname(__file__)
sys.path.append(script_dir)
import settings # Not django, but do something similar
# make sure we can find the grader files
sys.path.append(settings.GRADER_ROOT)
import grade
results_template = """
<div class="test">
<header>Test results</header>
<section>
<div class="shortform">
{status}
</div>
<div class="longform">
{errors}
{results}
</div>
</section>
</div>
"""
results_correct_template = """
<div class="result-output result-correct">
<h4>{short-description}</h4>
<p>{long-description}</p>
<dl>
<dt>Output:</dt>
<dd class="result-actual-output">
<pre>{actual-output}</pre>
</dd>
</dl>
</div>
"""
results_incorrect_template = """
<div class="result-output result-incorrect">
<h4>{short-description}</h4>
<p>{long-description}</p>
<dl>
<dt>Your output:</dt>
<dd class="result-actual-output"><pre>{actual-output}</pre></dd>
<dt>Correct output:</dt>
<dd><pre>{expected-output}</pre></dd>
</dl>
</div>
"""
def format_errors(errors):
esc = cgi.escape
error_string = ''
error_list = [esc(e) for e in errors or []]
if error_list:
items = '\n'.join(['<li><pre>{0}</pre></li>\n'.format(e) for e in error_list])
error_string = '<ul>\n{0}</ul>\n'.format(items)
error_string = '<div class="result-errors">{0}</div>'.format(error_string)
return error_string
def to_dict(result):
# long description may or may not be provided. If not, don't display it.
# TODO: replace with mako template
esc = cgi.escape
if result[1]:
long_desc = '<p>{0}</p>'.format(esc(result[1]))
else:
long_desc = ''
return {'short-description': esc(result[0]),
'long-description': long_desc,
'correct': result[2], # Boolean; don't escape.
'expected-output': esc(result[3]),
'actual-output': esc(result[4])
}
def render_results(results):
output = []
test_results = [to_dict(r) for r in results['tests']]
for result in test_results:
if result['correct']:
template = results_correct_template
else:
template = results_incorrect_template
output += template.format(**result)
errors = format_errors(results['errors'])
status = 'INCORRECT'
if errors:
status = 'ERROR'
elif results['correct']:
status = 'CORRECT'
return results_template.format(status=status,
errors=errors,
results=''.join(output))
def do_GET(data):
return "Hey, the time is %s" % strftime("%a, %d %b %Y %H:%M:%S", localtime())
def do_POST(data):
# This server expects jobs to be pushed to it from the queue
xpackage = json.loads(data)
body = xpackage['xqueue_body']
# Delivery from the lms
body = json.loads(body)
student_response = body['student_response']
payload = body['grader_payload']
try:
grader_config = json.loads(payload)
except ValueError as err:
# If parsing json fails, erroring is fine--something is wrong in the content.
# However, for debugging, still want to see what the problem is
raise
relative_grader_path = grader_config['grader']
grader_path = os.path.join(settings.GRADER_ROOT, relative_grader_path)
results = grade.grade(grader_path, student_response)
# Make valid JSON message
reply = { 'correct': results['correct'],
'score': results['score'],
'msg': render_results(results) }
return json.dumps(reply)
# Entry point
def application(env, start_response):
# Handle request
method = env['REQUEST_METHOD']
data = env['wsgi.input'].read()
def post_wrapper(data):
try:
return do_POST(data)
except:
return None
handlers = {'GET': do_GET,
'POST': post_wrapper,
}
if method in handlers.keys():
reply = handlers[method](data)
if reply is not None:
start_response('200 OK', [('Content-Type', 'text/html')])
return reply
# If we fell through to here, complain.
start_response('404 Not Found', [('Content-Type', 'text/plain')])
return ''
# Not django (for now), but use the same settings format anyway
import json
import os
from path import path
import sys
ROOT_PATH = path(__file__).dirname()
REPO_PATH = ROOT_PATH
ENV_ROOT = REPO_PATH.dirname()
# DEFAULTS
DEBUG = False
# Must end in '/'
RUN_URL = 'http://127.0.0.1:3031/' # Victor's VM ...
RUN_URL = 'http://sandbox-runserver-001.m.edx.org:8080/'
RUN_URL = 'http://sandbox-runserver.elb.edx.org:80/'
GRADER_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__),'..'))
# AWS
if os.path.isfile(ENV_ROOT / "env.json"):
print "Opening env.json file"
with open(ENV_ROOT / "env.json") as env_file:
ENV_TOKENS = json.load(env_file)
RUN_URL = ENV_TOKENS['RUN_URL']
LOG_DIR = ENV_TOKENS['LOG_DIR']
# Should be absolute path to 6.00 grader dir.
# NOTE: This means we only get one version of 6.00 graders available--has to
# be the same for internal and external class. Not critical -- can always
# use different grader file if want different problems.
GRADER_ROOT = ENV_TOKENS.get('GRADER_ROOT')
this is an incorrect response
\ No newline at end of file
,vik,vikp,02.11.2012 17:19,file:///home/vik/.config/libreoffice/3;
\ No newline at end of file
This experement didn't have a controle and the grupe didn't do multiple triles. You would also may need to know what tempriture the rome is.
{"grader":"tests/models/essay_set_1.p"}
In order for I for replicate this expirement I woukd need to know what are the reaserching with this expirement what kind of result are being booked at and the mass of each sample at the end of expirment theie results.
This source diff could not be displayed because it is too large. You can view the blob instead.
<b><fg>In order to replicate this experiment, I would need to know additional information such as the four different samples that they used (because I could have choosen metal, carbboard&&&&&and many other sample materials that they&;;;& didn't use and would get different results. Also I would also<>>> need to know the amount of vinegar to pour because this can caute a major change. Lastly, they might want to tell//////where to sit the samples while they dry for 30 minutes because if they are sitting in room temp. or by a light source makes a difference too.<b><b>
{"grader":"tests/models/essay_set_1.p"}
In order to conduct the experiment, the students would need to know the mass of the marble, the height of the drop, and the air temperature.
This source diff could not be displayed because it is too large. You can view the blob instead.
"A group of students wrote the following procedure for their investigation. Procedure: 1. Determine the mass of four different samples. 2. Pour vinegar in each of four separate, but identical, containers. 3. Place a sample of one material into one container and label. Repeat with remaining samples, placing a single sample into a single container. 4. After 24 hours, remove the samples from the containers and rinse each sample with distilled water. 5. Allow the samples to sit and dry for 30 minutes. 6. Determine the mass of each sample. The students’ data are recorded in the table below. Sample Starting Mass (g) Ending Mass (g) Difference in Mass (g) Marble 9.8 9.4 –0.4 Limestone 10.4 9.1 –1.3 Wood 11.2 11.2 0.0 Plastic 7.2 7.1 –0.1"
"score" "answer"
1 ""
1 ""
2 "The unfilled pband of Mg can be used exactly the same way as the unfilled sband of Na is used to be filled with excited electrons."
2 "The unfilled pband of Mg can be used exactly the same way as the unfilled sband of Na is used to be filled with excited electrons."
0 "Magnesium is a metal inspite of its fully filled sband, because of the availability of the empty Porbitals that make up the Pband which can grow close enough to overlap with some of the sorbitals in the sband and in so doing gives rise to hybridisation. Mixing of bands of the s and p orbitals is responsible for the metal properties exhibited by Mg."
3 "Magnesium is a metal inspite of its fully filled sband, because of the availability of the empty Porbitals that make up the Pband which can grow close enough to overlap with some of the sorbitals in the sband and in so doing gives rise to hybridisation. Mixing of bands of the s and p orbitals is responsible for the metal properties exhibited by Mg.nnNa has empty sorbitals in the half filled sband that means availability states to transit or move for electronsn"
3 "the overlapping pband and sband of Mg metal ensure it has unoccupied energy levels it only takes up 14 of the valence orbitals "
3 "the overlapping pband and sband of Mg metal ensure it has unoccupied energy levels it only takes up 14 of the valence orbitals nSodium has only 1 valence electron in the sorbital and so, it has halffilled sband"
3 " Metals tend to be good electronic conductors, meaning that they have a large number of electrons which are able to access empty mobile energy states within the material.n Sodium has a halffilled sband, so there are a number of empty states immediately above the highest occupied energy levels within the band.n Magnesium has a full sband, but the the sband and pband overlap in magnesium. Thus are still a large number of available energy states immediately above the sband highest occupied energy level."
2 "Sodium behaves as a metal because the electrons in the sband are able to accept energy from an electric field so can move into the unfilled sbands. In the case of Magnesium even though the s band is filled the electrons can still accept energy from an electric field but instead of moving to an unfilled sband it moves to an unfilled pband still enabling it to move around the structure. This gives Magnesium its metallic properties."
3 "All metals tend to conduct electricity as the electrons in the structure can change energy states. Sodium acts as a metal as the sband is only half filled so the electrons can change energy states into the unfilled bands. Magnesium acts as a metal because even though the sband is full the s and p bands overlap so the electrons in the sband can change energy states into the p band allowing them the conduct electricity "
1 "the energy difference the filled s band and the empty band is negligible.nhence a small amount of energy can excite electrons to the empty band.nhence they conduct electricity and act as metalsn"
3 "Hi"
3 "Metals are good electronic conductors as they have a large number of electrons which are able to access empty mobile energy states within the material.nSodium has a halffilled sband, so there are a number of empty states immediately above the highest occupied energy levels within the band.nMagnesium has a full sband, but the the sband and pband overlap in magnesium. Thus are still a large number of available energy states immediately above the sband highest occupied energy level."
2 "The p orbitals of Mg are very close in energy levels to the s orbitals so the electrons can jump from the s to p orbitals in much the same way that tha Na electrons can move to the upper unfilled s orbitals."
2 "Because the highest filled sband molecular orbital in Mg metal is situated near the empty pband molecular orbital, so electrons need really a little amount of energy to go from one molecular orbital to another. Just like in Na metal."
3 "Both elements have filled unfilled orbitals.nIn Na, electrons can be excited from the highest filled bonding s orbitals Valence bands into the lowest unfilled s orbitals antibonding u2013 Conduction bands.nIn Mg, the 3s 3p valence orbitals interact much more strongly with each other than with the filled core shells the Valence bands have a large band width u2013 so large, in fact, that the band width is wider than the energy gap the bands overlap. Thus it requires only a small amount of energy to excite an electron from a filled s orbital s band into an unfilled p orbital p band. This electron can then migrate through the crystal in response to an applied electric field thus conduct electricity.n"
3 "Metallic behavior can arise either from the presence of a single partially filled band or from two overlapping bands one full and one empty."
2 ""
1 "The electrons at the top of the filled sband in Mg can move into the empty pband."
3 "First, we will define a metal as being a good conductor of electricity, that is, a material where the electric charges move through easily. We know that the mobile charges are the electrons.nIn order for a solid to be a good conductor, the electrons need to dispose of empty extended molecular orbitals to which they can access with the small amounts of energy that are provided by an external applied electric field the electrons move then through these extended orbitals.nIn the case of Na atomic structure Ne 3s1, the system presents an sband, that is, a u201ccontinuousu201d bundle of extended molecular orbitals, which in this case is half filled. In this way, when an electric field is applied to the system, the electrons placed in the upper occupied band levels of the sband take the transferred energy and move to band levels with slightly higher energy, and then they move through the extended molecular levels linked with these band levels.nIn the case of Mg Ne 3s2, the sband is completely filled, so there is no possibility of transitions inside this band. However, the p atomic orbitals of Mg form a pband which overlaps with the sband, in such a way that the electrons in the upper part of the sband can jump to the pband with the amounts of energy provided by the applied electric field, and move through the pband extended molecular orbitals."
1 "The upper sband orbitals of magnesium have pband orbitals close to them. So the electrons can move to the porbitals accepting energy of the electric field."
2 "The electronic configuration of magnesium is 1s2 2s2 2p6 3s2. In this structure it appears that all the energy bands, 1s, 2s, 2p and 3s are completely filled, thus not satisfying the metallic feature according to band theory, however the magnesium is a metal. This is due to the fact that the 3s and 3p bands overlap in energy and consequently some electrons enter from 3s to 3p band before all the allowed states in 3s band are occupied. Therefore the current flow is possible and therefore the magnesium has a metallic behaviour."
2 "The electronic configuration of magnesium is 1s2 2s2 2p6 3s2. In this structure it appears that all the energy bands, 1s, 2s, 2p and 3s are completely filled, thus not satisfying the metallic feature according to band theory, however the magnesium is a metal. This is due to the fact that the 3s and 3p bands overlap in energy and consequently some electrons enter from 3s to 3p band before all the allowed states in 3s band are occupied. Therefore the current flow is possible and therefore the magnesium has a metallic behaviour."
3 "p orbitals overlap with a orbitals"
2 "THEY HAVE EMPTY SHELLS AT THE TOP FOR MOVING ELECTRONS "
2 "The electronic configuration of sodium is 1s2 2s2 2p6 3s1 and the electronic configuration of magnesium is 1s2 2s2 2p6 3s2. All the energy bands are completely filled. The magnesium has a metallic behaviour because this is due to the fact that the 3s and 3p bands overlap in energy and consequently some electrons enter from 3s to 3p band before all the allowed states in 3s band are occupied. "
2 "Because the electrons can be affected by an electric field and go to the higher level "
1 "Electrons at the top of the sband of Mg, when influenced by the electric field, have enough energy to jump to the bottom of the pband, thus displaying metallic properties."
1 "At Sodium has at last level of 1 s electron, and it is not u0440 electron. At Magnesium has at last level of 2 s electron, and it is not u0440 electron, but can pass 1 electron with s on u0440"
3 ""
3 "In both cases, there are electrons whose energy levels are located such that there is another energy level only a little bit above them, thus allowing them to absorb the tiny amount of energy imparted by an electric field in the presence of collisions."
2 "As these two bands overlape they become free electrons and act as conductors.rising levels of these electrons acquire an additional energy which enables them to move higher to unaccupied levels,transforming into kentic energy.thus behaving as metals."
3 "The sband is complete in the Mg because the Mg has two electrons of valence and the sband of Na only has one electron.nnThe electrons in the Na, can move in the sband but the electrons in the Mg only can move to pband."
2 "Na is a metal based on the previous lecture. Mg is a metal because the p and s bands overlap so electrons from the full sband can move into the pband with no energy barrier. Once in the pband, the Mg electrons are free to conduct by gaining minute amounts of energy from the electric field."
2 "The sband of Magnesium is filled because it has double electrons than Na.nMagnesium is metal because the electrons closed to the filled boundary can move to the pband."
2 "This is because the energy levels between the molecular orbital s band and the p band are very close to each other. And therefore any disturbance caused by an electric field is felt by the electrons present in these bands, who respond to this stimulus moving between spaces available."
2 ""
2 "Sodium is a simple metal we have a halffilled sband.nMagnesium The sband and the pband are overlapped. Althought the sband is filled, we have empty orbitals in the pband.n"
1 "Because there is no gap between the s and p bands of Mg"
3 "Sodium is behaving like a metal because it have a half band occupied, and its possible that some electron can jump to unoccupied orbitals easily.nnMagnesium is behaving like a metal because it have two band very closed, and its possible that some electron of sband can jump to pband easily.nnIf the gap between bands is greatest, the element is behaving like nometal, because the promotion of electrons would be difficult"
0 ""
1 "Magnesium behaves as a metal even though its sband is filled because the 3s and 3p bands overlap. Which allows some electrons to enter the 3p band before all the states in the 3s band have been filled. Making both bands partially filled and giving electrons access to empty states close to the top of the nearly filled boundary."
2 "An atom of sodium has electronic configuration 1s2 2s2 2p6 3s1 and therefore, the energy levels containing electrons are slevel, 2slevel, 2plevel and 3slevels. of these 1s, 2s, 2p levels are completely filled, but the 3s level is only half filled. accordingly in a solid sodium piece containing Natoms, there would be a 1sband, a 2sband, a 2pband and a 3sband of energy containing 2N, 2N, 6N, 2N, electronic states.of these 1s, 2s and 2pbands are completely filled but the 3sband is only halffilled.nNow if an electric field is applied across the piece of solid sodium, then the electrons in the valence band easily acquire additional energy to move to the higher unoccupied levels within the same band without acrossing any energy gap. the additional energy is in the form of kinetic energy and the moving electron consititutes electric current.nFor the matel magnesium whose electronic configuration 1s2 2s2 2p6 3s2. in this structure it appears that all the energy bands are completely filled, thus not satisfy ing the metalic feature according to band theory, but magnesium is a metal. this is due to the fact that the 3s and the 3p bands overlap is energy as shown in the figure above, and consequently some electrons enter from 3s to 3pband before all the allowed states in 3sband are occupied. this makes the 3sband partially filled and 3pband partially occupied. therefore the current flow is possible. this is explaine the metallic behaviour of magnesium."
2 "An atom of sodium has electronic configuration 1s2 2s2 2p6 3s1 and therefore, the energy levels containing electrons are slevel, 2slevel, 2plevel and 3slevels. of these 1s, 2s, 2p levels are completely filled, but the 3s level is only half filled. accordingly in a solid sodium piece containing Natoms, there would be a 1sband, a 2sband, a 2pband and a 3sband of energy containing 2N, 2N, 6N, 2N, electronic states.of these 1s, 2s and 2pbands are completely filled but the 3sband is only halffilled.nNow if an electric field is applied across the piece of solid sodium, then the electrons in the valence band easily acquire additional energy to move to the higher unoccupied levels within the same band without acrossing any energy gap. the additional energy is in the form of kinetic energy and the moving electron consititutes electric current.nFor the matel magnesium whose electronic configuration 1s2 2s2 2p6 3s2. in this structure it appears that all the energy bands are completely filled, thus not satisfy ing the metalic feature according to band theory, but magnesium is a metal. this is due to the fact that the 3s and the 3p bands overlap is energy as shown in the figure above, and consequently some electrons enter from 3s to 3pband before all the allowed states in 3sband are occupied. this makes the 3sband partially filled and 3pband partially occupied. therefore the current flow is possible. this is explaine the metallic behaviour of magnesium."
2 "An atom of sodium has electronic configuration 1s2 2s2 2p6 3s1 and therefore, the energy levels containing electrons are slevel, 2slevel, 2plevel and 3slevels. of these 1s, 2s, 2p levels are completely filled, but the 3s level is only half filled. accordingly in a solid sodium piece containing Natoms, there would be a 1sband, a 2sband, a 2pband and a 3sband of energy containing 2N, 2N, 6N, 2N, electronic states.of these 1s, 2s and 2pbands are completely filled but the 3sband is only halffilled.nNow if an electric field is applied across the piece of solid sodium, then the electrons in the valence band easily acquire additional energy to move to the higher unoccupied levels within the same band without acrossing any energy gap. the additional energy is in the form of kinetic energy and the moving electron consititutes electric current.nFor the matel magnesium whose electronic configuration 1s2 2s2 2p6 3s2. in this structure it appears that all the energy bands are completely filled, thus not satisfy ing the metalic feature according to band theory, but magnesium is a metal. this is due to the fact that the 3s and the 3p bands overlap is energy as shown in the figure above, and consequently some electrons enter from 3s to 3pband before all the allowed states in 3sband are occupied. this makes the 3sband partially filled and 3pband partially occupied. therefore the current flow is possible. this is explaine the metallic behaviour of magnesium."
3 ""
3 "In all metals, a large number of electrons are free to move about the crystal at room temperature. Sodium is a metal because the valence band half of the sorbitals is filled, and it only takes an incremental amount of energy to excite an electron from the valence band the conduction band. Magnesium is a metal because the sorbitals are fully filled, but they overlap with the porbitals, so it is easy to move electrons from the valence band to the conduction band."
2 "The sband of the sodium metal is only halffilled, therefore the electrons may move within the band to the higher energy levels.nnDue to the fact that the sband and the pband of the magnesium metal overlap, there is no significant difference in energy between these two bands, and the electrons may move from the sband to the higher energy levels of the pband."
0 "It is because both have one electron in the outer band. whatever. huh"
3 "High energy sband electrons in Mg metal may be excited to the pband orbitals, hence meaning they are able to accept the energy imparted by the electric field and move hence conducting a current."
2 "While the 3s band could be filled, the upper range of energies in this band overlap with the lower range of energies in the 3p bands. It requires little energy for electrons to move into vacant conduction levels."
3 "magnesium Mg has an electron configuration 1s2 2s2 2p6 3s2, it has a filled 3s shelln therefore the filled 3s shell on its own would not allow for electrons to gain energy, if the 3pnband was separated by a gap from the 3s bandn in Mg however, the 3s and 3p bands overlap in energy the 3p band can accommodate 22l1 6 electrons per atom, . jointly the 3s and the 3pnnorbitals form a band that can accommodate 8 N electronsn thus the conduction band is only 25 filled rendering Mg a good conductor and magnesium behave as metalnnso in sodium a good metal conductor there are 22l1 with l 0navailable electron states per atom in the 3s shell only one of which isnfilled with the single valence electronn as a result the 3s shell of sodium is only half filled n thus the electrons are free to change their energies within the 3snbandn this allows electrons to pick up a kinetic energy from an appliednelectric field leading to a electron drift velocity generating currentnthat makes Na a good metallic conductor"
3 "Magnesium conducts because of the overlapping of s and p energy bands. So even thought 3sband is completely filled, 3pband become aviable. Given that i havent any energy gap between bonding and conducting band,because now electrons can fill free 3pband ,Magnesium exhibits conduction."
3 "Sodium can conduct due to halffilles 3sband,so providing an external source of energy such as heat or elettric fields,electrons are free to occupy higher energy sband level.nMagnesium conducts because of the overlapping of s and p energy bands. So even thought 3sband is completely filled, 3pband become aviable. Given that i havent any energy gap between bonding and conducting band,because now electrons can fill free 3pband which is just a little over the highest sband energy,Magnesium exhibits conduction."
1 "There is a partial overlap of the 3s and 3p bands in Mg, therefore if there is enough energy the electron can transfer from valence band to the empty 3 p conduction band."
1 "Electronic configuration of Mg 3s2e 3p0e. 3s and 3p orbitals have very close energy, so electrons can occupy free 3porbitals, move there freely."
2 "Because the metallic behavior can arise from two overlapping bands one full and one empty, that is the case for Magnesium."
3 "Na metal sband not fully completed, an e can go upnMg metal sband and pband overlap an e can go upn"
1 "Magnesium is showing metal properties because it has pband which is overlaping with filled sband and thanks to this it is accesible to the highest energetic electrons from this sband"
3 "because p and s waves are superimposed"
1 "The filled sband is overlaped by empty pband. The electrons from the sband have access to empty state very close to the top of the sband. "
0 ""
1 "The pband of Mg overlap the s band, creating a way for the electrons."
3 " Metals tend to be good electronic conductors, meaning that they have a large number of electrons which are able to access empty mobile energy states within the material.n Sodium has a halffilled sband, so there are a number of empty states immediately above the highest occupied energy levels within the band.n Magnesium has a full sband, but the the sband and pband overlap in magnesium. Thus are still a large number of available energy states immediately above the sband highest occupied energy level."
1 "In magnesium, the s and p orbitals are very close in energy so there is an overlap of orbitals and the electrons can easily move from the filled sband to the empty pband"
3 "For mg, the sband electrons bordering the pband behave similar to the electrons in the middle of the halffilled sband."
0 ""
0 ""
3 "The difference in energy between s antibonding orbitals and p bonding orbitals is small they are overlaped, so electrons can go from s band to p band when are influenced by a electric field."
0 "The metallic bond is independent of the valence electrons."
0 ""
3 "Metals are a good electronic conductors.nBoth of metals have energy levels available"
3 "Orbitale Mg mogu0105 przyju0105u0107 8 elektronu00f3w zaju0119te su0105 tylko przez 2. Tym samym pozostaje au017c 75 wolnego miejsca na wzbudzanie elektronu00f3w. Orbitale Na 4 elektrony su0105 zaju0119te przez 2. Maju0105 50 miejsca na wzbudzone elektrony."
1 "The upper s band of Mg overlaps its pband thus providing a partiallyfilled joint band that allows electron movement. "
3 "In sodium, the valence and conduction bands are very close in energy so that even the small amount of energy an electron will receive is enough to excite the electrons to the conduction band.nIn magnesium, the sband is filled. However, the empty pband orbitals are now available for the electrons to be excited into some, in fact, are lower than the maximum energy level of the filled sband."
3 "The magnesium behaves as a metal because it has an open pband overlapping with the filled sband. Therefore the electrons that are near the border between the two bands can absorb energy and be influenced by an electric field. This mimics the half filled sband present in Sodium metal."
3 "They both behave as metals because they are metals. nnAlthough the outer 3s energy band in magnesium is filled, these metalnhas good electrical conductivity because their 3s bands overlap their 3p bands. In the case of magnesium, the empty 3p band combines with the 3s band to form a partially filled 3sp band.nnSodium atoms form an extended array in which the valence electron can be delocalized generally across the array. The ionization energy is sufficiently low to allow this. The underlying reason is that its electrons are delocalized , that is to say they are present more as a cloud than as in association with specific atoms.nnA metal is defined as an element that readily loses electrons to form positive ions cations and forms metallic bonds with other metal atoms. Metals form ionic bonds with nonmetals.nn"
1 "Magnesium has an unfilled p band, in which electrons may get excited and jump to. This frees up the s band a bit too."
3 "Metals have lots of empty energy levels hence being a good conductor.nnMagnesium has s and p overlap a higher energy state is right above the s for electrons to jump to.nnSodium is half filled s, so there is an empty higher energy state available immediately above."
3 "Both have available low lying available energy levels near their highest occupied molecular orbital. In the case of sodium, those available levels are part of the same band formed from the superposition of s orbitals, while in the case of magnesium, the low lying energy level is part of a pand formed from p orbitals."
2 "In Mg, the empty p band overlaps in energy with the full s band, allowing mobility of electrons in the same way that a partially full band would."
2 "Bottom of pbang in Mg is close enough in energy to the top of the sband for the electrons to jump there. "
3 "Na has a halffull sband, so there are a lot of electrons to move and an available energy state for them to move to.nnThe sband of Mg is full, but the bottom of pband is close enough in energy to the top of the sband for the electrons to jump there. Again, there are plenty of electrons available for this jump. "
2 "Because they have the half band full nnTheir orbital mixes "
3 "Sodium behaves as a metal as it has a half filled sband and the electrons on the highest level of the filled states can accept the energy and move into higher states to exhibit metallic properties.nIn case of magnesium, though the sband is completely filled, it overlaps with the pband of the crystal. As a result of which the electrons on the outer level can accept the energy to move into the empty pband and hence behave as a metal."
1 ""
3 "Conduction in overlapping pband."
3 "Engery of lower pband orbitals are very similar and even lower than the highest sband orbitals. This allows very the electrons to absorb very small amounts of energy as then get occupy orbitals with slightly higher energy."
1 "Even though the 3s orbitals of Mg is filled which can occupy the sband where as empty 3p orbitals available for conduction. "
2 "both the Na and the Mg have a half filled band so electrons can only get a higher energy at the boundary level between the filled part of the band and the unfilled part of the other band"
2 "Metals have partially filled bands of molecular orbitals that allow electrons to absorb very small amounts of energy relative to non metals. e.g. electrons can travel through metal easily because it can absorb very low amounts of energy in an electric field by being excited to a higher molecular orbital. nNa has a half filled sband made up of 3s orbitals and it takes very small amounts of energy to excite the electron to the next molecular orbital in the band.nMg has enough valence electrons to fill up the entire sband but because the s and p bands overlap there is still a very small energy gap between molecular orbitals and the Mg crystal still exhibits metallic behaviour."
3 "In Mg, some electrons enter from 3s to 3p band before all the allowed states in 3s band are occupied. this makes the 3s band partially filled and 3p band partially occupied. therefore the current flow is possible."
3 "The bands derived from the 3s and 3p atomic orbitals are wider than the energy gap between then resulting in overlapping bands. This causes a combined band from the overlap of the 3s and the 3p orbitals with rooms for 8 electrons. This means the combined band of Mg is only partially filled which is crucial for the metallic behavious because there are unoccupied energy levels at an infinitesimally small energy above the highest occupied level."
1 "Because in both cases, there are unoccupied orbitals that are close in energy to filled orbitals. Electrons in these nearby filled orbitals can accept small amounts of energy and move into these unoccupied orbitals.nnIt is the ability of electrons to accept small amounts of energy that defines metallic behaviour"
1 "The molecular orbitals relating to the 4s and 3p subshells overlap as there is a relatively small energy difference between these levels when viewed as atomic orbitals. This overlap in energy levels means the two subshells merge to form a single band and this allows spare energy levels for the electrons to move into."
3 "We saw that the half empty sband gives the higher energy electrons opportunity to be excited and form a current. This principle explains the metallic characteristics of Na. For Mg, the sband is filled, but the empty pband, which overlaps the top of the sband in terms of energy level, functions as the next energy level to be excited to. From this theory, we can further assume that the reason elements such as P are non metals, is that their pband and sband differs greatly in energy."
2 "in soduim, half of the sband is filled and as we can see from the picture, we need a small amount of energy the make the valence electrons jump from the bonding band to the antibonding band.nIn magnesuim, even if the sband is filled, the pband is overlapped with the sband, so we only need a small amount of energy the make the valence electrons jump from the s band to the p band."
2 "If the pband energies are close to the sband energies, or even overlapping as the diagram suggests, the high energy electrons in the sband can easily move to an unoccupied pband."
2 "The metallic properties of sodium are obvious, due to the half filled sband, which provides the amount of electrons near the edge of filling, occupying the energy states which enable the electrons to accept the energy from the field and move to a higher energy state in the sband.nnLooking at the band diagram of magnesium we can see that even though the sband is completely filled, the bands have a small overlap. Thus it gives the ability for the highenergysband electrons to be affected by the electric field the ability to change their energy, jumping to the empty pband."
3 "They are metals because electrons can go to an empty band with a really little jump in energy.nnNa is a metal because the s band in halffilled, so electrons can move on the bandnnMg is a metal because even having a full sband, the pband overlaps it, so electrons can go to the pband as if it was a continuous halffilled band"
3 "band theory can easily explain the electrical conductivity of the metal as evidenced by the corresponding example sodium, sodium in the inner bands are completely filled, while the bands originated from the atomic orbitals of the valence shell 3s and 3p bands, is half full 3s, 3p empty, being 3s the valence band and the next higher conduction band. magnesium has completely filled valence band you would expect in principle that magnesium ho not have driver for free energy levels in the valence band. but the fact that for the equilibrium internuclear distance of the valence band overlaps the conduction band levels makes this easily accessible to the valence electrons, thus favoring metallic conduction."
1 " Even if the sband of Mg is completely filled it behaves as a metal, because the only prerequisite for behaving as metal is at least some of the electrons in its filled band must have access to an empty higher energy band .n In Mg even if the s band is completely filled some of the electrons in this completely filled sband present at the boundary is having access to the subsequent higher energy empty pband since both these bands overlaps each other.n Hence it act as metal."
3 "Becouse both of them have e near the boundary."
1 "3s shell of sodium is half filled, and 3s2 of magnesium is completely filled with electrons."
3 "Magnesium behaves like metal due to superposition of 3s and 3p orbitals due to the small energy difference between them. Low Band Gap"
3 "Both have partially filled conduction bands. Its just that the Mg Conduction band is made of overlapping s p bands."
2 "Because the magnesiums 3selectron can replace to one of the 3porbitals."
2 "Because the sband for the magnesium is in contact with its pband, so some electrons can go from the highest orbitals in the sband to the lowest ones in the pband."
2 "Because the sband for the magnesium is in contact with its pband, so some electrons can go from the highest orbitals in the sband to the lowest ones in the pband."
2 "Magnesium behave as a metal because of a partial overlap of the 3s and the empty 3p bands. With this overlap, electrons can be activated into empty 3p states and exhibit conduction, as in the partly filled s band in Na."
1 "Because of overlap between pband and sband , the high energy level electron in magnesium can move up to unoccupied pband."
2 "Because the combination of the p atomic orbitals of Magnesium generates a band of p molecular orbitals that can be occupied by the electrons when excited"
3 "Because the combination of the p atomic orbitals of Magnesium generates a band of p molecular orbitals that can be occupied by the electrons when excited"
3 "sodium behaves as metal because electrons can move from one molecular orbital to another molecular orbital in sband , thus allowing conduction . in case of magnesium the energy gap between sband and pband is very low , so even though the sband is filled conduction occurs by movement of electrons from sband to pband , thus magnesium also behaves as metal."
3 "Because, the electrons at the top energy level are able to move to a empty level which has a higher energy. For sodium, its s band is not full so for some electrons they can get energy to another higher level. As for magnesium, although the sband is filled, the pband has the near energy, or in other words, the two energy band have intersect. So the electrons at the sband can get energy and move to the pband.nFrom the analysis above, we can see that both sodium and magnesium behave as metals"
2 "To be a metal electrons need to be able to move. They do this by moving from one energy band to that if a higher energy band.nIn Na the other s orbital is vacant, so electrons can be promoted into these.nIs 2s. In 2 orbital are also spaces for 6 p electrons. nMg can be a metal as electrons promoted from s to p"
3 "Although the sband of magnesium is filled, the band gap between the sband and the pband is very small, this allows the electrons from the sband jump to the pband. The electrons in Na also have this movility in the sband, this movility gives the material the proporty of conduct electricity typicall of metals "
2 "The pband of magnesium is so close to the sband they actually overlap that it takes nearly no energy to excite an electron into the pband. Therefore, electrons near the pband can accept energies that are released from colliding with nuclei and can be accelerated by an electric field. Also, they can absorb light of many different wavelengths and reemitt light of many different wavelengths, giving the metal its shiny appearance."
0 "Na and Md have selectrons on the valence electron level. Na 1e and Mg 2e. But in Mg crystal electrons can occupai pband too becaus they can emigrate from slevel to plevel. And Na have only sband, but Mg can have s and pbands together.n Electrons from Na and Mg crystals can be cut of easy from sband and pband."
1 "It is obvious that the magnesiums pband orbitals overlap with the sband. This provides the possibility for the electrons from the sband to diffuse into higher energy orbitals, thus every metal atom with nearly energetically allocated other types of bands can behave as metal conduct current."
2 "Thats because the pband of magnesium is close to its sband and nottaken such that the electrons from the latter can move into the pband when electric field is applied."
2 "Both sodium and magnesium behave as metals, even though the sband of magnesium is filled because the 3p orbitals of magnesium, while empty in an single atom, expand into a band that overlaps the 3s band. As magnesium atoms push together, the electrons initially enter the 3s band, but ultimately the highest energy electrons in the 3s band spill over into the lower energy levels in the 3p band. Sodium, instead, behaves as a metal due to the half filled 3s band that forms the cohesive energy."
2 "Sodiums electrons can move because sband is halffilled. Mg has an overlap between pband and sband, so that electrons have access to the higher energy state from sband to pband."
2 "The sband of Mg is filled with electrons 3s2. However, the s and p band energies have started to overlap.Electrons from the upper energy levels of the sband can jump into the pband and have freedom to move. As they can move about they can behave as a metal and conduct electricity."
2 "electron configuration of Mg is Ne3s2.and we know tow energy levels 3s and 3p are close. however sbanding is filled, as schematic diagram shows sband and pband over lap energy, so electrons can change energy easily and get pband which is empty. in fact, Mg has conductive band .as result of it, Mg behave a metal.nn Na has an electron configuration Ne 3s1 so half of s shell is occupied. the schematic diagram shows just half of sband is filled therefor Na has conductive band and electrons have opportunity to change energy easily. because they dont a lot of energy so, it is a good electron conductor. "
2 "The Na would because of the 3s1 orbital,this would allow the electrons to have access to the boundary. The Mg because it overlaps into the 3P orbitalnallowing room for electrons energy gain. "
1 "Electrons can easily move into empty pband, hence conductive,"
3 "Part of the bonding region in the pband of Magnesium is around the same energy as part of the antibonding region of the sband. The sband of Magnesium is completely filled, while the pband is completely empty. Therefore, electrons in the s subshell can accept energy and transfer into the p subshell. This allows for conductivity and Magnesium behaves like a metal. Sodium behaves like a metal because of energy transfer within the s subshell that occur between the bonding and antibonding band regions."
1 "Because still only few electrons compared to the whole neighbours with the pband.n"
0 ""
3 "Sband is halffilled in Na and empty bands are very close to full bands so electrons can jump to conduction bands. In Mg pband overlaps with sband to give similar properties.n"
3 "For a material to behave as a metal or exhibit properties of a metal, it is required to have an empty band of molecular orbitals with slightly higher energy. This is because, the properties of a metal are on account of the existence of free electrons within the structure. Now, In sodium metal, the band of molecular orbitals formed is from the 2s atomic orbitals only. This band is halffilled, and as a result, the electrons with the energies equivalent to or just equivalent to the level of the halffilled band can be excited and sent to the unfilled half part of the band. However, in case of Magnesium metal, in spite of both the electrons in a single atom of Magnesium being in the 2s atomic orbital, the molecular orbitals band is formed from the 2s as well as the empty 2p atomic orbitals. The electrons completely fill up the s part of the band, but the p part remains unfilled. This facilitates for some of the electrons to be excited and sent to a higher energy band, where they can be free to some extent. It is this availability of the empty part in the band of molecular orbitals, and thus of electrons to be able to excite, that enables Magnesium metal also to behave as a metal, justlike Sodium. "
2 "In Mg metal electrons from the filled sband can move into the lower levels of the empty pband, as its energy level overlaps with the top of the sband. This movement of electrons in energy bands allows the metallic behaviour. "
3 "According to Aufbaus principle, the lowest energy states of the band are filled first and the upper states remain empty u2013 but can readily be occupied by electrons upon thermal excitation or the application of an electric field. In other words, to be a metal, it requires some of the electrons in the electronic structure to have access to empty states very close to the top of this filled boundary. nHowever, in the case of Magnesium where the sband is filled, there is the pband for electrons to move to. There are unoccupied orbitals just on top of the 3sband which is the 3pband. As the sband and pband meet, they mix therefore giving electrons enough space to roam."
2 "Because there is an overlap between the S band and the P band. Thus, it is possible for the electrons to get excited into the p band in the magnesium metal."
3 ""
2 "Sodium is located in one family and this group all elements are metals, are excellent conductors of electricity, soft and highly reactive. Have outermost electron in an electron weakly bonded to the core and generally forms univalent compounds, ionic and colorless. He has one valence electron in the outermost orbital s an electron, which occupies a spherical orbital. Ignoring the internal filled electron shell, their electronic configurations can be written as 2s1. The valence electron is quite removed from the core. Thus, the core is loosely bound and can be removed with ease. In contrast, the remaining electrons are closer to the core are more firmly attached and removed with difficulty. At room temperature adopt the bodycentered cubic structure, with coordination number 8.nNow magnesium is less reactive than sodium. he is bivalent and form colorless ionic compounds, have two electrons in the outermost electron level is a strong reducing agent, the fact that it has two electrons in the outer shell gives a distinctive feature to the metal."
2 "Magnesium behaves as metal even though the sband is filled because the pband is close in energy to the sband, so the electrons in the higher energy orbitals of the sband can move to the pband."
2 "This is because the magnesium metal has low energy empty orbitals of the pi band that can accept electron density form the s band orbitals. This is, even though the s band is full, Mg metal can donate electrons to the p band and be modifyed by an electric field as any other metal with empty s band orbitals."
2 "Magnesium can behave as a metal since, though to 3s subshell is full, the 3p subshell is not, and so electrons can jump to those orbitals and move freely. Thus magnesium can also display metallic properties, despite having a filled outermost orbital."
3 "because there is empty energy states or unfilled orbitals very close to the top of the filled boundary"
3 ""
1 "Perhaps Mg creates an sp2 hybrid orbital that eventually forms the molecular orbitals. Which can therefore be halffilled."
1 "The overlap in s and pbands in Mg allows for the small energy transitions of electrons necessary for metals."
1 "."
2 "Magnesium behaves as metal, because the filled sband and the empty pband overlap. The pband in Magnesium is partially filled. "
1 "This effect is due to the fact that in the magnesium metal, even though the sband is completely filled, the pband is empty and close enough in energy that the electron, when supplied energy, will jump from the sband to the pband."
2 "Na only half of the sband is filled with e. With little energy gaining by an Efield, for example some e can reach empty sorbitals and travel around the cristal.nnMg the whole sband is filled with e. But the free pband overlaps on the energyscale and so some e can occupy pbandorbitals and freeing sbandorbitals and lowering the overall energy of the cristal. Now, with little energy gaining by an Efield, for example some e can reach empty s and porbitals and travel around the cristal."
3 " The explanation is that, since 3p and 3s valence orbitals of adjacent atoms are farther from their nucleus, their interaction is stronger than that of filled inner orbitals in the core. This results in valence bands to have a larger bandwidth causing 3s and 3p orbitals to overlap and the energy gap between them to disappear. The consequence is that a new band with a total capacity of eight electrons is obtained.n This way Nas band and Mgs band, both formed by delocalized orbitals, are partially filled 18th and 14th respectively and comply with the two requisites to behave as a metal."
1 "Because in both of the cases, there are electrons that have access to the empty states at the top."
2 "Magnesium is a metal with the structure 1su00b2 2su00b2 2pu2076 3su00b2. For the quantum orbits with n3 it seems to be that the upper part of the 3s band created by all the atoms together in the solid overlaps with the lower part of its 3p band. That overlapping makes possible for eu207b to jump to the 3p as it was the conduction band empty of eu207b, with the result that it behaves like the antibonding band of the Sodium. In that way eu207b can travel through the valence band upper 3s band to the conduction band lower 3p band and the Mg behaves as a metal element. That implies the possibility to transmit a current through Mg and its metal behaviour."
1 "The sband of Mg, though filled, overlaps with the pband orbitals. Electrons at the top of the sband are able to use orbitals in the pband."
2 "The excited electrons from Magnesium would not be able to create a molecular orbital sshell if it is already filled, so they must jump into the porbital."
1 "The molecular orbitals of Magnesium can be formed by both s and p orbitals i.e, s and p orbitals can hybridize because they are close in energy. Thus Magnesium will also have partially filled band and can behave as a metal."
1 "In the magnesium, the sband and the pband overlap. Electrons are able to move from the sband to the pband the same way electrons are able to move higher in the sband in the sodium. "
1 "Magnesium behave live metal because have empty orbitals in the pband that are closely the boundary filled orbitals of the sband. That way, the electrons of that boundary orbitals, can easily be influenced by the electric field."
2 "By linear combination of atomic orbitals LCAO to determine the MO state, we obtain the number of electronic states depends on the chain of atoms within upper and lower limit an energy band. According to the Pauli principle, the electronic states orbitals within an energy band are filled progressively by pairs of electron.nWe can see that each 3s state of valence shell in the Na atoms is halffilled 3s1 while Mg atoms is doubly occupied 3s2 therefore the sband of Na will be halffilled and sband of Mg is filled actually there is a partially overlap of the 3s and 3p."
3 " Metals tend to be good electronic conductors, meaning that they have a large number of electrons which are able to access empty mobile energy states within the material.n Sodium has a halffilled sband, so there are a number of empty states immediately above the highest occupied energy levels within the band.n Magnesium has a full sband, but the the sband and pband overlap in magnesium. Thus are still a large number of available energy states immediately above the sband highest occupied energy level."
2 "At interaction of atoms Mg participate not only ssubshells, but psubshells too,the continuous power zone is as a result formed, this zone is not fulled by electrons, pband adjoins to sband, and we observe u0435u0440u0444u0435 magnesium behave as metal"
1 "Even though the sband of magnesium is filled, pband has plenty of empty orbitals, and there is no gap between the s and pbands, therefore electrons can behave in the same way, leading to metallic behavior."
3 "Sodium behaves as metal, because it has a half filled sbandwith and enough free electronic states to which electrons can be excited by an electric field. In Magnesium the sband is completely filled. But since the sband overlaps with the pband, the small amount of energy supplied by an electric field is sufficient to excite selectrons to electronic states in the empty pband. So also magnesium is metallic. Just as in sodium, an electric field can induce an electric current."
3 "p orbital is empty"
3 "In Metals electrons are mobile.nIn Na, the higher energy electrons located in the valance band can easily transition to the conduction band. nnIn Mg the only difference is that the conduction band is a pband, not an sband. Mg highest energy electrons can easily move to this pband the conduction band."
0 "Because the difference between states even in magnesium is very little and all the electrons from s band of magnesium act as free electrons somehow and they can move also with little energy."
1 "The overlapping region between the sband and the pband confers metallic properties to magnesium."
3 "Magnesium has all the 3s energy level completed with electrons, so it wouldnt be a conductor in normal cases , but in this , p band is very close in energy so the electrons can be excited and go to the p band making it conductive metal , if the gap was larger , we will have a semiconductor , and if it was more larger we will have non conductor . In Na metal the 3s level is not filled so electron can move in the last ocuppied level is half full so we have a good conductor ."
2 "Because in Mg electrons are able to reach empty porbitals and thus accept the energy on applying electric field."
2 "Because the electrons of sband of Mg, even this band is filled, can accept the energy of the electric field and fill the pband that is empty."
1 "The p and sband in Mg overlap, so the electrons in the sband can be excited to an Elevel in the pband which serves as the conduction band. "
2 "There is some overlap between the s and p band, so we get a hybridised sp band. This is only 14 full, so conduction can occur"
3 "Magnesium behave as metal even though the sband is filled, because it has the pband completely empty. So, the electrons that are on the threshold between the sband and pband are able to acquire more energy by moving to the pband."
3 "Metals tend to be good electronic conductors, meaning that they have a large number of electrons which are able to access empty mobile energy states within the material.nSodium has a halffilled sband, so there are a number of empty states immediately above the highest occupied energy levels within the band.nMagnesium has a full sband, but the the sband and pband overlap in magnesium. Thus are still a large number of available energy states immediately above the sband highest occupied energy level."
2 "The electrons are able to move into an unoccupied shell where they are free to move. "
3 ""
2 "sodium has a half filled band and conducts by its antibonding half or conducting band, so itu00b4s a metal, in the Mg case we have an overlaping of the s and p bands so electrons can use the p orbitals to travel so the p band is the conduction band.nIm portuguese so sorry for any typos, and i saw all the classes before answering, i usualy take all the classes first"
3 ""
3 "They are both metals because the electrons that are on the border of the Sband either S to p band as in Mg, or half the Sband as in Na. These electrons on the border are going to be affected by an electron field, causing them to move up into the empty shells. This will cause energy to be released, giving metallic properties. "
2 "Sodium behaves as a metal because the electrons on the border of the filled and empty orbitals can be influenced by the electric field and can move up to a higher energy state. Magnesium behaves as a metal because the electrons in the overlap between the s and p orbitals have an ability to be influenced by the electric field and therefore move up to a higher energy state. This is why both sodium and magnesium behave as metals."
2 "The atom of Na has next electronic configuration Ne 3s1. Sodium behaves as metal because the net of nucleons has a halffilled sband with 3selectrons, where there are filled the 3sbonding orbitals .nThe Mg with next electronic configuration Ne 3s2, has completed the 3s orbital, but still there are empty 3porbitals to be filled for any 3selectron in interaction with a electric field."
1 "The sband and pband overlap in magnesium"
3 "Both behave as metals because there are enough free carrier energy levels inmediately above the fermi level. No energy gap exists between both bands in the Mg metal because of the overlap between the s and pband. Consequently, any electron of these energy bands can move freely occupying empty levels inmediately above the fermi level and, thus, showing metal behavior."
3 "Both Na and Mg behave as metals because they have empty MO close in energy to the filled MO. This means that the e at the highest energy filled MO can absorb tiny amounts of energy, so they can interact with an electric field when it is applied to the material."
3 ""
3 "In both cases electrons can gain a little part of energy be accelerated by the electric field and occupied a higher state. Sodium sband is half full and electron around middle can be excited to the higher state in sband. In Magnesium case full filled sband, the higher states in sband overlap the state in pband. Energy of highest state in sband is higher then lowest state in pband. Electron of highest state in sband can get a little part of energy and occupied a pband state, so it can be accelerated by the electric field."
3 "Sodium has a completely filled s valence band, but the s conduction band is empty and very close in energy to the valence band, so electrons at room temperature have enough energy to move into the conduction band where they can flow freely. Magnesium, in contrast, has a completely filled s band, but the empty p band overlaps with the s band, again allowing the electrons to transition from one to the other and flow."
2 ""
0 ""
3 "Metals tend to be good electronic conductors, meaning that they have a large number of electrons which are able to access empty mobile energy states within the material.nnSodium has a halffilled sband, so there are a number of empty states immediately above the highest occupied energy levels within the band.nnMagnesium has a full sband, but the the sband and pband overlap in magnesium. Thus are still a large number of available energy states immediately above the sband highest occupied energy level."
1 "because the pband is very close in energy to the s band and we have a lot of empty p orbitals close in energy to the sband and because the p orbitals are partly filled."
2 "in sodium 3s orbit is half filled and in magnisium electrons jumps from 3s to vacant 3p orbit."
3 "Nes turi laisvu0105 p band p orbitales u012f kurias gali peru0161okti elektronas."
1 "The different level of energy are very similar for Mg as seen, there is some overlapp that allows electron to move into higher energy simply with room temperature."
2 "Thinking only about the sband in a magnesium crystal, its not clear how this metal have a behavior ofa metal. The full band shows that we cant have charge carriers, so, the eletrical condutivity, based on this facts, must be zero.nFor another point, we need to take care with the pband energy structure. If we look to the figure, we can see that the top of th sband have the same energy of the bottom of the pband. This means that, for thermal excitations, the charge carriers electrons can jump for the pband, where they are free to move as charge carriers."
1 "Magnesium electrons still have unfilled energy states that are relatively close to the top of the sband."
1 "Band s and band p overlap, so the electron can go fron s band into p band, because there is no gap between s and p band."
1 "because the electron can be excited to the p band."
3 "The bands overlap, so no problem if an electron from the s band gets some small energy. It just moves to pband. In any case the electron only needs a valid orbital to move to and is pretty much indifferent on how we name it."
3 "The Na has the s band half filled, so the electron can move trough the half band that is empty, while the Mg, in spite of having the s band filled, is also a metal because there are not energy gap between the s band and the p band, so the electron can move trough the p band"
1 "Because the sband and pband of Mg overlap, i.e. they are partially degenerate, electrons in orbitals close in energy to the pband can accept energy and move into pband orbitals. If the s and p bands did not overlap, the electrons from the s band would not be able to cross the band gap they would not have enough energy."
2 "Its because the energy level of the free pband begins under the top of sband, so the electrons can freely move from one band to another and use free pband as the extension of the filled sband. "
0 "Sodium and Magnesium both behave as metals, even though the sband of magnesium is filled because the band is the same size with similar magnitude despite Magnesium having a mixture of a pband and a sband slightly overlapping each other as same diameter in this comparison showing same pressure because Magnesium usually has a larger atomic radius."
2 "Sodium behaves as a metal because even though the molecular orbitals are filled, the electrons near the boundary between the bonding and anti bonding orbitals are able to move into the anti bonding orbitals a higher orbital when an electric field is applied because they are supplied with energy which accelerates the electrons through the crystal structure. The same applies for Magnesium Metal because all though the sband is full the electrons near the boundary are able to move into the higher empty porbitals."
3 "In order for the elements to behave as metals, both Na and Mg must have empty states in their respective bands for electrons to occupy when accepting energy from an electric field. Sodium has a halfempty sband, which is occupied by boundary electrons when they accept energy. Although the sband of the Mg metal is filled, there is an overlap between the pband and the sband. Boundary electrons in the Mg metals sband are therefore able to occupy empty states in the pband when accepting energy from an electric field, which is the behavior necessary to be a metal."
1 "Because the distance in energy between s and p orbitals in Mg is small, and the higher energy s electrons can propell themselves under the force of an electric field to the higher in energy p band. So p band in a way is acting as an empty continuation of s band.nThe low electronegativity of Mg helps this,too."
2 "In both cases, there are unoccupied orbitals withinreach of occupied orbitals. In sodiums case, it is the upper half of the sband within reach of the lower half in magnesiums case, it is the pband within reach of the sband."
1 "Mg Electrons can move into the unfilled Pband where they can conduct. The filled SBand overlaps with the unfilled PBand and so not much energy is needed to achieve a conducting state."
3 "Presumably the electrons in Mg near the surface can move into the p orbitals when they gain energy"
0 "Presumably the electrons in Mg near the surface can move into the p orbitals when they gain energynNa has s orbitals that the energised electrons can move inton"
3 ""
1 "Because e in magnesium could jump out to the pband"
1 "Because the metals need some free space to move electrons and they both have enough free space."
1 "Because the sband and the pbands overlap thus the electrons in that overlapping area can move to the pband."
2 "Both elements have valence bands that are partly filled, so in both cases electrons can be promoted to other energies within the band for a very low deltaE. "
2 "There are orbitals on top of the upper most filled molecule orbitals."
2 "Because energy levels of p and sbands in Mg overlap no band gap, electrons can accelerate from valence to the conductivity zone."
3 "As we have seen in the sreenshot before, for an electron in order to accept the energy given by an electric field, it needs to be able to move up to another unoccupied level of energy. Only the electrons near the boundary between the filled molecular orbitals and the empty molecular orbitals can do so. This means that for a given element to have metallic character, it requires some of the electrons in the electronic structure to have access to empty states very close to the top of this filled boundary. For both Na and Mg, this is the casenNa has access to the non filled orbitals in the s band, while Mg has access to the non filled orbitals of the pband, that are that close in energy with its Sband that both sband and pband are able to overlap, allowing the electrons to reach the nonfilled energy levels."
1 "Because the electrons would gain enough energy to jump orbitals if there is an electric field."
2 ""
3 "fre"
3 "Because the s and p bands in magnesium slightly overlap, and therefore the electrons in states closely below the Fermi level have states closely above it readily available, which is a requisite for metallic electron transport."
3 "Electron conduct under an external excitation such as a bias voltage occurs if there exist vacant states closely above the Fermi level readily available to the electrons occupying the band states closely below the Fermi level.nnThis requisite is obviously satisfied in sodium, as the sband is halffilled and it is also satisfied in magnesium, for which the the s and p bands show a slight overlap in their upper and lower ends, and regardless of the fact that the sband is completely filled by electrons, theres still vacant states readily available for these electrons."
3 ""
3 "firts Metals tend to be good electronic conductors. Second Sodium has a halffilled sband. Third Magnesium has a full sbandn"
2 "Because sand pband acts as continous band therefore, the upper sband electrons have access to empty states pband lower states located very close to them. This access to very close empity states defines a metal."
2 "Sodium has a half filled sband and so the electron can mobilize throughout the sband characteristic of metals.nMagnesium sband and pbands overlap meaning they are energetically similar and the electron from the sband can mobilize within the pband which is characteristic of a metal."
In order to replicate this experiment, I would need to know additional information such as the four different samples that they used (because I could have choosen metal, carbboard and many other sample materials that they didn't use and would get different results. Also I would also need to know the amount of vinegar to pour because this can caute a major change. Lastly, they might want to tell where to sit the samples while they dry for 30 minutes because if they are sitting in room temp. or by a light source makes a difference too.
{"grader":"tests/models/essay_set_1.p"}
this is an incorrect response
import os
import sys
base_path = os.path.dirname(__file__)
sys.path.append(base_path)
one_up_path=os.path.abspath(os.path.join(os.path.dirname(__file__),'..'))
sys.path.append(one_up_path)
import util_functions
import essay_set
import feature_extractor
import numpy
from sklearn.ensemble import GradientBoostingClassifier
if not base_path.endswith("/"):
base_path=base_path+"/"
FILENAME="sa_data.tsv"
all_err=[]
all_kappa=[]
for t_len in [0,50,100,200,300]:
sa_val = file(FILENAME)
scores=[]
texts=[]
lines=sa_val.readlines()
eset=essay_set.EssaySet(type="train")
for i in xrange(1,len(lines)):
score,text=lines[i].split("\t\"")
if len(text)>t_len:
scores.append(int(score))
texts.append(text)
eset.add_essay(text,int(score))
#if int(score)==0:
# eset.generate_additional_essays(text,int(score))
extractor=feature_extractor.FeatureExtractor()
extractor.initialize_dictionaries(eset)
train_feats=extractor.gen_feats(eset)
clf=GradientBoostingClassifier(n_estimators=100, learn_rate=.05,max_depth=4, random_state=1,min_samples_leaf=3)
cv_preds=util_functions.gen_cv_preds(clf,train_feats,scores)
err=numpy.mean(numpy.abs(cv_preds-scores))
print err
kappa=util_functions.quadratic_weighted_kappa(list(cv_preds),scores)
print kappa
all_err.append(err)
all_kappa.append(kappa)
"""
outfile=open("full_cvout.tsv",'w+')
outfile.write("cv_pred" + "\t" + "actual")
for i in xrange(0,len(cv_preds)):
outfile.write("{0}\t{1}".format(cv_preds[i],scores[i]))
"""
import os
import sys
base_path = os.path.dirname(__file__)
sys.path.append(base_path)
one_up_path=os.path.abspath(os.path.join(os.path.dirname(__file__),'..'))
sys.path.append(one_up_path)
import util_functions
import essay_set
import feature_extractor
import numpy
import math
from sklearn.ensemble import GradientBoostingClassifier
if not base_path.endswith("/"):
base_path=base_path+"/"
filenames = ['LSQ_W09_60_MLT.tsv',
'LSQ_W10_22_a.tsv',
'LSQ_W11_21_MLT.tsv',
]
for filename in filenames:
base_name = base_path + filename
print base_name
sa_val = file(base_name)
scores=[]
texts=[]
lines=sa_val.readlines()
eset=essay_set.EssaySet(type="train")
for i in xrange(1,len(lines)):
score,text=lines[i].split("\t\"")
scores.append(int(score))
texts.append(text)
eset.add_essay(text,int(score))
#if int(score)==0:
# eset.generate_additional_essays(text,int(score))
extractor=feature_extractor.FeatureExtractor()
extractor.initialize_dictionaries(eset)
train_feats=extractor.gen_feats(eset)
clf=GradientBoostingClassifier(n_estimators=100, learn_rate=.05,max_depth=4, random_state=1,min_samples_leaf=3)
cv_preds=util_functions.gen_cv_preds(clf,train_feats,scores, num_chunks = int(math.floor(len(texts)/2)))
err=numpy.mean(numpy.abs(numpy.array(cv_preds)-scores))
print err
kappa=util_functions.quadratic_weighted_kappa(list(cv_preds),scores)
print kappa
outfile=open(filename + "_cvout.tsv",'w+')
outfile.write("cv_pred" + "\t" + "actual\n")
for i in xrange(0,len(cv_preds)):
outfile.write("{0}\t{1}\n".format(str(cv_preds[i]),str(scores[i])))
outfile.close()
import os
import sys
base_path = os.path.dirname(__file__)
sys.path.append(base_path)
one_up_path=os.path.abspath(os.path.join(base_path,'..'))
sys.path.append(one_up_path)
import util_functions
import predictor_set
import predictor_extractor
import numpy
from sklearn.ensemble import GradientBoostingClassifier
if not base_path.endswith("/"):
base_path=base_path+"/"
FILENAME="sa_data.tsv"
sa_val = file(FILENAME)
scores=[]
texts=[]
lines=sa_val.readlines()
pset = predictor_set.PredictorSet(type="train")
for i in xrange(1,len(lines)):
score,text=lines[i].split("\t\"")
if len(text)>t_len:
scores.append(int(score))
texts.append(text)
pset.add_row([1],[text],int(score))
extractor=predictor_extractor.PredictorExtractor()
extractor.initialize_dictionaries(pset)
train_feats=extractor.gen_feats(pset)
clf=GradientBoostingClassifier(n_estimators=100, learn_rate=.05,max_depth=4, random_state=1,min_samples_leaf=3)
cv_preds=util_functions.gen_cv_preds(clf,train_feats,scores)
err=numpy.mean(numpy.abs(cv_preds-scores))
print err
kappa=util_functions.quadratic_weighted_kappa(list(cv_preds),scores)
print kappa
\ No newline at end of file
#!/usr/bin/env python
"""
Send some test programs to an xserver.
For each dir in the current directory, send the contents of payload.xml and each
of the answer*.py, right*.py and wrong*.py files.
"""
import argparse
import glob
import json
import os
import os.path
from path import path
import requests
import sys
import time
xserver = 'http://127.0.0.1:3031/'
def send(payload, answer):
"""
Send a grading request to the xserver
"""
body = {'grader_payload': payload,
'student_response': answer}
data = {'xqueue_body': json.dumps(body),
'xqueue_files': ''}
start = time.time()
r = requests.post(xserver, data=json.dumps(data))
end = time.time()
print "Request took %.03f sec" % (end - start)
if r.status_code != requests.codes.ok:
print "Request error:{0},{1},{2}".format(r.headers,payload,answer)
parsed_text=json.loads(r.text)
print("\nAnswer: {0}\nScore: {1} Correct: {2} \nFeedback: {3}"
.format(answer,parsed_text['score'],parsed_text['correct'],
parsed_text['feedback']))
#print "Score:{0} {1}".format(parsed_text['score'],parsed_text['correct'])
return r.text
def check_contains(string, substr):
if not substr in string:
print "ERROR: Expected to be {0}".format(substr)
return False
else:
return True
def check_not_contains(string, substr):
if substr in string:
print "ERROR: Expected to be {0}".format(substr)
return False
else:
return True
def check_right(string):
return check_contains(string, '\"correct\": true')
def check_wrong(string):
return check_contains(string, '\"correct\": false')
def globs(dirname, *patterns):
"""
Produce a sequence of all the files matching any of our patterns in dirname.
"""
for pat in patterns:
for fname in glob.glob(os.path.join(dirname, pat)):
yield fname
def contents(fname):
"""
Return the contents of the file `fname`.
"""
with open(fname) as f:
return f.read()
def check(dirname,type):
"""
Look for payload.json, answer*.py, right*.py, wrong*.py, run tests.
"""
payload_file = os.path.join(dirname, 'payload.json')
if os.path.isfile(payload_file):
payload = contents(payload_file)
print("found payload: " + payload)
else:
graders = list(globs(dirname, 'grade*.py'))
if not graders:
#print "No payload.json or grade*.py in {0}".format(dirname)
return
if len(graders) > 1:
print "More than one grader in {0}".format(dirname)
return
payload = json.dumps({'grader': os.path.abspath(graders[0])})
for name in globs(dirname, 'answer*.txt', 'right*.py'):
#print "Checking correct response from {0}".format(name)
answer = contents(name)
right=check_right(send(payload, answer))
for name in globs(dirname, 'wrong*.txt'):
#print "Checking wrong response from {0}".format(name)
answer = contents(name)
wrong=check_wrong(send(payload, answer))
if(type=="test"):
assert wrong and right
def main(argv):
global xserver
#parser = argparse.ArgumentParser(description="Send dummy requests to a qserver")
#parser.add_argument('server')
#parser.add_argument('root', nargs='?')
#args = parser.parse_args(argv)
#xserver = args.server
if not xserver.endswith('/'):
xserver += '/'
#root = args.root or '.'
root=os.path.dirname( os.path.abspath(__file__ ))
for dirpath, _, _ in os.walk(root):
print("checking" + dirpath)
check(dirpath,"normal")
if __name__=="__main__":
main(sys.argv[1:])
def test_graders():
root=os.path.dirname( os.path.abspath(__file__ ))
for dirpath, _, _ in os.walk(root):
print("checking" + dirpath)
yield check, dirpath, "test"
def test_model_creation():
model_creator_dir=os.path.abspath(os.path.join(os.path.dirname(__file__),'..'))
# Run with arguments train_file prompt_file model_path to generate a sample model file
import os
import sys
import argparse
base_path = os.path.dirname(__file__)
sys.path.append(base_path)
one_up_path = os.path.abspath(os.path.join(os.path.dirname(__file__),'..'))
sys.path.append(one_up_path)
import model_creator
def main(argv):
parser = argparse.ArgumentParser(description="Generate model from test data files")
parser.add_argument('train_file')
parser.add_argument('prompt_file')
parser.add_argument('model_path')
args = parser.parse_args(argv)
score, text = model_creator.read_in_test_data(args.train_file)
prompt_string = model_creator.read_in_test_prompt(args.prompt_file)
print("data read")
e_set = model_creator.create_essay_set(text, score, prompt_string)
print("essay set created")
feature_ext, classifier = model_creator.extract_features_and_generate_model(e_set)
print("features pulled out and model generated")
model_creator.dump_model_to_file(prompt_string, feature_ext, classifier, text, score, args.model_path)
print("model file written")
if __name__ == "__main__":
main(sys.argv[1:])
def test_model_creation():
try:
score, text = model_creator.read_in_test_data("train.tsv")
prompt_string = model_creator.read_in_test_prompt("prompt.txt")
e_set = model_creator.create_essay_set(text, score, prompt_string)
feature_ext, classifier = model_creator.extract_features_and_generate_model(e_set)
model_creator.dump_model_to_file(prompt_string, feature_ext, classifier, args.model_path)
assert True
except:
assert False
in order to replicate this experiment , we would need to know the temperature of the vinegar as well as how much vinegar to put in . both of these could vary and therefore change the result of the experiment .
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
in order for i for replicate this expirement i woukd need to know what are the reaserching with this expirement what kind of result are being booked at and the mass of each sample at the end of expirment theie results . i didn't know what the answer is .
\ No newline at end of file
#Collection of misc functions needed to support essay_set.py and feature_extractor.py.
#Requires aspell to be installed and added to the path
from external_code.fisher import fisher
aspell_path = "aspell"
import re
import os
from sklearn.feature_extraction.text import CountVectorizer
import fisher
import numpy
from itertools import chain
import math
import nltk
import random
import pickle
from path import path
import logging
import sys
log=logging.getLogger(__name__)
base_path = os.path.dirname(__file__)
sys.path.append(base_path)
if not base_path.endswith("/"):
base_path=base_path+"/"
#Paths to needed data files
ESSAY_CORPUS_PATH = base_path + "data/essaycorpus.txt"
ESSAY_COR_TOKENS_PATH = base_path + "data/essay_cor_tokens.p"
class AlgorithmTypes(object):
"""
Defines what types of algorithm can be used
"""
regression = "regression"
classification = "classifiction"
def create_model_path(model_path):
"""
Creates a path to model files
model_path - string
"""
if not model_path.startswith("/") and not model_path.startswith("models/"):
model_path="/" + model_path
if not model_path.startswith("models"):
......@@ -36,7 +51,9 @@ def sub_chars(string):
Strips illegal characters from a string. Used to sanitize input essays.
Removes all non-punctuation, digit, or letter characters.
Returns sanitized string.
string - string
"""
#Define replacement patterns
sub_pat = r"[^A-Za-z\.\?!,';:]"
char_pat = r"\."
com_pat = r","
......@@ -44,26 +61,18 @@ def sub_chars(string):
excl_pat = r"!"
sem_pat = r";"
col_pat = r":"
whitespace_pat = r"\s{1,}"
whitespace_comp = re.compile(whitespace_pat)
sub_comp = re.compile(sub_pat)
char_comp = re.compile(char_pat)
com_comp = re.compile(com_pat)
ques_comp = re.compile(ques_pat)
excl_comp = re.compile(excl_pat)
sem_comp = re.compile(sem_pat)
col_comp = re.compile(col_pat)
nstring = sub_comp.sub(" ", string)
nstring = char_comp.sub(" .", nstring)
nstring = com_comp.sub(" ,", nstring)
nstring = ques_comp.sub(" ?", nstring)
nstring = excl_comp.sub(" !", nstring)
nstring = sem_comp.sub(" ;", nstring)
nstring = col_comp.sub(" :", nstring)
nstring = whitespace_comp.sub(" ", nstring)
#Replace text. Ordering is very important!
nstring = re.sub(sub_pat, " ", string)
nstring = re.sub(char_pat," .", nstring)
nstring = re.sub(com_pat, " ,", nstring)
nstring = re.sub(ques_pat, " ?", nstring)
nstring = re.sub(excl_pat, " !", nstring)
nstring = re.sub(sem_pat, " ;", nstring)
nstring = re.sub(col_pat, " :", nstring)
nstring = re.sub(whitespace_pat, " ", nstring)
return nstring
......@@ -72,7 +81,10 @@ def spell_correct(string):
Uses aspell to spell correct an input string.
Requires aspell to be installed and added to the path.
Returns the spell corrected string if aspell is found, original string if not.
string - string
"""
#Create a temp file so that aspell could be used
f = open('tmpfile', 'w')
f.write(string)
f_path = os.path.abspath(f.name)
......@@ -81,13 +93,16 @@ def spell_correct(string):
p = os.popen(aspell_path + " -a < " + f_path + " --sug-mode=ultra")
except:
log.exception("Could not find aspell, so could not spell correct!")
#Return original string if aspell fails
return string,0, string
#Aspell returns a list of incorrect words with the above flags
incorrect = p.readlines()
p.close()
incorrect_words = list()
correct_spelling = list()
for i in range(1, len(incorrect)):
if(len(incorrect[i]) > 10):
#Reformat aspell output to make sense
match = re.search(":", incorrect[i])
if hasattr(match, "start"):
begstring = incorrect[i][2:match.start()]
......@@ -101,6 +116,8 @@ def spell_correct(string):
incorrect_words.append(begword)
correct_spelling.append(sug)
#Create markup based on spelling errors
newstring = string
markup_string = string
already_subbed=[]
......@@ -419,13 +436,13 @@ def get_separator_words(toks1):
Returns a list of separator words
"""
tab_toks1 = nltk.FreqDist(word.lower() for word in toks1)
if(os.path.isfile("essay_cor_tokens.p")):
toks2 = pickle.load(open('essay_cor_tokens.p', 'rb'))
if(os.path.isfile(ESSAY_COR_TOKENS_PATH)):
toks2 = pickle.load(open(ESSAY_COR_TOKENS_PATH, 'rb'))
else:
essay_corpus = open("essaycorpus.txt").read()
essay_corpus = open(ESSAY_CORPUS_PATH).read()
essay_corpus = sub_chars(essay_corpus)
toks2 = nltk.FreqDist(word.lower() for word in nltk.word_tokenize(essay_corpus))
pickle.dump(toks2, open('essay_cor_tokens.p', 'wb'))
pickle.dump(toks2, open(ESSAY_COR_TOKENS_PATH, 'wb'))
sep_words = []
for word in tab_toks1.keys():
tok1_present = tab_toks1[word]
......
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