Datasets:
Tasks:
Token Classification
Modalities:
Text
Formats:
parquet
Sub-tasks:
named-entity-recognition
Languages:
English
Size:
1K<n<10K
Tags:
License:
File size: 1,066 Bytes
74d8708 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
from datasets import load_metric
from ast import literal_eval
def compute_seqeval(references_dataset, predictions_dataset, ref_col='ner_tags', pred_col='pred_ner_tags'):
# computes the seqeval scores
# sort by id
references_dataset = references_dataset.sort('unique_id')
predictions_dataset = predictions_dataset.sort('unique_id')
# load the huggingface metric function
seqeval = load_metric('seqeval')
# check that tokens match
assert(references_dataset['tokens']==predictions_dataset['tokens'])
# ensure IOB2?
# compute scores
seqeval_results = seqeval.compute(predictions = predictions_dataset[pred_col],
references = references_dataset[ref_col],
scheme = 'IOB2',
suffix = False,
)
# change all values to regular (not numpy) floats (otherwise cannot be serialized to json)
seqeval_results = literal_eval(str(seqeval_results))
return(seqeval_results)
|