Skip to content

Commit

Permalink
Separating requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
aslucki committed Mar 31, 2019
1 parent d57da6b commit 73d838f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 14 deletions.
3 changes: 3 additions & 0 deletions Dockerfile
Expand Up @@ -20,5 +20,8 @@ RUN pip3 install --upgrade pip
COPY requirements.txt .
RUN pip3 install --no-cache-dir -r requirements.txt

COPY example/requirements.txt ./example/
RUN pip3 install --no-cache-dir -r example/requirements.txt

RUN git clone https://github.com/codalab/codalab-cli.git \
&& cd codalab-cli && ./setup.sh server
26 changes: 16 additions & 10 deletions example/evaluation.py
Expand Up @@ -62,9 +62,9 @@ def calculate_dataset_scores(dataset, predict_func, score_func):

scores = []
for entry in dataset:
for paragraph in entry['paragraphs']:
for paragraph in entry['paragraphs'][:10]:
context = paragraph['context']
for qa in paragraph['qas']:
for qa in paragraph['qas'][:5]:
gt_answers = [answer['text'] for answer in qa['answers']]
prediction = predict_func(context, qa['question'])
scores.append(metric_max_over_ground_truths(score_func,
Expand Down Expand Up @@ -93,32 +93,35 @@ def create_log_output(mean_scores, severity):
return output


def evaluate(squad_obj, score_func, predict_func, aspect):
def evaluate(squad_obj, score_func, predict_func, aspect, limit=10):

f1_original =\
calculate_dataset_scores(squad_obj.data['data'],
calculate_dataset_scores(squad_obj.data['data'][:limit],
predict_func, score_func)
means = [np.mean(f1_original)]
results = [create_log_output(means, 0)]

for severity in range(10, 101, 10):
print("Analysing {} with severity {}"
.format(aspect.__name__, severity))
try:
aspect_obj = aspect(words_percentage=severity)
means = []
for _ in range(10):
for _ in range(5):
modified = squad_obj.apply(aspect_obj)
f1_scores = calculate_dataset_scores(modified['data'],
predict_func,
score_func)
f1_scores =\
calculate_dataset_scores(
modified['data'][:limit], predict_func,
score_func)
means.append(np.mean(f1_scores))

results.append(create_log_output(means, severity))

except KeyboardInterrupt:
break

except:
pass
except Exception as e:
print("Error occurred:", e)

return results

Expand Down Expand Up @@ -149,7 +152,9 @@ def save_plot(main_results, main_results_label,


if __name__ == '__main__':
print(__file__)

''''
BiDAF = Predictor.from_path(
"https://s3-us-west-2.amazonaws.com/allennlp/models/bidaf-model-2017.09.15-charpad.tar.gz")
Expand Down Expand Up @@ -180,3 +185,4 @@ def bidaf_predict(context, question):
save_plot(qwerty_df, 'QWERTY', remove_char_df, 'RemoveChar',
'qwerty', 'Analysis of BiDAF robustness to QWERTY misspellings',
'RemoveChar for comparison')
'''
5 changes: 5 additions & 0 deletions example/requirements.txt
@@ -0,0 +1,5 @@
allennlp==0.8.3
matplotlib==3.0.3
numpy==1.16.2
pandas==0.24.2
requests==2.21.0
4 changes: 0 additions & 4 deletions requirements.txt
@@ -1,10 +1,6 @@
allennlp==0.8.3
matplotlib==3.0.3
numpy==1.16.2
num2words==0.5.9
pandas==0.24.2
pytest==4.2.0
requests==2.21.0
Sphinx==1.8.4
sphinx-rtd-theme==0.4.3
twine==1.13.0

0 comments on commit 73d838f

Please sign in to comment.