Datasets:
updates check answer logic
Browse files
README.md
CHANGED
|
@@ -96,19 +96,24 @@ To check the answer, we use an exact match criteria:
|
|
| 96 |
```python
|
| 97 |
import re
|
| 98 |
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
|
|
|
|
|
|
|
|
|
| 104 |
preds = generation.split("\n")[-1]
|
| 105 |
preds = re.sub("Answer:", "", preds)
|
| 106 |
preds = preds.split(",")
|
| 107 |
preds = [p.strip() for p in preds]
|
| 108 |
preds = sorted(preds, key=lambda x: x[0])
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
|
|
|
|
|
|
| 112 |
```
|
| 113 |
|
| 114 |
|
|
|
|
| 96 |
```python
|
| 97 |
import re
|
| 98 |
|
| 99 |
+
def check_answer(generation: str, ground_truth: str) -> bool:
|
| 100 |
+
"""
|
| 101 |
+
Args:
|
| 102 |
+
generation: model response, expected to contain "Answer: ..."
|
| 103 |
+
ground_truth: comma-separated string of correct answers
|
| 104 |
+
|
| 105 |
+
Returns: bool, whether the prediction matches the ground truth
|
| 106 |
+
"""
|
| 107 |
preds = generation.split("\n")[-1]
|
| 108 |
preds = re.sub("Answer:", "", preds)
|
| 109 |
preds = preds.split(",")
|
| 110 |
preds = [p.strip() for p in preds]
|
| 111 |
preds = sorted(preds, key=lambda x: x[0])
|
| 112 |
+
|
| 113 |
+
# split into a list
|
| 114 |
+
ground_truth_list = [a.strip() for a in ground_truth.split(",")]
|
| 115 |
+
ground_truth_list = sorted(ground_truth_list)
|
| 116 |
+
return preds == ground_truth_list
|
| 117 |
```
|
| 118 |
|
| 119 |
|