Skip to content

Commit

Permalink
Evaluation results combined
Browse files Browse the repository at this point in the history
  • Loading branch information
mrinalgrover committed Jun 27, 2022
1 parent 03c4afa commit 23c7e31
Show file tree
Hide file tree
Showing 4 changed files with 2,645 additions and 7 deletions.
15 changes: 9 additions & 6 deletions code/NER_Model.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,15 +350,18 @@ def predict(sentence, correct_spellings=True):

output_str = crf.predict([feat])
print(f" IOB Tagging : {output_str}")
output_str = NER_Model_postprocessing.tag_color(output_str)
output_str = NER_Model_postprocessing.tag_price(output_str)
output_str = NER_Model_postprocessing.tag_shape(output_str)
output_str = NER_Model_postprocessing.tag_size(output_str)

print(f"Postprocessed output: {output_str}")
result = []

for token, tag in zip(tokens, output_str[0]):
result.append((token, tag))

result = NER_Model_postprocessing.tag_color(result)
result = NER_Model_postprocessing.tag_price(result)
result = NER_Model_postprocessing.tag_shape(result)
result = NER_Model_postprocessing.tag_size(result)

print(f"Postprocessed output: {result}")

return result

def evaluate_results(token_list):
Expand Down
9 changes: 8 additions & 1 deletion code/evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ def evaluate(true_seqs, pred_seqs, verbose=True):
tokens = []
actual_tags = []
predicted_tags = []
evaluation_res = {"Token":[], "Actual Tag":[], "Predicted Tag":[]}
NER_Model.main()
for index, row in validataion_df.iterrows():
if row['Tokens'] is np.nan:
Expand All @@ -209,18 +210,24 @@ def evaluate(true_seqs, pred_seqs, verbose=True):
pred_tok_tag = Negation_Analyser.predict(predicted_ner, "tags")
for tag in pred_tok_tag['token-tags']:
predicted_tags.append(tag[1])
evaluation_res["Predicted Tag"].append(tag[1])
print(f"Predicted : {pred_tok_tag}")
sent = []
tok_tag_act = []

else:
sent.append(row['Tokens'])
evaluation_res["Token"].append(row['Tokens'])
if(row['is_negative'] is True):
tok_tag_act.append((row['Tokens'], row['Tags'].replace('I-', 'I-N-')))
actual_tags.append(row['Tags'].replace('I-', 'I-N-'))
evaluation_res["Actual Tag"].append(row['Tags'].replace('I-', 'I-N-'))
else:
actual_tags.append(row['Tags'])
tok_tag_act.append((row['Tokens'], row['Tags']))
evaluation_res["Actual Tag"].append(row['Tags'])


evaluate(actual_tags, predicted_tags)
evaluate(actual_tags, predicted_tags)
res_df = pd.DataFrame(evaluation_res)
res_df.to_csv('data/combined_evaluation.csv',index=False)
Loading

0 comments on commit 23c7e31

Please sign in to comment.