Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace seqeval code with original classification_report for simplicity #738

Merged
merged 2 commits into from
Oct 19, 2020
Merged

Replace seqeval code with original classification_report for simplicity #738

merged 2 commits into from
Oct 19, 2020

Conversation

Hironsan
Copy link
Contributor

@Hironsan Hironsan commented Oct 16, 2020

Recently, the original seqeval has enabled us to get per type scores and overall scores as a dictionary.

This PR replaces the current code with the original function(classification_report) to simplify it.

Also, the original code has been updated to fix #352.

from datasets import load_metric
metric = load_metric("seqeval")
y_true = [['O', 'O', 'O', 'B-MISC', 'I-MISC', 'I-MISC', 'O'], ['B-PER', 'I-PER', 'O']]
y_pred = [['O', 'O', 'B-MISC', 'I-MISC', 'I-MISC', 'I-MISC', 'O'], ['B-PER', 'I-PER', 'O']]
metric.compute(predictions=y_pred, references=y_true)
# Output: {'MISC': {'precision': 0.0, 'recall': 0.0, 'f1': 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}

Copy link
Member

@thomwolf thomwolf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

Copy link
Member

@lhoestq lhoestq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's awesome thank you :)

Could you update the docstring before we merge the PR ?

metrics/seqeval/seqeval.py Show resolved Hide resolved
Copy link
Member

@lhoestq lhoestq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you !

@lhoestq lhoestq merged commit 2bbdfef into huggingface:master Oct 19, 2020
@Hironsan Hironsan deleted the fix-seqeval-in-metrics branch October 19, 2020 10:35
@Tomas0413
Copy link

Hello,

I ran https://github.com/huggingface/transformers/blob/master/examples/token-classification/run.sh

And received this error:

100%|██████████| 407/407 [21:37<00:00,  3.44s/it]Traceback (most recent call last):
  File "run_ner.py", line 445, in <module>
    main()
  File "run_ner.py", line 398, in main
    results = trainer.evaluate()
  File "/data/2021/transformers/src/transformers/trainer.py", line 1470, in evaluate
    metric_key_prefix=metric_key_prefix,
  File "/data/2021/transformers/src/transformers/trainer.py", line 1622, in prediction_loop
    metrics = self.compute_metrics(EvalPrediction(predictions=preds, label_ids=label_ids))
  File "run_ner.py", line 345, in compute_metrics
    results = metric.compute(predictions=true_predictions, references=true_labels)
  File "/usr/local/lib/python3.6/dist-packages/datasets/metric.py", line 398, in compute
    output = self._compute(predictions=predictions, references=references, **kwargs)
  File "/root/.cache/huggingface/modules/datasets_modules/metrics/seqeval/81eda1ff004361d4fa48754a446ec69bb7aa9cf4d14c7215f407d1475941c5ff/seqeval.py", line 97, in _compute
    report = classification_report(y_true=references, y_pred=predictions, suffix=suffix, output_dict=True)
TypeError: classification_report() got an unexpected keyword argument 'output_dict'

I'm still trying multiple things to see if I can work around this, but I thought it might be useful to mention it here.

Name: transformers
Version: 4.3.0.dev0

Name: datasets
Version: 1.2.1

@lhoestq
Copy link
Member

lhoestq commented Jan 20, 2021

Hi, can you try to update your local installation of seqeval ?

pip install --upgrade seqeval

@Tomas0413
Copy link

@lhoestq thanks for the reply. Indeed it was some issue with my setup. I removed the "transformers" and "datasets" (that I had previously installed from the source code), cleared the cache and installed everything again. It works great now!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants