Spaces:
Running
Running
Update Space (evaluate main: c447fc8e)
Browse files- perplexity.py +2 -26
- requirements.txt +1 -1
perplexity.py
CHANGED
@@ -13,9 +13,6 @@
|
|
13 |
# limitations under the License.
|
14 |
"""Perplexity Metric."""
|
15 |
|
16 |
-
from dataclasses import dataclass
|
17 |
-
from typing import Optional
|
18 |
-
|
19 |
import datasets
|
20 |
import numpy as np
|
21 |
import torch
|
@@ -87,30 +84,14 @@ Examples:
|
|
87 |
"""
|
88 |
|
89 |
|
90 |
-
@dataclass
|
91 |
-
class PerplexityConfig(evaluate.info.Config):
|
92 |
-
|
93 |
-
name: str = "default"
|
94 |
-
|
95 |
-
model_id: str = "binary"
|
96 |
-
batch_size: int = 16
|
97 |
-
add_start_token: bool = True
|
98 |
-
device: Optional[str] = None
|
99 |
-
|
100 |
-
|
101 |
@evaluate.utils.file_utils.add_start_docstrings(_DESCRIPTION, _KWARGS_DESCRIPTION)
|
102 |
class Perplexity(evaluate.Metric):
|
103 |
-
|
104 |
-
CONFIG_CLASS = PerplexityConfig
|
105 |
-
ALLOWED_CONFIG_NAMES = ["default"]
|
106 |
-
|
107 |
-
def _info(self, config):
|
108 |
return evaluate.MetricInfo(
|
109 |
module_type="metric",
|
110 |
description=_DESCRIPTION,
|
111 |
citation=_CITATION,
|
112 |
inputs_description=_KWARGS_DESCRIPTION,
|
113 |
-
config=config,
|
114 |
features=datasets.Features(
|
115 |
{
|
116 |
"predictions": datasets.Value("string"),
|
@@ -119,12 +100,7 @@ class Perplexity(evaluate.Metric):
|
|
119 |
reference_urls=["https://huggingface.co/docs/transformers/perplexity"],
|
120 |
)
|
121 |
|
122 |
-
def _compute(self, predictions):
|
123 |
-
|
124 |
-
model_id = self.config.model_id
|
125 |
-
device = self.config.device
|
126 |
-
batch_size = self.config.batch_size
|
127 |
-
add_start_token = self.config.add_start_token
|
128 |
|
129 |
if device is not None:
|
130 |
assert device in ["gpu", "cpu", "cuda"], "device should be either gpu or cpu."
|
|
|
13 |
# limitations under the License.
|
14 |
"""Perplexity Metric."""
|
15 |
|
|
|
|
|
|
|
16 |
import datasets
|
17 |
import numpy as np
|
18 |
import torch
|
|
|
84 |
"""
|
85 |
|
86 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
87 |
@evaluate.utils.file_utils.add_start_docstrings(_DESCRIPTION, _KWARGS_DESCRIPTION)
|
88 |
class Perplexity(evaluate.Metric):
|
89 |
+
def _info(self):
|
|
|
|
|
|
|
|
|
90 |
return evaluate.MetricInfo(
|
91 |
module_type="metric",
|
92 |
description=_DESCRIPTION,
|
93 |
citation=_CITATION,
|
94 |
inputs_description=_KWARGS_DESCRIPTION,
|
|
|
95 |
features=datasets.Features(
|
96 |
{
|
97 |
"predictions": datasets.Value("string"),
|
|
|
100 |
reference_urls=["https://huggingface.co/docs/transformers/perplexity"],
|
101 |
)
|
102 |
|
103 |
+
def _compute(self, predictions, model_id, batch_size: int = 16, add_start_token: bool = True, device=None):
|
|
|
|
|
|
|
|
|
|
|
104 |
|
105 |
if device is not None:
|
106 |
assert device in ["gpu", "cpu", "cuda"], "device should be either gpu or cpu."
|
requirements.txt
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
git+https://github.com/huggingface/evaluate@
|
2 |
torch
|
3 |
torch
|
4 |
transformers
|
|
|
1 |
+
git+https://github.com/huggingface/evaluate@c447fc8eda9c62af501bfdc6988919571050d950
|
2 |
torch
|
3 |
torch
|
4 |
transformers
|