mpapucci commited on
Commit
d8c7f06
·
verified ·
1 Parent(s): de9ce05

Rename to SIMPLE Score (simple-score)

Browse files
Files changed (5) hide show
  1. README.md +12 -12
  2. demo.js +1 -1
  3. index.html +13 -13
  4. model/manifest.json +1 -1
  5. simple.py → simple-score.py +18 -18
README.md CHANGED
@@ -1,5 +1,5 @@
1
  ---
2
- title: SIMPLE
3
  emoji: 🧩
4
  colorFrom: blue
5
  colorTo: green
@@ -12,15 +12,15 @@ tags:
12
  - metric
13
  - text-simplification
14
  description: >-
15
- SIMPLE: a reference-free learned metric for text simplification that also reports its
16
  own uncertainty.
17
  ---
18
 
19
- # Metric Card for SIMPLE
20
 
21
  ## Metric description
22
 
23
- SIMPLE (SImplicity Metric via Preference LEarning) scores a candidate simplification
24
  against its source sentence, without references. It returns:
25
 
26
  - **score** `mu` in (-1, 1): +1 = highly successful simplification, 0 = verbatim copy of
@@ -29,7 +29,7 @@ against its source sentence, without references. It returns:
29
  - **uncertainty** `sigma` (> 0.05): the model's confidence in that score; lower = more
30
  confident. Predictions with low sigma agree more often with human judgements.
31
 
32
- SIMPLE is a DeBERTa-v3 cross-encoder trained with a Thurstone pairwise preference loss and
33
  calibrated on human quality ratings with a Gaussian likelihood. Three sizes are available.
34
 
35
  This Space's page runs an in-browser demo (SIMPLE-small with 8-bit weights, via ONNX Runtime
@@ -40,20 +40,20 @@ Web); the model is downloaded only when a visitor starts the demo.
40
  ```python
41
  import evaluate
42
 
43
- simple = evaluate.load("mpapucci/simple") # SIMPLE-large (default)
44
- # simple = evaluate.load("mpapucci/simple", "base") # or "small"
45
- out = simple.compute(
46
  sources=["The feline perched upon the mat in a state of repose."],
47
  predictions=["The cat sat on the mat."],
48
  )
49
- print(out["simple"], out["scores"], out["sigmas"])
50
  ```
51
 
52
- This needs `pip install simple-metric`. The package can also be used directly, which avoids
53
  the `evaluate` dependency:
54
 
55
  ```python
56
- from simple_metric import SIMPLE
57
  metric = SIMPLE.from_pretrained("large")
58
  metric.score(sources, predictions)
59
  ```
@@ -66,7 +66,7 @@ metric.score(sources, predictions)
66
 
67
  ### Output values
68
 
69
- - `simple` (float): mean score.
70
  - `scores` (list of float): per-example score `mu`.
71
  - `sigmas` (list of float): per-example uncertainty `sigma`.
72
 
 
1
  ---
2
+ title: SIMPLE Score
3
  emoji: 🧩
4
  colorFrom: blue
5
  colorTo: green
 
12
  - metric
13
  - text-simplification
14
  description: >-
15
+ SIMPLE Score: a reference-free learned metric for text simplification that also reports its
16
  own uncertainty.
17
  ---
18
 
19
+ # Metric Card for SIMPLE Score
20
 
21
  ## Metric description
22
 
23
+ SIMPLE Score (SImplicity Metric via Preference LEarning) scores a candidate simplification
24
  against its source sentence, without references. It returns:
25
 
26
  - **score** `mu` in (-1, 1): +1 = highly successful simplification, 0 = verbatim copy of
 
29
  - **uncertainty** `sigma` (> 0.05): the model's confidence in that score; lower = more
30
  confident. Predictions with low sigma agree more often with human judgements.
31
 
32
+ SIMPLE Score is a DeBERTa-v3 cross-encoder trained with a Thurstone pairwise preference loss and
33
  calibrated on human quality ratings with a Gaussian likelihood. Three sizes are available.
34
 
35
  This Space's page runs an in-browser demo (SIMPLE-small with 8-bit weights, via ONNX Runtime
 
40
  ```python
41
  import evaluate
42
 
43
+ simple_score = evaluate.load("mpapucci/simple-score") # SIMPLE-large (default)
44
+ # simple_score = evaluate.load("mpapucci/simple-score", "base") # or "small"
45
+ out = simple_score.compute(
46
  sources=["The feline perched upon the mat in a state of repose."],
47
  predictions=["The cat sat on the mat."],
48
  )
49
+ print(out["simple_score"], out["scores"], out["sigmas"])
50
  ```
51
 
52
+ This needs `pip install simple-score`. The package can also be used directly, which avoids
53
  the `evaluate` dependency:
54
 
55
  ```python
56
+ from simple_score import SIMPLE
57
  metric = SIMPLE.from_pretrained("large")
58
  metric.score(sources, predictions)
59
  ```
 
66
 
67
  ### Output values
68
 
69
+ - `simple_score` (float): mean score.
70
  - `scores` (list of float): per-example score `mu`.
71
  - `sigmas` (list of float): per-example uncertainty `sigma`.
72
 
demo.js CHANGED
@@ -7,7 +7,7 @@ const TOKENIZERS_VERSION = "0.2.0";
7
  const ORT_BASE = `https://cdn.jsdelivr.net/npm/onnxruntime-web@${ORT_VERSION}/dist/`;
8
  const TOKENIZERS_URL = `https://cdn.jsdelivr.net/npm/@huggingface/tokenizers@${TOKENIZERS_VERSION}/dist/tokenizers.min.mjs`;
9
  const MANIFEST_URL = "model/manifest.json";
10
- const CACHE_PREFIX = "simple-metric-demo-";
11
  const MAX_TOKENS = 512;
12
 
13
  const $ = (id) => document.getElementById(id);
 
7
  const ORT_BASE = `https://cdn.jsdelivr.net/npm/onnxruntime-web@${ORT_VERSION}/dist/`;
8
  const TOKENIZERS_URL = `https://cdn.jsdelivr.net/npm/@huggingface/tokenizers@${TOKENIZERS_VERSION}/dist/tokenizers.min.mjs`;
9
  const MANIFEST_URL = "model/manifest.json";
10
+ const CACHE_PREFIX = "simple-score-demo-";
11
  const MAX_TOKENS = 512;
12
 
13
  const $ = (id) => document.getElementById(id);
index.html CHANGED
@@ -3,9 +3,9 @@
3
  <head>
4
  <meta charset="utf-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1">
6
- <title>SIMPLE metric</title>
7
  <link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Crect width='32' height='32' rx='7' fill='%232457c5'/%3E%3Cpath d='M8 21h16M8 15h11M8 9h16' stroke='white' stroke-width='3' stroke-linecap='round'/%3E%3C/svg%3E">
8
- <meta name="description" content="SIMPLE: a reference-free metric for sentence simplification that also reports its own uncertainty. Try it in your browser.">
9
  <script>
10
  // Apply the saved theme before the page is drawn (no flash of the wrong theme).
11
  try {
@@ -146,7 +146,7 @@
146
  <main>
147
  <header>
148
  <div class="top">
149
- <h1>SIMPLE</h1>
150
  <div class="theme" role="group" aria-label="Colour theme">
151
  <button type="button" data-theme-choice="auto">Auto</button>
152
  <button type="button" data-theme-choice="light">Light</button>
@@ -159,7 +159,7 @@
159
 
160
  <section aria-labelledby="read-title">
161
  <h2 id="read-title">Reading the score</h2>
162
- <p>SIMPLE returns a score <strong>μ</strong> between −1 and +1 for each (source, simplification) pair:</p>
163
  <div class="scale" aria-hidden="true"></div>
164
  <div class="scale-labels"><span>−1 unrelated, degenerate text or complexification</span><span>0 copy of the source</span><span>+1 successful simplification</span></div>
165
  <p class="small muted" style="margin-top:12px">Negative scores flag unsuccessful simplifications, including
@@ -223,8 +223,8 @@
223
 
224
  <section aria-labelledby="use-title">
225
  <h2 id="use-title">Use it in Python</h2>
226
- <pre><code>pip install simple-metric</code></pre>
227
- <pre><code>from simple_metric import SIMPLE
228
 
229
  metric = SIMPLE.from_pretrained("large") # or "small", "base"
230
  out = metric.score(sources, simplifications)
@@ -232,16 +232,16 @@ out.mu, out.sigma, out.mean</code></pre>
232
  <p>With 🤗 Evaluate:</p>
233
  <pre><code>import evaluate
234
 
235
- simple = evaluate.load("mpapucci/simple", "large")
236
- simple.compute(sources=sources, predictions=simplifications)</code></pre>
237
- <p class="small muted">Models: <a href="https://huggingface.co/mpapucci/simple-metric-small" target="_blank" rel="noopener noreferrer">small</a>,
238
- <a href="https://huggingface.co/mpapucci/simple-metric-base" target="_blank" rel="noopener noreferrer">base</a>,
239
- <a href="https://huggingface.co/mpapucci/simple-metric-large" target="_blank" rel="noopener noreferrer">large</a>.
240
- Code and training: <a href="https://github.com/michelepapucci/simple-metric" target="_blank" rel="noopener noreferrer">github.com/michelepapucci/simple-metric</a>.
241
  Paper: <em>Rethinking Text Simplification Evaluation as Preference Learning</em> (link coming soon).</p>
242
  </section>
243
 
244
- <footer>SIMPLE · MIT License ·
245
  <a href="http://www.italianlp.it/" target="_blank" rel="noopener noreferrer">ItaliaNLP Lab @ CNR-ILC</a> ·
246
  <a href="https://michelepapucci.github.io/" target="_blank" rel="noopener noreferrer">Michele Papucci</a></footer>
247
  </main>
 
3
  <head>
4
  <meta charset="utf-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1">
6
+ <title>SIMPLE Score</title>
7
  <link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Crect width='32' height='32' rx='7' fill='%232457c5'/%3E%3Cpath d='M8 21h16M8 15h11M8 9h16' stroke='white' stroke-width='3' stroke-linecap='round'/%3E%3C/svg%3E">
8
+ <meta name="description" content="SIMPLE Score: a reference-free metric for sentence simplification that also reports its own uncertainty. Try it in your browser.">
9
  <script>
10
  // Apply the saved theme before the page is drawn (no flash of the wrong theme).
11
  try {
 
146
  <main>
147
  <header>
148
  <div class="top">
149
+ <h1>SIMPLE Score</h1>
150
  <div class="theme" role="group" aria-label="Colour theme">
151
  <button type="button" data-theme-choice="auto">Auto</button>
152
  <button type="button" data-theme-choice="light">Light</button>
 
159
 
160
  <section aria-labelledby="read-title">
161
  <h2 id="read-title">Reading the score</h2>
162
+ <p>SIMPLE Score returns a score <strong>μ</strong> between −1 and +1 for each (source, simplification) pair:</p>
163
  <div class="scale" aria-hidden="true"></div>
164
  <div class="scale-labels"><span>−1 unrelated, degenerate text or complexification</span><span>0 copy of the source</span><span>+1 successful simplification</span></div>
165
  <p class="small muted" style="margin-top:12px">Negative scores flag unsuccessful simplifications, including
 
223
 
224
  <section aria-labelledby="use-title">
225
  <h2 id="use-title">Use it in Python</h2>
226
+ <pre><code>pip install simple-score</code></pre>
227
+ <pre><code>from simple_score import SIMPLE
228
 
229
  metric = SIMPLE.from_pretrained("large") # or "small", "base"
230
  out = metric.score(sources, simplifications)
 
232
  <p>With 🤗 Evaluate:</p>
233
  <pre><code>import evaluate
234
 
235
+ simple_score = evaluate.load("mpapucci/simple-score", "large")
236
+ simple_score.compute(sources=sources, predictions=simplifications)</code></pre>
237
+ <p class="small muted">Models: <a href="https://huggingface.co/mpapucci/simple-score-small" target="_blank" rel="noopener noreferrer">small</a>,
238
+ <a href="https://huggingface.co/mpapucci/simple-score-base" target="_blank" rel="noopener noreferrer">base</a>,
239
+ <a href="https://huggingface.co/mpapucci/simple-score-large" target="_blank" rel="noopener noreferrer">large</a>.
240
+ Code and training: <a href="https://github.com/michelepapucci/simple-score" target="_blank" rel="noopener noreferrer">github.com/michelepapucci/simple-score</a>.
241
  Paper: <em>Rethinking Text Simplification Evaluation as Preference Learning</em> (link coming soon).</p>
242
  </section>
243
 
244
+ <footer>SIMPLE Score · MIT License ·
245
  <a href="http://www.italianlp.it/" target="_blank" rel="noopener noreferrer">ItaliaNLP Lab @ CNR-ILC</a> ·
246
  <a href="https://michelepapucci.github.io/" target="_blank" rel="noopener noreferrer">Michele Papucci</a></footer>
247
  </main>
model/manifest.json CHANGED
@@ -14,7 +14,7 @@
14
  "version": "small-int8-e2dbc3d43fa5",
15
  "runtime_bytes": 14848852,
16
  "export_report": {
17
- "model": "/tmp/claude-1006/-home-mpapucci-SimRM/02346888-ac69-4314-bd7b-2417b261b6ab/scratchpad/hfcache/models--mpapucci--simple-metric-small/snapshots/da4a27472fda25177e4122ea6f50bffd425249c9",
18
  "sizes_mb": {
19
  "model.onnx": 539.5,
20
  "model_quantized.onnx": 157.6
 
14
  "version": "small-int8-e2dbc3d43fa5",
15
  "runtime_bytes": 14848852,
16
  "export_report": {
17
+ "model": "mpapucci/simple-score-small",
18
  "sizes_mb": {
19
  "model.onnx": 539.5,
20
  "model_quantized.onnx": 157.6
simple.py → simple-score.py RENAMED
@@ -1,31 +1,31 @@
1
- """SIMPLE as a Hugging Face `evaluate` metric.
2
 
3
  import evaluate
4
- simple = evaluate.load("mpapucci/simple") # SIMPLE-large
5
- simple = evaluate.load("mpapucci/simple", "base") # or "small"
6
- out = simple.compute(sources=[...], predictions=[...])
7
 
8
- This module is a thin wrapper around the `simple-metric` package
9
- (`pip install simple-metric`), which can also be used directly.
10
  """
11
 
12
  import datasets
13
  import evaluate
14
 
15
  _CITATION = """\
16
- @misc{simple-metric,
17
  title = {Rethinking Text Simplification Evaluation as Preference Learning},
18
  note = {Citation will be added upon publication},
19
  }
20
  """
21
 
22
  _DESCRIPTION = """\
23
- SIMPLE (SImplicity Metric via Preference LEarning) is a reference-free learned metric for
24
  sentence simplification. Given a source sentence and a candidate simplification it returns a
25
  quality score in (-1, 1): +1 for a highly successful simplification, 0 for a verbatim copy of
26
  the source, and -1 for unrelated or degenerate text; negative scores flag unsuccessful
27
  simplifications, including complexifications. With every score it also reports sigma, the
28
- model's own uncertainty (lower = more confident). SIMPLE is a DeBERTa-v3 cross-encoder trained
29
  on pairwise preferences between simplifications (Thurstone model) and calibrated on human
30
  quality ratings. No reference simplifications are needed.
31
  """
@@ -37,23 +37,23 @@ Args:
37
  batch_size (int, optional): batch size for scoring. Defaults to 32.
38
  device (str, optional): e.g. "cuda", "cuda:1" or "cpu". Defaults to CUDA when available.
39
  Returns:
40
- simple (float): mean SIMPLE score over all examples, in (-1, 1).
41
  scores (list of float): per-example scores (mu).
42
  sigmas (list of float): per-example uncertainty (sigma > 0.05; lower = more confident).
43
  Examples:
44
- >>> simple = evaluate.load("mpapucci/simple")
45
- >>> out = simple.compute(
46
  ... sources=["The feline perched upon the mat in a state of repose."],
47
  ... predictions=["The cat sat on the mat."])
48
  >>> sorted(out)
49
- ['scores', 'sigmas', 'simple']
50
  """
51
 
52
  _SIZES = ("small", "base", "large")
53
 
54
 
55
  @evaluate.utils.file_utils.add_start_docstrings(_DESCRIPTION, _KWARGS_DESCRIPTION)
56
- class Simple(evaluate.Metric):
57
  def _info(self):
58
  return evaluate.MetricInfo(
59
  description=_DESCRIPTION,
@@ -62,8 +62,8 @@ class Simple(evaluate.Metric):
62
  features=datasets.Features(
63
  {"sources": datasets.Value("string"), "predictions": datasets.Value("string")}
64
  ),
65
- codebase_urls=["https://github.com/michelepapucci/simple-metric"],
66
- reference_urls=["https://huggingface.co/mpapucci/simple-metric-large"],
67
  )
68
 
69
  def _download_and_prepare(self, dl_manager):
@@ -76,11 +76,11 @@ class Simple(evaluate.Metric):
76
  def _scorer(self, device):
77
  key = str(device)
78
  if key not in self._scorers:
79
- from simple_metric import SIMPLE
80
 
81
  self._scorers[key] = SIMPLE.from_pretrained(self._model_name, device=device)
82
  return self._scorers[key]
83
 
84
  def _compute(self, sources, predictions, batch_size=32, device=None):
85
  out = self._scorer(device).score(sources, predictions, batch_size=batch_size)
86
- return {"simple": out.mean, "scores": out.mu, "sigmas": out.sigma}
 
1
+ """SIMPLE Score as a Hugging Face `evaluate` metric.
2
 
3
  import evaluate
4
+ simple_score = evaluate.load("mpapucci/simple-score") # SIMPLE-large
5
+ simple_score = evaluate.load("mpapucci/simple-score", "base") # or "small"
6
+ out = simple_score.compute(sources=[...], predictions=[...])
7
 
8
+ This module is a thin wrapper around the `simple-score` package
9
+ (`pip install simple-score`), which can also be used directly.
10
  """
11
 
12
  import datasets
13
  import evaluate
14
 
15
  _CITATION = """\
16
+ @misc{simple-score,
17
  title = {Rethinking Text Simplification Evaluation as Preference Learning},
18
  note = {Citation will be added upon publication},
19
  }
20
  """
21
 
22
  _DESCRIPTION = """\
23
+ SIMPLE Score (SImplicity Metric via Preference LEarning) is a reference-free learned metric for
24
  sentence simplification. Given a source sentence and a candidate simplification it returns a
25
  quality score in (-1, 1): +1 for a highly successful simplification, 0 for a verbatim copy of
26
  the source, and -1 for unrelated or degenerate text; negative scores flag unsuccessful
27
  simplifications, including complexifications. With every score it also reports sigma, the
28
+ model's own uncertainty (lower = more confident). SIMPLE Score is a DeBERTa-v3 cross-encoder trained
29
  on pairwise preferences between simplifications (Thurstone model) and calibrated on human
30
  quality ratings. No reference simplifications are needed.
31
  """
 
37
  batch_size (int, optional): batch size for scoring. Defaults to 32.
38
  device (str, optional): e.g. "cuda", "cuda:1" or "cpu". Defaults to CUDA when available.
39
  Returns:
40
+ simple_score (float): mean SIMPLE Score over all examples, in (-1, 1).
41
  scores (list of float): per-example scores (mu).
42
  sigmas (list of float): per-example uncertainty (sigma > 0.05; lower = more confident).
43
  Examples:
44
+ >>> simple_score = evaluate.load("mpapucci/simple-score")
45
+ >>> out = simple_score.compute(
46
  ... sources=["The feline perched upon the mat in a state of repose."],
47
  ... predictions=["The cat sat on the mat."])
48
  >>> sorted(out)
49
+ ['scores', 'sigmas', 'simple_score']
50
  """
51
 
52
  _SIZES = ("small", "base", "large")
53
 
54
 
55
  @evaluate.utils.file_utils.add_start_docstrings(_DESCRIPTION, _KWARGS_DESCRIPTION)
56
+ class SimpleScore(evaluate.Metric):
57
  def _info(self):
58
  return evaluate.MetricInfo(
59
  description=_DESCRIPTION,
 
62
  features=datasets.Features(
63
  {"sources": datasets.Value("string"), "predictions": datasets.Value("string")}
64
  ),
65
+ codebase_urls=["https://github.com/michelepapucci/simple-score"],
66
+ reference_urls=["https://huggingface.co/mpapucci/simple-score-large"],
67
  )
68
 
69
  def _download_and_prepare(self, dl_manager):
 
76
  def _scorer(self, device):
77
  key = str(device)
78
  if key not in self._scorers:
79
+ from simple_score import SIMPLE
80
 
81
  self._scorers[key] = SIMPLE.from_pretrained(self._model_name, device=device)
82
  return self._scorers[key]
83
 
84
  def _compute(self, sources, predictions, batch_size=32, device=None):
85
  out = self._scorer(device).score(sources, predictions, batch_size=batch_size)
86
+ return {"simple_score": out.mean, "scores": out.mu, "sigmas": out.sigma}