Spaces:
Paused
Paused
Update Space (evaluate main: 828c6327)
Browse filesFiles changed (4)
- README.md+141-4
- app.pyAdded+6
- requirements.txtAdded+4
- seqeval.pyAdded+164
123456789101112---title: Seqevalemoji: 🐠colorFrom: pinkcolorTo: redsdk: gradiosdk_version: 3.0.2app_file: app.pypinned: false---Check out the configuration reference at https://huggingface.co/docs/hub/spaces#reference123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149---title: seqevalemoji: 🤗colorFrom: bluecolorTo: redsdk: gradiosdk_version: 3.0.2app_file: app.pypinned: falsetags:- evaluate- metric---# Metric Card for seqeval## Metric descriptionseqeval is a Python framework for sequence labeling evaluation. seqeval can evaluate the performance of chunking tasks such as named-entity recognition, part-of-speech tagging, semantic role labeling and so on.## How to useSeqeval produces labelling scores along with its sufficient statistics from a source against one or more references.It takes two mandatory arguments:`predictions`: a list of lists of predicted labels, i.e. estimated targets as returned by a tagger.`references`: a list of lists of reference labels, i.e. the ground truth/target values.It can also take several optional arguments:`suffix` (boolean): `True` if the IOB tag is a suffix (after type) instead of a prefix (before type), `False` otherwise. The default value is `False`, i.e. the IOB tag is a prefix (before type).`scheme`: the target tagging scheme, which can be one of [`IOB1`, `IOB2`, `IOE1`, `IOE2`, `IOBES`, `BILOU`]. The default value is `None`.`mode`: whether to count correct entity labels with incorrect I/B tags as true positives or not. If you want to only count exact matches, pass `mode="strict"` and a specific `scheme` value. The default is `None`.`sample_weight`: An array-like of shape (n_samples,) that provides weights for individual samples. The default is `None`.`zero_division`: Which value to substitute as a metric value when encountering zero division. Should be one of [`0`,`1`,`"warn"`]. `"warn"` acts as `0`, but the warning is raised.```python>>> seqeval = evaluate.load('seqeval')>>> predictions = [['O', 'O', 'B-MISC', 'I-MISC', 'I-MISC', 'I-MISC', 'O'], ['B-PER', 'I-PER', 'O']]>>> references = [['O', 'O', 'O', 'B-MISC', 'I-MISC', 'I-MISC', 'O'], ['B-PER', 'I-PER', 'O']]>>> results = seqeval.compute(predictions=predictions, references=references)```## Output valuesThis metric returns a dictionary with a summary of scores for overall and per type:Overall:`accuracy`: the average [accuracy](https://huggingface.co/metrics/accuracy), on a scale between 0.0 and 1.0.`precision`: the average [precision](https://huggingface.co/metrics/precision), on a scale between 0.0 and 1.0.`recall`: the average [recall](https://huggingface.co/metrics/recall), on a scale between 0.0 and 1.0.`f1`: the average [F1 score](https://huggingface.co/metrics/f1), which is the harmonic mean of the precision and recall. It also has a scale of 0.0 to 1.0.Per type (e.g. `MISC`, `PER`, `LOC`,...):`precision`: the average [precision](https://huggingface.co/metrics/precision), on a scale between 0.0 and 1.0.`recall`: the average [recall](https://huggingface.co/metrics/recall), on a scale between 0.0 and 1.0.`f1`: the average [F1 score](https://huggingface.co/metrics/f1), on a scale between 0.0 and 1.0.### Values from popular papersThe 1995 "Text Chunking using Transformation-Based Learning" [paper](https://aclanthology.org/W95-0107) reported a baseline recall of 81.9% and a precision of 78.2% using non Deep Learning-based methods.More recently, seqeval continues being used for reporting performance on tasks such as [named entity detection](https://www.mdpi.com/2306-5729/6/8/84/htm) and [information extraction](https://ieeexplore.ieee.org/abstract/document/9697942/).## ExamplesMaximal values (full match) :```python>>> seqeval = evaluate.load('seqeval')>>> predictions = [['O', 'O', 'B-MISC', 'I-MISC', 'I-MISC', 'I-MISC', 'O'], ['B-PER', 'I-PER', 'O']]>>> references = [['O', 'O', 'B-MISC', 'I-MISC', 'I-MISC', 'I-MISC', 'O'], ['B-PER', 'I-PER', 'O']]>>> results = seqeval.compute(predictions=predictions, references=references)>>> print(results){'MISC': {'precision': 1.0, 'recall': 1.0, 'f1': 1.0, 'number': 1}, 'PER': {'precision': 1.0, 'recall': 1.0, 'f1': 1.0, 'number': 1}, 'overall_precision': 1.0, 'overall_recall': 1.0, 'overall_f1': 1.0, 'overall_accuracy': 1.0}```Minimal values (no match):```python>>> seqeval = evaluate.load('seqeval')>>> predictions = [['O', 'B-MISC', 'I-MISC'], ['B-PER', 'I-PER', 'O']]>>> references = [['B-MISC', 'O', 'O'], ['I-PER', '0', 'I-PER']]>>> results = seqeval.compute(predictions=predictions, references=references)>>> print(results){'MISC': {'precision': 0.0, 'recall': 0.0, 'f1': 0.0, 'number': 1}, 'PER': {'precision': 0.0, 'recall': 0.0, 'f1': 0.0, 'number': 2}, '_': {'precision': 0.0, 'recall': 0.0, 'f1': 0.0, 'number': 1}, 'overall_precision': 0.0, 'overall_recall': 0.0, 'overall_f1': 0.0, 'overall_accuracy': 0.0}```Partial match:```python>>> seqeval = evaluate.load('seqeval')>>> predictions = [['O', 'O', 'B-MISC', 'I-MISC', 'I-MISC', 'I-MISC', 'O'], ['B-PER', 'I-PER', 'O']]>>> references = [['O', 'O', 'O', 'B-MISC', 'I-MISC', 'I-MISC', 'O'], ['B-PER', 'I-PER', 'O']]>>> results = seqeval.compute(predictions=predictions, references=references)>>> print(results){'MISC': {'precision': 0.0, 'recall': 0.0, 'f1': 0.0, 'number': 1}, 'PER': {'precision': 1.0, 'recall': 1.0, 'f1': 1.0, 'number': 1}, 'overall_precision': 0.5, 'overall_recall': 0.5, 'overall_f1': 0.5, 'overall_accuracy': 0.8}```## Limitations and biasseqeval supports following IOB formats (short for inside, outside, beginning) : `IOB1`, `IOB2`, `IOE1`, `IOE2`, `IOBES`, `IOBES` (only in strict mode) and `BILOU` (only in strict mode).For more information about IOB formats, refer to the [Wikipedia page](https://en.wikipedia.org/wiki/Inside%E2%80%93outside%E2%80%93beginning_(tagging)) and the description of the [CoNLL-2000 shared task](https://aclanthology.org/W02-2024).## Citation```bibtex@inproceedings{ramshaw-marcus-1995-text,title = "Text Chunking using Transformation-Based Learning",author = "Ramshaw, Lance andMarcus, Mitch",booktitle = "Third Workshop on Very Large Corpora",year = "1995",url = "https://www.aclweb.org/anthology/W95-0107",}``````bibtex@misc{seqeval,title={{seqeval}: A Python framework for sequence labeling evaluation},url={https://github.com/chakki-works/seqeval},note={Software available from https://github.com/chakki-works/seqeval},author={Hiroki Nakayama},year={2018},}```## Further References- [README for seqeval at GitHub](https://github.com/chakki-works/seqeval)- [CoNLL-2000 shared task](https://www.clips.uantwerpen.be/conll2002/ner/bin/conlleval.txt)
123456import evaluatefrom evaluate.utils import launch_gradio_widget
module = evaluate.load("seqeval")launch_gradio_widget(module)1234# TODO: fix github to releasegit+https://github.com/huggingface/evaluate.git@b6e6ed7f3e6844b297bff1b43a1b4be0709b9671datasets~=2.0seqeval123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164# Copyright 2020 The HuggingFace Evaluate Authors.## Licensed under the Apache License, Version 2.0 (the "License");# you may not use this file except in compliance with the License.# You may obtain a copy of the License at## http://www.apache.org/licenses/LICENSE-2.0## Unless required by applicable law or agreed to in writing, software# distributed under the License is distributed on an "AS IS" BASIS,# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.# See the License for the specific language governing permissions and# limitations under the License.""" seqeval metric. """
import importlibfrom typing import List, Optional, Union
import datasetsfrom seqeval.metrics import accuracy_score, classification_report
import evaluate
_CITATION = """\@inproceedings{ramshaw-marcus-1995-text, title = "Text Chunking using Transformation-Based Learning", author = "Ramshaw, Lance and Marcus, Mitch", booktitle = "Third Workshop on Very Large Corpora", year = "1995", url = "https://www.aclweb.org/anthology/W95-0107",}@misc{seqeval, title={{seqeval}: A Python framework for sequence labeling evaluation}, url={https://github.com/chakki-works/seqeval}, note={Software available from https://github.com/chakki-works/seqeval}, author={Hiroki Nakayama}, year={2018},}"""
_DESCRIPTION = """\seqeval is a Python framework for sequence labeling evaluation.seqeval can evaluate the performance of chunking tasks such as named-entity recognition, part-of-speech tagging, semantic role labeling and so on.
This is well-tested by using the Perl script conlleval, which can be used formeasuring the performance of a system that has processed the CoNLL-2000 shared task data.
seqeval supports following formats:IOB1IOB2IOE1IOE2IOBES
See the [README.md] file at https://github.com/chakki-works/seqeval for more information."""
_KWARGS_DESCRIPTION = """Produces labelling scores along with its sufficient statisticsfrom a source against one or more references.
Args: predictions: List of List of predicted labels (Estimated targets as returned by a tagger) references: List of List of reference labels (Ground truth (correct) target values) suffix: True if the IOB prefix is after type, False otherwise. default: False scheme: Specify target tagging scheme. Should be one of ["IOB1", "IOB2", "IOE1", "IOE2", "IOBES", "BILOU"]. default: None mode: Whether to count correct entity labels with incorrect I/B tags as true positives or not. If you want to only count exact matches, pass mode="strict". default: None. sample_weight: Array-like of shape (n_samples,), weights for individual samples. default: None zero_division: Which value to substitute as a metric value when encountering zero division. Should be on of 0, 1, "warn". "warn" acts as 0, but the warning is raised.
Returns: 'scores': dict. Summary of the scores for overall and per type Overall: 'accuracy': accuracy, 'precision': precision, 'recall': recall, 'f1': F1 score, also known as balanced F-score or F-measure, Per type: 'precision': precision, 'recall': recall, 'f1': F1 score, also known as balanced F-score or F-measureExamples:
>>> predictions = [['O', 'O', 'B-MISC', 'I-MISC', 'I-MISC', 'I-MISC', 'O'], ['B-PER', 'I-PER', 'O']] >>> references = [['O', 'O', 'O', 'B-MISC', 'I-MISC', 'I-MISC', 'O'], ['B-PER', 'I-PER', 'O']] >>> seqeval = evaluate.load("seqeval") >>> results = seqeval.compute(predictions=predictions, references=references) >>> print(list(results.keys())) ['MISC', 'PER', 'overall_precision', 'overall_recall', 'overall_f1', 'overall_accuracy'] >>> print(results["overall_f1"]) 0.5 >>> print(results["PER"]["f1"]) 1.0"""
@evaluate.utils.file_utils.add_start_docstrings(_DESCRIPTION, _KWARGS_DESCRIPTION)class Seqeval(evaluate.EvaluationModule): def _info(self): return evaluate.EvaluationModuleInfo( description=_DESCRIPTION, citation=_CITATION, homepage="https://github.com/chakki-works/seqeval", inputs_description=_KWARGS_DESCRIPTION, features=datasets.Features( { "predictions": datasets.Sequence(datasets.Value("string", id="label"), id="sequence"), "references": datasets.Sequence(datasets.Value("string", id="label"), id="sequence"), } ), codebase_urls=["https://github.com/chakki-works/seqeval"], reference_urls=["https://github.com/chakki-works/seqeval"], )
def _compute( self, predictions, references, suffix: bool = False, scheme: Optional[str] = None, mode: Optional[str] = None, sample_weight: Optional[List[int]] = None, zero_division: Union[str, int] = "warn", ): if scheme is not None: try: scheme_module = importlib.import_module("seqeval.scheme") scheme = getattr(scheme_module, scheme) except AttributeError: raise ValueError(f"Scheme should be one of [IOB1, IOB2, IOE1, IOE2, IOBES, BILOU], got {scheme}") report = classification_report( y_true=references, y_pred=predictions, suffix=suffix, output_dict=True, scheme=scheme, mode=mode, sample_weight=sample_weight, zero_division=zero_division, ) report.pop("macro avg") report.pop("weighted avg") overall_score = report.pop("micro avg")
scores = { type_name: { "precision": score["precision"], "recall": score["recall"], "f1": score["f1-score"], "number": score["support"], } for type_name, score in report.items() } scores["overall_precision"] = overall_score["precision"] scores["overall_recall"] = overall_score["recall"] scores["overall_f1"] = overall_score["f1-score"] scores["overall_accuracy"] = accuracy_score(y_true=references, y_pred=predictions)
return scoresREADME.md+141-4
app.pyAdded+6
requirements.txtAdded+4
seqeval.pyAdded+164