jogonba2 commited on
Commit
7004eb5
·
1 Parent(s): 3445e81

readme and gpu

Browse files
Files changed (2) hide show
  1. generation_evaluator.py +15 -31
  2. gradio_tst.py +1 -2
generation_evaluator.py CHANGED
@@ -2,6 +2,7 @@ import datasets
2
  import evaluate
3
  import numpy as np
4
  import spacy
 
5
  from alignscore import AlignScore
6
 
7
  _CITATION = """\
@@ -53,38 +54,19 @@ _CITATION = """\
53
  """
54
 
55
  _DESCRIPTION = """\
56
- ROUGE, or Recall-Oriented Understudy for Gisting Evaluation, is a set of metrics and a software package used for
57
- evaluating automatic summarization and machine translation software in natural language processing.
58
- The metrics compare an automatically produced summary or translation against a reference or a set of references (human-produced) summary or translation.
59
 
60
- Note that ROUGE is case insensitive, meaning that upper case letters are treated the same way as lower case letters.
61
 
62
- This metrics is a wrapper around Google Research reimplementation of ROUGE:
63
- https://github.com/google-research/google-research/tree/master/rouge
64
 
65
- BLEU (Bilingual Evaluation Understudy) is an algorithm for evaluating the quality of text which has been machine-translated from one natural language to another.
66
- Quality is considered to be the correspondence between a machine's output and that of a human: "the closer a machine translation is to a professional human translation, the better it is"
67
- this is the central idea behind BLEU. BLEU was one of the first metrics to claim a high correlation with human judgements of quality, and remains one of the most popular automated and inexpensive metrics.
68
 
69
- Scores are calculated for individual translated segments—generally sentencesby comparing them with a set of good quality reference translations.
70
- Those scores are then averaged over the whole corpus to reach an estimate of the translation's overall quality.
71
- Neither intelligibility nor grammatical correctness are not taken into account.
72
 
73
- EXACT MATCH: Returns the rate at which the input predicted strings exactly match their references, ignoring any strings input as part of the regexes_to_ignore list.
74
 
75
- BERTScore leverages the pre-trained contextual embeddings from BERT and matches words in candidate and reference
76
- sentences by cosine similarity.
77
- It has been shown to correlate with human judgment on sentence-level and system-level evaluation.
78
- Moreover, BERTScore computes precision, recall, and F1 measure, which can be useful for evaluating different language
79
- generation tasks.
80
- See the project's README at https://github.com/Tiiiger/bert_score#readme for more information.
81
-
82
- AlignScore evaluates whether all the information in b is contained in a (b does not contradict a).
83
- See https://github.com/yuh-zha/AlignScore for more information.
84
-
85
- ChrF and ChrF++ are two MT evaluation metrics. They both use the F-score statistic for character n-gram matches,
86
- and ChrF++ adds word n-grams as well which correlates more strongly with direct assessment. We use the implementation
87
- that is already present in sacrebleu.
88
  """
89
 
90
  _KWARGS_DESCRIPTION = """
@@ -120,7 +102,7 @@ BERT_SCORE:{
120
  "hashcode": Hashcode of the library.
121
  },
122
  AlignScore:{
123
- "score": mean align scores using roberta-base as scorer
124
  },
125
  CHRF:{
126
  'score' (float): The chrF (chrF++) score,
@@ -131,10 +113,9 @@ CHRF:{
131
  """
132
 
133
  ALIGNSCORE_ARGS = {
134
- "model": "roberta-base",
135
  "batch_size": 32,
136
- "device": "cuda",
137
- "ckpt_path": "https://huggingface.co/yzha/AlignScore/resolve/main/AlignScore-base.ckpt",
138
  "evaluation_mode": "nli_sp",
139
  }
140
 
@@ -167,9 +148,12 @@ class GenerationEvaluator(evaluate.Metric):
167
  except OSError:
168
  spacy.cli.download("en_core_web_sm")
169
 
170
- # Download AlignScore checkpoint
171
  model_path = dl_manager.download(ALIGNSCORE_ARGS["ckpt_path"])
172
  ALIGNSCORE_ARGS["ckpt_path"] = model_path
 
 
 
173
  self.align_scorer = AlignScore(**ALIGNSCORE_ARGS)
174
 
175
  def _compute(self, predictions, references):
 
2
  import evaluate
3
  import numpy as np
4
  import spacy
5
+ import torch
6
  from alignscore import AlignScore
7
 
8
  _CITATION = """\
 
54
  """
55
 
56
  _DESCRIPTION = """\
57
+ This evaluator computes multiple metrics to assess the quality of generated text. These metrics are the following:
 
 
58
 
59
+ - **ROUGE**: a set of metrics and a software package used for evaluating automatic summarization and machine translation software in natural language processing. The metrics compare an automatically produced summary or translation against a reference or a set of references (human-produced) summary or translation. Note that ROUGE is case insensitive, meaning that upper case letters are treated the same way as lower case letters. This metrics is a wrapper around Google Research reimplementation of ROUGE: https://github.com/google-research/google-research/tree/master/rouge
60
 
61
+ - **BLEU**: evaluates the quality of text which has been machine-translated from one natural language to another. Quality is considered to be the correspondence between a machine's output and that of a human: "the closer a machine translation is to a professional human translation, the better it is" this is the central idea behind BLEU. BLEU was one of the first metrics to claim a high correlation with human judgements of quality, and remains one of the most popular automated and inexpensive metrics. Scores are calculated for individual translated segments—generally sentences—by comparing them with a set of good quality reference translations. Those scores are then averaged over the whole corpus to reach an estimate of the translation's overall quality. Neither intelligibility nor grammatical correctness are not taken into account.
 
62
 
63
+ - **Exact Match**: rate at which the input predicted strings exactly match their references, ignoring any strings input as part of the regexes_to_ignore list.
 
 
64
 
65
+ - **BERTScore**: leverages the pre-trained contextual embeddings from BERT and matches words in candidate and reference sentences by cosine similarity. It has been shown to correlate with human judgment on sentence-level and system-level evaluation. Moreover, BERTScore computes precision, recall, and F1 measure, which can be useful for evaluating different language generation tasks. See the project's README at https://github.com/Tiiiger/bert_score#readme for more information.
 
 
66
 
67
+ - **AlignScore**: evaluates whether all the information in a piece of text *b* is contained in another piece of text *a* and *b* does not contradict *a*, by leveraging an information alignment function learnt through RoBERTa models. See https://github.com/yuh-zha/AlignScore for more information.
68
 
69
+ - **ChrF and ChrF++**: are two MT evaluation metrics. They both use the F-score statistic for character n-gram matches, and ChrF++ adds word n-grams as well which correlates more strongly with direct assessment. We use the implementation that is already present in sacrebleu.
 
 
 
 
 
 
 
 
 
 
 
 
70
  """
71
 
72
  _KWARGS_DESCRIPTION = """
 
102
  "hashcode": Hashcode of the library.
103
  },
104
  AlignScore:{
105
+ "score": mean align-scores using roberta-large as scorer
106
  },
107
  CHRF:{
108
  'score' (float): The chrF (chrF++) score,
 
113
  """
114
 
115
  ALIGNSCORE_ARGS = {
116
+ "model": "roberta-large",
117
  "batch_size": 32,
118
+ "ckpt_path": "https://huggingface.co/yzha/AlignScore/resolve/main/AlignScore-large.ckpt",
 
119
  "evaluation_mode": "nli_sp",
120
  }
121
 
 
148
  except OSError:
149
  spacy.cli.download("en_core_web_sm")
150
 
151
+ # Download AlignScore model and move to GPU if possible
152
  model_path = dl_manager.download(ALIGNSCORE_ARGS["ckpt_path"])
153
  ALIGNSCORE_ARGS["ckpt_path"] = model_path
154
+ ALIGNSCORE_ARGS["device"] = (
155
+ "cuda:0" if torch.cuda.is_available() else "cpu"
156
+ )
157
  self.align_scorer = AlignScore(**ALIGNSCORE_ARGS)
158
 
159
  def _compute(self, predictions, references):
gradio_tst.py CHANGED
@@ -128,8 +128,7 @@ def launch_gradio_widget2(metric):
128
  outputs=gr.Textbox(label=metric.name),
129
  description=(
130
  metric.info.description
131
- + "\nIf this is a text-based metric, make sure to wrap you input in double quotes."
132
- " Alternatively you can use a JSON-formatted list as input."
133
  ),
134
  title=f"Metric: {metric.name}",
135
  article=parse_readme(local_path / "README.md"),
 
128
  outputs=gr.Textbox(label=metric.name),
129
  description=(
130
  metric.info.description
131
+ + "\nThis is a text-based metric, so make sure to wrap you input in double quotes."
 
132
  ),
133
  title=f"Metric: {metric.name}",
134
  article=parse_readme(local_path / "README.md"),