add k param
Browse files
README.md
CHANGED
|
@@ -31,6 +31,7 @@ It is the average of the precision scores computer after each relevant document
|
|
| 31 |
### Inputs
|
| 32 |
- **predictions:** a list of dictionaries where each dictionary consists of document relevancy scores produced by the model for a given query. One dictionary per query. The dictionaries should be converted to string.
|
| 33 |
- **references:** a lift of list of dictionaries where each dictionary consists of the relevant order for the documents for a given query in a sorted relevancy order. The dictionaries should be converted to string.
|
|
|
|
| 34 |
|
| 35 |
### Output Values
|
| 36 |
- **map (`float`):** mean average precision score. Minimum possible value is 0. Maximum possible value is 1.0
|
|
|
|
| 31 |
### Inputs
|
| 32 |
- **predictions:** a list of dictionaries where each dictionary consists of document relevancy scores produced by the model for a given query. One dictionary per query. The dictionaries should be converted to string.
|
| 33 |
- **references:** a lift of list of dictionaries where each dictionary consists of the relevant order for the documents for a given query in a sorted relevancy order. The dictionaries should be converted to string.
|
| 34 |
+
- **k:** an optional paramater whose default is None to calculate map@k
|
| 35 |
|
| 36 |
### Output Values
|
| 37 |
- **map (`float`):** mean average precision score. Minimum possible value is 0. Maximum possible value is 1.0
|
map.py
CHANGED
|
@@ -46,6 +46,7 @@ Args:
|
|
| 46 |
One dictionary per query.
|
| 47 |
references: List of list of strings where each lists consists of the relevant document names for a given query in a sorted relevancy order.
|
| 48 |
The outer list is sorted from query one to n.
|
|
|
|
| 49 |
Returns:
|
| 50 |
map (`float`): mean average precision score. Minimum possible value is 0. Maximum possible value is 1.0
|
| 51 |
Examples:
|
|
@@ -75,14 +76,15 @@ class map(evaluate.Metric):
|
|
| 75 |
inputs_description=_KWARGS_DESCRIPTION,
|
| 76 |
# This defines the format of each prediction and reference
|
| 77 |
features=datasets.Features({
|
| 78 |
-
'predictions': datasets.Value("string"),
|
| 79 |
-
'references': datasets.Value("string")
|
|
|
|
| 80 |
}),
|
| 81 |
# Homepage of the module for documentation
|
| 82 |
reference_urls=["https://amenra.github.io/ranx/"]
|
| 83 |
)
|
| 84 |
|
| 85 |
-
def _compute(self, predictions, references):
|
| 86 |
"""Returns the scores"""
|
| 87 |
preds = {}
|
| 88 |
refs = {}
|
|
@@ -92,12 +94,6 @@ class map(evaluate.Metric):
|
|
| 92 |
refs = refs | json.loads(ref)
|
| 93 |
|
| 94 |
run = Run(preds)
|
| 95 |
-
"""gt_dict = {}
|
| 96 |
-
for i in range(len(references)):
|
| 97 |
-
per_query_gt = {}
|
| 98 |
-
for rank in range(len(references[i])):
|
| 99 |
-
per_query_gt[references[i][rank]] = rank+1
|
| 100 |
-
gt_dict[f"q_{i+1}"] = per_query_gt"""
|
| 101 |
qrels = Qrels(refs)
|
| 102 |
map_score = ran_evaluate(qrels, run, "map")
|
| 103 |
return {
|
|
|
|
| 46 |
One dictionary per query.
|
| 47 |
references: List of list of strings where each lists consists of the relevant document names for a given query in a sorted relevancy order.
|
| 48 |
The outer list is sorted from query one to n.
|
| 49 |
+
k: `int`, optional, default is None, it is to calculate map@k
|
| 50 |
Returns:
|
| 51 |
map (`float`): mean average precision score. Minimum possible value is 0. Maximum possible value is 1.0
|
| 52 |
Examples:
|
|
|
|
| 76 |
inputs_description=_KWARGS_DESCRIPTION,
|
| 77 |
# This defines the format of each prediction and reference
|
| 78 |
features=datasets.Features({
|
| 79 |
+
'predictions': datasets.Value("string"),
|
| 80 |
+
'references': datasets.Value("string"),
|
| 81 |
+
'k': datasets.Value("int", default=None)
|
| 82 |
}),
|
| 83 |
# Homepage of the module for documentation
|
| 84 |
reference_urls=["https://amenra.github.io/ranx/"]
|
| 85 |
)
|
| 86 |
|
| 87 |
+
def _compute(self, predictions, references, k=None):
|
| 88 |
"""Returns the scores"""
|
| 89 |
preds = {}
|
| 90 |
refs = {}
|
|
|
|
| 94 |
refs = refs | json.loads(ref)
|
| 95 |
|
| 96 |
run = Run(preds)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
qrels = Qrels(refs)
|
| 98 |
map_score = ran_evaluate(qrels, run, "map")
|
| 99 |
return {
|