summaryrefslogtreecommitdiff
path: root/python-jury.spec
blob: d232ca5ac1e49be4ececea73778abc1d4ab19564 (plain)
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
%global _empty_manifest_terminate_build 0
Name:		python-jury
Version:	2.2.3
Release:	1
Summary:	Evaluation toolkit for neural language generation.
License:	MIT
URL:		https://github.com/obss/jury
Source0:	https://mirrors.nju.edu.cn/pypi/web/packages/82/cb/2cc74d1c798d175573becbcf91eebb0e4bc797ea48b6a183360cdf53783f/jury-2.2.3.tar.gz
BuildArch:	noarch

Requires:	python3-click
Requires:	python3-evaluate
Requires:	python3-fire
Requires:	python3-nltk
Requires:	python3-rouge-score
Requires:	python3-scikit-learn
Requires:	python3-tqdm
Requires:	python3-validators
Requires:	python3-black
Requires:	python3-deepdiff
Requires:	python3-flake8
Requires:	python3-isort
Requires:	python3-pytest
Requires:	python3-pytest-cov
Requires:	python3-pytest-timeout
Requires:	python3-sacrebleu
Requires:	python3-bert-score
Requires:	python3-jiwer
Requires:	python3-seqeval
Requires:	python3-sentencepiece
Requires:	python3-unbabel-comet
Requires:	python3-fairseq
Requires:	python3-importlib-metadata
Requires:	python3-numpy
Requires:	python3-numpy
Requires:	python3-sacrebleu
Requires:	python3-bert-score
Requires:	python3-jiwer
Requires:	python3-seqeval
Requires:	python3-sentencepiece
Requires:	python3-unbabel-comet
Requires:	python3-fairseq
Requires:	python3-numpy
Requires:	python3-numpy
Requires:	python3-fairseq
Requires:	python3-numpy
Requires:	python3-numpy

%description
<h1 align="center">Jury</h1>

<p align="center">
<a href="https://pypi.org/project/jury"><img src="https://img.shields.io/pypi/pyversions/jury" alt="Python versions"></a>
<a href="https://pepy.tech/project/jury"><img src="https://pepy.tech/badge/jury" alt="downloads"></a>
<a href="https://pypi.org/project/jury"><img src="https://img.shields.io/pypi/v/jury?color=blue" alt="PyPI version"></a>
<a href="https://github.com/obss/jury/releases/latest"><img alt="Latest Release" src="https://img.shields.io/github/release-date/obss/jury"></a>
<a href="https://colab.research.google.com/github/obss/jury/blob/main/examples/jury_evaluate.ipynb"><img alt="Open in Colab" src="https://colab.research.google.com/assets/colab-badge.svg"></a>
<br>
<a href="https://github.com/obss/jury/actions"><img alt="Build status" src="https://github.com/obss/jury/actions/workflows/ci.yml/badge.svg"></a>
<a href="https://libraries.io/pypi/jury"><img alt="Dependencies" src="https://img.shields.io/librariesio/github/obss/jury"></a>
<a href="https://github.com/psf/black"><img alt="Code style: black" src="https://img.shields.io/badge/code%20style-black-000000.svg"></a>
<a href="https://github.com/obss/jury/blob/main/LICENSE"><img alt="License: MIT" src="https://img.shields.io/pypi/l/jury"></a>
<br>
<a href="https://doi.org/10.5281/zenodo.6109838"><img src="https://zenodo.org/badge/DOI/10.5281/zenodo.6109838.svg" alt="DOI"></a>
</p>

A comprehensive toolkit for evaluating NLP experiments offering various automated metrics. Jury offers a smooth and easy-to-use interface. It uses a more advanced version of [evaluate](https://github.com/huggingface/evaluate/) design for underlying metric computation, so that adding custom metric is easy as extending proper class.

Main advantages that Jury offers are:

- Easy to use for any NLP project.
- Unified structure for computation input across all metrics.
- Calculate many metrics at once.
- Metrics calculations can be handled concurrently to save processing time.
- It seamlessly supports evaluation for multiple predictions/multiple references.

To see more, check the [official Jury blog post](https://medium.com/codable/jury-evaluating-performance-of-nlg-models-730eb9c9999f).

# Available Metrics

The table below shows the current support status for available metrics.

| Metric                                                                        | Jury Support       | HF/evaluate Support |
|-------------------------------------------------------------------------------|--------------------|---------------------|
| Accuracy-Numeric                                                              | :heavy_check_mark: | :white_check_mark:  |
| Accuracy-Text                                                                 | :heavy_check_mark: | :x:                 |
| Bartscore                                                                     | :heavy_check_mark: | :x:                 |
| Bertscore                                                                     | :heavy_check_mark: | :white_check_mark:  |
| Bleu                                                                          | :heavy_check_mark: | :white_check_mark:  |
| Bleurt                                                                        | :heavy_check_mark: | :white_check_mark:  |
| CER                                                                           | :heavy_check_mark: | :white_check_mark:  |
| CHRF                                                                          | :heavy_check_mark: | :white_check_mark:  |
| COMET                                                                         | :heavy_check_mark: | :white_check_mark:  |
| F1-Numeric                                                                    | :heavy_check_mark: | :white_check_mark:  |
| F1-Text                                                                       | :heavy_check_mark: | :x:                 |
| METEOR                                                                        | :heavy_check_mark: | :white_check_mark:  |
| Precision-Numeric                                                             | :heavy_check_mark: | :white_check_mark:  |
| Precision-Text                                                                | :heavy_check_mark: | :x:                 |
| Prism                                                                         | :heavy_check_mark: | :x:                 |
| Recall-Numeric                                                                | :heavy_check_mark: | :white_check_mark:  |
| Recall-Text                                                                   | :heavy_check_mark: | :x:                 |
| ROUGE                                                                         | :heavy_check_mark: | :white_check_mark:  |
| SacreBleu                                                                     | :heavy_check_mark: | :white_check_mark:  |
| Seqeval                                                                       | :heavy_check_mark: | :white_check_mark:  |
| Squad                                                                         | :heavy_check_mark: | :white_check_mark:  |
| TER                                                                           | :heavy_check_mark: | :white_check_mark:  |
| WER                                                                           | :heavy_check_mark: | :white_check_mark:  |
| [Other metrics](https://github.com/huggingface/evaluate/tree/master/metrics)* | :white_check_mark: | :white_check_mark:  |

_*_ Placeholder for the rest of the metrics available in `evaluate` package apart from those which are present in the 
table. 

**Notes**

* The entry :heavy_check_mark: represents that full Jury support is available meaning that all combinations of input 
types (single prediction & single reference, single prediction & multiple references, multiple predictions & multiple 
references) are supported

* The entry :white_check_mark: means that this metric is supported (for Jury through the `evaluate`), so that it 
can (and should) be used just like the `evaluate` metric as instructed in `evaluate` implementation although 
unfortunately full Jury support for those metrics are not yet available.

## Request for a New Metric

For the request of a new metric please [open an issue](https://github.com/obss/jury/issues/new?assignees=&labels=&template=new-metric.md&title=) providing the minimum information. Also, PRs addressing new metric 
supports are welcomed :).

## <div align="center"> Installation </div>

Through pip,

    pip install jury

or build from source,

    git clone https://github.com/obss/jury.git
    cd jury
    python setup.py install

**NOTE:** There may be malfunctions of some metrics depending on `sacrebleu` package on Windows machines which is 
mainly due to the package `pywin32`. For this, we fixed pywin32 version on our setup config for Windows platforms. 
However, if pywin32 causes trouble in your environment we strongly recommend using `conda` manager install the package 
as `conda install pywin32`.

## <div align="center"> Usage </div>

### API Usage

It is only two lines of code to evaluate generated outputs.

```python
from jury import Jury

scorer = Jury()
predictions = [
    ["the cat is on the mat", "There is cat playing on the mat"], 
    ["Look!    a wonderful day."]
]
references = [
    ["the cat is playing on the mat.", "The cat plays on the mat."], 
    ["Today is a wonderful day", "The weather outside is wonderful."]
]
scores = scorer(predictions=predictions, references=references)
```

Specify metrics you want to use on instantiation.

```python
scorer = Jury(metrics=["bleu", "meteor"])
scores = scorer(predictions, references)
```

#### Use of Metrics standalone

You can directly import metrics from `jury.metrics` as classes, and then instantiate and use as desired.

```python
from jury.metrics import Bleu

bleu = Bleu.construct()
score = bleu.compute(predictions=predictions, references=references)
```

The additional parameters can either be specified on `compute()`

```python
from jury.metrics import Bleu

bleu = Bleu.construct()
score = bleu.compute(predictions=predictions, references=references, max_order=4)
```

, or alternatively on instantiation

```python
from jury.metrics import Bleu
bleu = Bleu.construct(compute_kwargs={"max_order": 1})
score = bleu.compute(predictions=predictions, references=references)
```

Note that you can seemlessly access both `jury` and `evaluate` metrics through `jury.load_metric`. 

```python
import jury

bleu = jury.load_metric("bleu")
bleu_1 = jury.load_metric("bleu", resulting_name="bleu_1", compute_kwargs={"max_order": 1})
# metrics not available in `jury` but in `evaluate`
wer = jury.load_metric("competition_math") # It falls back to `evaluate` package with a warning
```

### CLI Usage

You can specify predictions file and references file paths and get the resulting scores. Each line should be paired in both files. You can optionally provide reduce function and an export path for results to be written.

    jury eval --predictions /path/to/predictions.txt --references /path/to/references.txt --reduce_fn max --export /path/to/export.txt

You can also provide prediction folders and reference folders to evaluate multiple experiments. In this set up, however, it is required that the prediction and references files you need to evaluate as a pair have the same file name. These common names are paired together for prediction and reference.

    jury eval --predictions /path/to/predictions_folder --references /path/to/references_folder --reduce_fn max --export /path/to/export.txt

If you want to specify metrics, and do not want to use default, specify it in config file (json) in `metrics` key.

```json
{
  "predictions": "/path/to/predictions.txt",
  "references": "/path/to/references.txt",
  "reduce_fn": "max",
  "metrics": [
    "bleu",
    "meteor"
  ]
}
```

Then, you can call jury eval with `config` argument.

    jury eval --config path/to/config.json

### Custom Metrics

You can use custom metrics with inheriting `jury.metrics.Metric`, you can see current metrics implemented on Jury from [jury/metrics](https://github.com/obss/jury/tree/master/jury/metrics). Jury falls back to `evaluate` implementation of metrics for the ones that are currently not supported by Jury, you can see the metrics available for `evaluate` on [evaluate/metrics](https://github.com/huggingface/evaluate/tree/master/metrics). 

Jury itself uses `evaluate.Metric` as a base class to drive its own base class as `jury.metrics.Metric`. The interface is similar; however, Jury makes the metrics to take a unified input type by handling the inputs for each metrics, and allows supporting several input types as;

- single prediction & single reference
- single prediction & multiple reference
- multiple prediction & multiple reference

As a custom metric both base classes can be used; however, we strongly recommend using `jury.metrics.Metric` as it has several advantages such as supporting computations for the input types above or unifying the type of the input.

```python
from jury.metrics import MetricForTask

class CustomMetric(MetricForTask):
    def _compute_single_pred_single_ref(
        self, predictions, references, reduce_fn = None, **kwargs
    ):
        raise NotImplementedError

    def _compute_single_pred_multi_ref(
        self, predictions, references, reduce_fn = None, **kwargs
    ):
        raise NotImplementedError

    def _compute_multi_pred_multi_ref(
            self, predictions, references, reduce_fn = None, **kwargs
    ):
        raise NotImplementedError
```

For more details, have a look at base metric implementation [jury.metrics.Metric](./jury/metrics/_base.py)

## <div align="center"> Contributing </div>

PRs are welcomed as always :)

### Installation

    git clone https://github.com/obss/jury.git
    cd jury
    pip install -e .[dev]

Also, you need to install the packages which are available through a git source separately with the following command. 
For the folks who are curious about "why?"; a short explaination is that PYPI does not allow indexing a package which 
are directly dependent on non-pypi packages due to security reasons. The file `requirements-dev.txt` includes packages 
which are currently only available through a git source, or they are PYPI packages with no recent release or 
incompatible with Jury, so that they are added as git sources or pointing to specific commits.

    pip install -r requirements-dev.txt

### Tests

To tests simply run.

    python tests/run_tests.py

### Code Style

To check code style,

    python tests/run_code_style.py check

To format codebase,

    python tests/run_code_style.py format


## <div align="center"> Citation </div>

If you use this package in your work, please cite it as:

    @software{obss2021jury,
      author       = {Cavusoglu, Devrim and Akyon, Fatih Cagatay and Sert, Ulas and Cengiz, Cemil},
      title        = {{Jury: Comprehensive NLP Evaluation toolkit}},
      month        = {feb},
      year         = {2022},
      publisher    = {Zenodo},
      doi          = {10.5281/zenodo.6108229},
      url          = {https://doi.org/10.5281/zenodo.6108229}
    }

## <div align="center"> License </div>

Licensed under the [MIT](LICENSE) License.


%package -n python3-jury
Summary:	Evaluation toolkit for neural language generation.
Provides:	python-jury
BuildRequires:	python3-devel
BuildRequires:	python3-setuptools
BuildRequires:	python3-pip
%description -n python3-jury
<h1 align="center">Jury</h1>

<p align="center">
<a href="https://pypi.org/project/jury"><img src="https://img.shields.io/pypi/pyversions/jury" alt="Python versions"></a>
<a href="https://pepy.tech/project/jury"><img src="https://pepy.tech/badge/jury" alt="downloads"></a>
<a href="https://pypi.org/project/jury"><img src="https://img.shields.io/pypi/v/jury?color=blue" alt="PyPI version"></a>
<a href="https://github.com/obss/jury/releases/latest"><img alt="Latest Release" src="https://img.shields.io/github/release-date/obss/jury"></a>
<a href="https://colab.research.google.com/github/obss/jury/blob/main/examples/jury_evaluate.ipynb"><img alt="Open in Colab" src="https://colab.research.google.com/assets/colab-badge.svg"></a>
<br>
<a href="https://github.com/obss/jury/actions"><img alt="Build status" src="https://github.com/obss/jury/actions/workflows/ci.yml/badge.svg"></a>
<a href="https://libraries.io/pypi/jury"><img alt="Dependencies" src="https://img.shields.io/librariesio/github/obss/jury"></a>
<a href="https://github.com/psf/black"><img alt="Code style: black" src="https://img.shields.io/badge/code%20style-black-000000.svg"></a>
<a href="https://github.com/obss/jury/blob/main/LICENSE"><img alt="License: MIT" src="https://img.shields.io/pypi/l/jury"></a>
<br>
<a href="https://doi.org/10.5281/zenodo.6109838"><img src="https://zenodo.org/badge/DOI/10.5281/zenodo.6109838.svg" alt="DOI"></a>
</p>

A comprehensive toolkit for evaluating NLP experiments offering various automated metrics. Jury offers a smooth and easy-to-use interface. It uses a more advanced version of [evaluate](https://github.com/huggingface/evaluate/) design for underlying metric computation, so that adding custom metric is easy as extending proper class.

Main advantages that Jury offers are:

- Easy to use for any NLP project.
- Unified structure for computation input across all metrics.
- Calculate many metrics at once.
- Metrics calculations can be handled concurrently to save processing time.
- It seamlessly supports evaluation for multiple predictions/multiple references.

To see more, check the [official Jury blog post](https://medium.com/codable/jury-evaluating-performance-of-nlg-models-730eb9c9999f).

# Available Metrics

The table below shows the current support status for available metrics.

| Metric                                                                        | Jury Support       | HF/evaluate Support |
|-------------------------------------------------------------------------------|--------------------|---------------------|
| Accuracy-Numeric                                                              | :heavy_check_mark: | :white_check_mark:  |
| Accuracy-Text                                                                 | :heavy_check_mark: | :x:                 |
| Bartscore                                                                     | :heavy_check_mark: | :x:                 |
| Bertscore                                                                     | :heavy_check_mark: | :white_check_mark:  |
| Bleu                                                                          | :heavy_check_mark: | :white_check_mark:  |
| Bleurt                                                                        | :heavy_check_mark: | :white_check_mark:  |
| CER                                                                           | :heavy_check_mark: | :white_check_mark:  |
| CHRF                                                                          | :heavy_check_mark: | :white_check_mark:  |
| COMET                                                                         | :heavy_check_mark: | :white_check_mark:  |
| F1-Numeric                                                                    | :heavy_check_mark: | :white_check_mark:  |
| F1-Text                                                                       | :heavy_check_mark: | :x:                 |
| METEOR                                                                        | :heavy_check_mark: | :white_check_mark:  |
| Precision-Numeric                                                             | :heavy_check_mark: | :white_check_mark:  |
| Precision-Text                                                                | :heavy_check_mark: | :x:                 |
| Prism                                                                         | :heavy_check_mark: | :x:                 |
| Recall-Numeric                                                                | :heavy_check_mark: | :white_check_mark:  |
| Recall-Text                                                                   | :heavy_check_mark: | :x:                 |
| ROUGE                                                                         | :heavy_check_mark: | :white_check_mark:  |
| SacreBleu                                                                     | :heavy_check_mark: | :white_check_mark:  |
| Seqeval                                                                       | :heavy_check_mark: | :white_check_mark:  |
| Squad                                                                         | :heavy_check_mark: | :white_check_mark:  |
| TER                                                                           | :heavy_check_mark: | :white_check_mark:  |
| WER                                                                           | :heavy_check_mark: | :white_check_mark:  |
| [Other metrics](https://github.com/huggingface/evaluate/tree/master/metrics)* | :white_check_mark: | :white_check_mark:  |

_*_ Placeholder for the rest of the metrics available in `evaluate` package apart from those which are present in the 
table. 

**Notes**

* The entry :heavy_check_mark: represents that full Jury support is available meaning that all combinations of input 
types (single prediction & single reference, single prediction & multiple references, multiple predictions & multiple 
references) are supported

* The entry :white_check_mark: means that this metric is supported (for Jury through the `evaluate`), so that it 
can (and should) be used just like the `evaluate` metric as instructed in `evaluate` implementation although 
unfortunately full Jury support for those metrics are not yet available.

## Request for a New Metric

For the request of a new metric please [open an issue](https://github.com/obss/jury/issues/new?assignees=&labels=&template=new-metric.md&title=) providing the minimum information. Also, PRs addressing new metric 
supports are welcomed :).

## <div align="center"> Installation </div>

Through pip,

    pip install jury

or build from source,

    git clone https://github.com/obss/jury.git
    cd jury
    python setup.py install

**NOTE:** There may be malfunctions of some metrics depending on `sacrebleu` package on Windows machines which is 
mainly due to the package `pywin32`. For this, we fixed pywin32 version on our setup config for Windows platforms. 
However, if pywin32 causes trouble in your environment we strongly recommend using `conda` manager install the package 
as `conda install pywin32`.

## <div align="center"> Usage </div>

### API Usage

It is only two lines of code to evaluate generated outputs.

```python
from jury import Jury

scorer = Jury()
predictions = [
    ["the cat is on the mat", "There is cat playing on the mat"], 
    ["Look!    a wonderful day."]
]
references = [
    ["the cat is playing on the mat.", "The cat plays on the mat."], 
    ["Today is a wonderful day", "The weather outside is wonderful."]
]
scores = scorer(predictions=predictions, references=references)
```

Specify metrics you want to use on instantiation.

```python
scorer = Jury(metrics=["bleu", "meteor"])
scores = scorer(predictions, references)
```

#### Use of Metrics standalone

You can directly import metrics from `jury.metrics` as classes, and then instantiate and use as desired.

```python
from jury.metrics import Bleu

bleu = Bleu.construct()
score = bleu.compute(predictions=predictions, references=references)
```

The additional parameters can either be specified on `compute()`

```python
from jury.metrics import Bleu

bleu = Bleu.construct()
score = bleu.compute(predictions=predictions, references=references, max_order=4)
```

, or alternatively on instantiation

```python
from jury.metrics import Bleu
bleu = Bleu.construct(compute_kwargs={"max_order": 1})
score = bleu.compute(predictions=predictions, references=references)
```

Note that you can seemlessly access both `jury` and `evaluate` metrics through `jury.load_metric`. 

```python
import jury

bleu = jury.load_metric("bleu")
bleu_1 = jury.load_metric("bleu", resulting_name="bleu_1", compute_kwargs={"max_order": 1})
# metrics not available in `jury` but in `evaluate`
wer = jury.load_metric("competition_math") # It falls back to `evaluate` package with a warning
```

### CLI Usage

You can specify predictions file and references file paths and get the resulting scores. Each line should be paired in both files. You can optionally provide reduce function and an export path for results to be written.

    jury eval --predictions /path/to/predictions.txt --references /path/to/references.txt --reduce_fn max --export /path/to/export.txt

You can also provide prediction folders and reference folders to evaluate multiple experiments. In this set up, however, it is required that the prediction and references files you need to evaluate as a pair have the same file name. These common names are paired together for prediction and reference.

    jury eval --predictions /path/to/predictions_folder --references /path/to/references_folder --reduce_fn max --export /path/to/export.txt

If you want to specify metrics, and do not want to use default, specify it in config file (json) in `metrics` key.

```json
{
  "predictions": "/path/to/predictions.txt",
  "references": "/path/to/references.txt",
  "reduce_fn": "max",
  "metrics": [
    "bleu",
    "meteor"
  ]
}
```

Then, you can call jury eval with `config` argument.

    jury eval --config path/to/config.json

### Custom Metrics

You can use custom metrics with inheriting `jury.metrics.Metric`, you can see current metrics implemented on Jury from [jury/metrics](https://github.com/obss/jury/tree/master/jury/metrics). Jury falls back to `evaluate` implementation of metrics for the ones that are currently not supported by Jury, you can see the metrics available for `evaluate` on [evaluate/metrics](https://github.com/huggingface/evaluate/tree/master/metrics). 

Jury itself uses `evaluate.Metric` as a base class to drive its own base class as `jury.metrics.Metric`. The interface is similar; however, Jury makes the metrics to take a unified input type by handling the inputs for each metrics, and allows supporting several input types as;

- single prediction & single reference
- single prediction & multiple reference
- multiple prediction & multiple reference

As a custom metric both base classes can be used; however, we strongly recommend using `jury.metrics.Metric` as it has several advantages such as supporting computations for the input types above or unifying the type of the input.

```python
from jury.metrics import MetricForTask

class CustomMetric(MetricForTask):
    def _compute_single_pred_single_ref(
        self, predictions, references, reduce_fn = None, **kwargs
    ):
        raise NotImplementedError

    def _compute_single_pred_multi_ref(
        self, predictions, references, reduce_fn = None, **kwargs
    ):
        raise NotImplementedError

    def _compute_multi_pred_multi_ref(
            self, predictions, references, reduce_fn = None, **kwargs
    ):
        raise NotImplementedError
```

For more details, have a look at base metric implementation [jury.metrics.Metric](./jury/metrics/_base.py)

## <div align="center"> Contributing </div>

PRs are welcomed as always :)

### Installation

    git clone https://github.com/obss/jury.git
    cd jury
    pip install -e .[dev]

Also, you need to install the packages which are available through a git source separately with the following command. 
For the folks who are curious about "why?"; a short explaination is that PYPI does not allow indexing a package which 
are directly dependent on non-pypi packages due to security reasons. The file `requirements-dev.txt` includes packages 
which are currently only available through a git source, or they are PYPI packages with no recent release or 
incompatible with Jury, so that they are added as git sources or pointing to specific commits.

    pip install -r requirements-dev.txt

### Tests

To tests simply run.

    python tests/run_tests.py

### Code Style

To check code style,

    python tests/run_code_style.py check

To format codebase,

    python tests/run_code_style.py format


## <div align="center"> Citation </div>

If you use this package in your work, please cite it as:

    @software{obss2021jury,
      author       = {Cavusoglu, Devrim and Akyon, Fatih Cagatay and Sert, Ulas and Cengiz, Cemil},
      title        = {{Jury: Comprehensive NLP Evaluation toolkit}},
      month        = {feb},
      year         = {2022},
      publisher    = {Zenodo},
      doi          = {10.5281/zenodo.6108229},
      url          = {https://doi.org/10.5281/zenodo.6108229}
    }

## <div align="center"> License </div>

Licensed under the [MIT](LICENSE) License.


%package help
Summary:	Development documents and examples for jury
Provides:	python3-jury-doc
%description help
<h1 align="center">Jury</h1>

<p align="center">
<a href="https://pypi.org/project/jury"><img src="https://img.shields.io/pypi/pyversions/jury" alt="Python versions"></a>
<a href="https://pepy.tech/project/jury"><img src="https://pepy.tech/badge/jury" alt="downloads"></a>
<a href="https://pypi.org/project/jury"><img src="https://img.shields.io/pypi/v/jury?color=blue" alt="PyPI version"></a>
<a href="https://github.com/obss/jury/releases/latest"><img alt="Latest Release" src="https://img.shields.io/github/release-date/obss/jury"></a>
<a href="https://colab.research.google.com/github/obss/jury/blob/main/examples/jury_evaluate.ipynb"><img alt="Open in Colab" src="https://colab.research.google.com/assets/colab-badge.svg"></a>
<br>
<a href="https://github.com/obss/jury/actions"><img alt="Build status" src="https://github.com/obss/jury/actions/workflows/ci.yml/badge.svg"></a>
<a href="https://libraries.io/pypi/jury"><img alt="Dependencies" src="https://img.shields.io/librariesio/github/obss/jury"></a>
<a href="https://github.com/psf/black"><img alt="Code style: black" src="https://img.shields.io/badge/code%20style-black-000000.svg"></a>
<a href="https://github.com/obss/jury/blob/main/LICENSE"><img alt="License: MIT" src="https://img.shields.io/pypi/l/jury"></a>
<br>
<a href="https://doi.org/10.5281/zenodo.6109838"><img src="https://zenodo.org/badge/DOI/10.5281/zenodo.6109838.svg" alt="DOI"></a>
</p>

A comprehensive toolkit for evaluating NLP experiments offering various automated metrics. Jury offers a smooth and easy-to-use interface. It uses a more advanced version of [evaluate](https://github.com/huggingface/evaluate/) design for underlying metric computation, so that adding custom metric is easy as extending proper class.

Main advantages that Jury offers are:

- Easy to use for any NLP project.
- Unified structure for computation input across all metrics.
- Calculate many metrics at once.
- Metrics calculations can be handled concurrently to save processing time.
- It seamlessly supports evaluation for multiple predictions/multiple references.

To see more, check the [official Jury blog post](https://medium.com/codable/jury-evaluating-performance-of-nlg-models-730eb9c9999f).

# Available Metrics

The table below shows the current support status for available metrics.

| Metric                                                                        | Jury Support       | HF/evaluate Support |
|-------------------------------------------------------------------------------|--------------------|---------------------|
| Accuracy-Numeric                                                              | :heavy_check_mark: | :white_check_mark:  |
| Accuracy-Text                                                                 | :heavy_check_mark: | :x:                 |
| Bartscore                                                                     | :heavy_check_mark: | :x:                 |
| Bertscore                                                                     | :heavy_check_mark: | :white_check_mark:  |
| Bleu                                                                          | :heavy_check_mark: | :white_check_mark:  |
| Bleurt                                                                        | :heavy_check_mark: | :white_check_mark:  |
| CER                                                                           | :heavy_check_mark: | :white_check_mark:  |
| CHRF                                                                          | :heavy_check_mark: | :white_check_mark:  |
| COMET                                                                         | :heavy_check_mark: | :white_check_mark:  |
| F1-Numeric                                                                    | :heavy_check_mark: | :white_check_mark:  |
| F1-Text                                                                       | :heavy_check_mark: | :x:                 |
| METEOR                                                                        | :heavy_check_mark: | :white_check_mark:  |
| Precision-Numeric                                                             | :heavy_check_mark: | :white_check_mark:  |
| Precision-Text                                                                | :heavy_check_mark: | :x:                 |
| Prism                                                                         | :heavy_check_mark: | :x:                 |
| Recall-Numeric                                                                | :heavy_check_mark: | :white_check_mark:  |
| Recall-Text                                                                   | :heavy_check_mark: | :x:                 |
| ROUGE                                                                         | :heavy_check_mark: | :white_check_mark:  |
| SacreBleu                                                                     | :heavy_check_mark: | :white_check_mark:  |
| Seqeval                                                                       | :heavy_check_mark: | :white_check_mark:  |
| Squad                                                                         | :heavy_check_mark: | :white_check_mark:  |
| TER                                                                           | :heavy_check_mark: | :white_check_mark:  |
| WER                                                                           | :heavy_check_mark: | :white_check_mark:  |
| [Other metrics](https://github.com/huggingface/evaluate/tree/master/metrics)* | :white_check_mark: | :white_check_mark:  |

_*_ Placeholder for the rest of the metrics available in `evaluate` package apart from those which are present in the 
table. 

**Notes**

* The entry :heavy_check_mark: represents that full Jury support is available meaning that all combinations of input 
types (single prediction & single reference, single prediction & multiple references, multiple predictions & multiple 
references) are supported

* The entry :white_check_mark: means that this metric is supported (for Jury through the `evaluate`), so that it 
can (and should) be used just like the `evaluate` metric as instructed in `evaluate` implementation although 
unfortunately full Jury support for those metrics are not yet available.

## Request for a New Metric

For the request of a new metric please [open an issue](https://github.com/obss/jury/issues/new?assignees=&labels=&template=new-metric.md&title=) providing the minimum information. Also, PRs addressing new metric 
supports are welcomed :).

## <div align="center"> Installation </div>

Through pip,

    pip install jury

or build from source,

    git clone https://github.com/obss/jury.git
    cd jury
    python setup.py install

**NOTE:** There may be malfunctions of some metrics depending on `sacrebleu` package on Windows machines which is 
mainly due to the package `pywin32`. For this, we fixed pywin32 version on our setup config for Windows platforms. 
However, if pywin32 causes trouble in your environment we strongly recommend using `conda` manager install the package 
as `conda install pywin32`.

## <div align="center"> Usage </div>

### API Usage

It is only two lines of code to evaluate generated outputs.

```python
from jury import Jury

scorer = Jury()
predictions = [
    ["the cat is on the mat", "There is cat playing on the mat"], 
    ["Look!    a wonderful day."]
]
references = [
    ["the cat is playing on the mat.", "The cat plays on the mat."], 
    ["Today is a wonderful day", "The weather outside is wonderful."]
]
scores = scorer(predictions=predictions, references=references)
```

Specify metrics you want to use on instantiation.

```python
scorer = Jury(metrics=["bleu", "meteor"])
scores = scorer(predictions, references)
```

#### Use of Metrics standalone

You can directly import metrics from `jury.metrics` as classes, and then instantiate and use as desired.

```python
from jury.metrics import Bleu

bleu = Bleu.construct()
score = bleu.compute(predictions=predictions, references=references)
```

The additional parameters can either be specified on `compute()`

```python
from jury.metrics import Bleu

bleu = Bleu.construct()
score = bleu.compute(predictions=predictions, references=references, max_order=4)
```

, or alternatively on instantiation

```python
from jury.metrics import Bleu
bleu = Bleu.construct(compute_kwargs={"max_order": 1})
score = bleu.compute(predictions=predictions, references=references)
```

Note that you can seemlessly access both `jury` and `evaluate` metrics through `jury.load_metric`. 

```python
import jury

bleu = jury.load_metric("bleu")
bleu_1 = jury.load_metric("bleu", resulting_name="bleu_1", compute_kwargs={"max_order": 1})
# metrics not available in `jury` but in `evaluate`
wer = jury.load_metric("competition_math") # It falls back to `evaluate` package with a warning
```

### CLI Usage

You can specify predictions file and references file paths and get the resulting scores. Each line should be paired in both files. You can optionally provide reduce function and an export path for results to be written.

    jury eval --predictions /path/to/predictions.txt --references /path/to/references.txt --reduce_fn max --export /path/to/export.txt

You can also provide prediction folders and reference folders to evaluate multiple experiments. In this set up, however, it is required that the prediction and references files you need to evaluate as a pair have the same file name. These common names are paired together for prediction and reference.

    jury eval --predictions /path/to/predictions_folder --references /path/to/references_folder --reduce_fn max --export /path/to/export.txt

If you want to specify metrics, and do not want to use default, specify it in config file (json) in `metrics` key.

```json
{
  "predictions": "/path/to/predictions.txt",
  "references": "/path/to/references.txt",
  "reduce_fn": "max",
  "metrics": [
    "bleu",
    "meteor"
  ]
}
```

Then, you can call jury eval with `config` argument.

    jury eval --config path/to/config.json

### Custom Metrics

You can use custom metrics with inheriting `jury.metrics.Metric`, you can see current metrics implemented on Jury from [jury/metrics](https://github.com/obss/jury/tree/master/jury/metrics). Jury falls back to `evaluate` implementation of metrics for the ones that are currently not supported by Jury, you can see the metrics available for `evaluate` on [evaluate/metrics](https://github.com/huggingface/evaluate/tree/master/metrics). 

Jury itself uses `evaluate.Metric` as a base class to drive its own base class as `jury.metrics.Metric`. The interface is similar; however, Jury makes the metrics to take a unified input type by handling the inputs for each metrics, and allows supporting several input types as;

- single prediction & single reference
- single prediction & multiple reference
- multiple prediction & multiple reference

As a custom metric both base classes can be used; however, we strongly recommend using `jury.metrics.Metric` as it has several advantages such as supporting computations for the input types above or unifying the type of the input.

```python
from jury.metrics import MetricForTask

class CustomMetric(MetricForTask):
    def _compute_single_pred_single_ref(
        self, predictions, references, reduce_fn = None, **kwargs
    ):
        raise NotImplementedError

    def _compute_single_pred_multi_ref(
        self, predictions, references, reduce_fn = None, **kwargs
    ):
        raise NotImplementedError

    def _compute_multi_pred_multi_ref(
            self, predictions, references, reduce_fn = None, **kwargs
    ):
        raise NotImplementedError
```

For more details, have a look at base metric implementation [jury.metrics.Metric](./jury/metrics/_base.py)

## <div align="center"> Contributing </div>

PRs are welcomed as always :)

### Installation

    git clone https://github.com/obss/jury.git
    cd jury
    pip install -e .[dev]

Also, you need to install the packages which are available through a git source separately with the following command. 
For the folks who are curious about "why?"; a short explaination is that PYPI does not allow indexing a package which 
are directly dependent on non-pypi packages due to security reasons. The file `requirements-dev.txt` includes packages 
which are currently only available through a git source, or they are PYPI packages with no recent release or 
incompatible with Jury, so that they are added as git sources or pointing to specific commits.

    pip install -r requirements-dev.txt

### Tests

To tests simply run.

    python tests/run_tests.py

### Code Style

To check code style,

    python tests/run_code_style.py check

To format codebase,

    python tests/run_code_style.py format


## <div align="center"> Citation </div>

If you use this package in your work, please cite it as:

    @software{obss2021jury,
      author       = {Cavusoglu, Devrim and Akyon, Fatih Cagatay and Sert, Ulas and Cengiz, Cemil},
      title        = {{Jury: Comprehensive NLP Evaluation toolkit}},
      month        = {feb},
      year         = {2022},
      publisher    = {Zenodo},
      doi          = {10.5281/zenodo.6108229},
      url          = {https://doi.org/10.5281/zenodo.6108229}
    }

## <div align="center"> License </div>

Licensed under the [MIT](LICENSE) License.


%prep
%autosetup -n jury-2.2.3

%build
%py3_build

%install
%py3_install
install -d -m755 %{buildroot}/%{_pkgdocdir}
if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi
if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi
if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi
if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi
pushd %{buildroot}
if [ -d usr/lib ]; then
	find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/lib64 ]; then
	find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/bin ]; then
	find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/sbin ]; then
	find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst
fi
touch doclist.lst
if [ -d usr/share/man ]; then
	find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst
fi
popd
mv %{buildroot}/filelist.lst .
mv %{buildroot}/doclist.lst .

%files -n python3-jury -f filelist.lst
%dir %{python3_sitelib}/*

%files help -f doclist.lst
%{_docdir}/*

%changelog
* Wed May 31 2023 Python_Bot <Python_Bot@openeuler.org> - 2.2.3-1
- Package Spec generated