Spaces:
Runtime error
Runtime error
JP-SystemsX
commited on
Commit
·
3d11165
1
Parent(s):
82bab0f
Init Code
Browse files- app.py +11 -0
- nDCG.py +25 -0
- requirements.txt +2 -0
app.py
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import sys
|
2 |
+
|
3 |
+
import evaluate
|
4 |
+
from evaluate.utils import launch_gradio_widget
|
5 |
+
|
6 |
+
|
7 |
+
sys.path = [p for p in sys.path if p != "/home/user/app"]
|
8 |
+
module = evaluate.load("nDCG")
|
9 |
+
sys.path = ["/home/user/app"] + sys.path
|
10 |
+
|
11 |
+
launch_gradio_widget(module)
|
nDCG.py
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import evaluate as ev
|
2 |
+
from sklearn.metrics import ndcg_score
|
3 |
+
import datasets
|
4 |
+
|
5 |
+
@ev.utils.file_utils.add_start_docstrings("_DESCRIPTION", "_KWARGS_DESCRIPTION")
|
6 |
+
class nDCG(ev.Metric):
|
7 |
+
def _info(self):
|
8 |
+
return ev.MetricInfo(
|
9 |
+
module_type="metric",
|
10 |
+
description="nDCG",
|
11 |
+
citation="None",
|
12 |
+
inputs_description="None",
|
13 |
+
features=datasets.Features({
|
14 |
+
'predictions': datasets.Sequence(datasets.Value('float')),
|
15 |
+
'references': datasets.Sequence(datasets.Value('float'))
|
16 |
+
}),
|
17 |
+
homepage="none",
|
18 |
+
)
|
19 |
+
|
20 |
+
def _compute(self, predictions, references, sample_weight=None, k=5):
|
21 |
+
"""Returns the scores"""
|
22 |
+
score = ndcg_score(references, predictions, k=k, sample_weight=sample_weight)
|
23 |
+
return {
|
24 |
+
"nDCG@"+str(k): score
|
25 |
+
}
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
git+https://github.com/huggingface/evaluate@dd35e04844c71068318335e05d8a658200dafe89
|
2 |
+
scikit-learn
|