Spaces:
Sleeping
Sleeping
| import pytest | |
| from test_of_time_accuracy import TestOfTimeAccuracy | |
| arithmetic_test_cases = { | |
| "predictions": [ | |
| 'JSON = {"explanation": "The war began in 360 BC. Since BC years count backwards, adding 8 years to 360 BC means subtracting 8 from 360, resulting in 352 BC.", "answer": "352 BC"}', | |
| '```json\n{\n "explanation": "The dates provided are March 2012, September 2011, June 2017, September 2019, and June 2015. These correspond to visits to Miami, Sydney, Tokyo, London, and Nairobi respectively. The latest date among these is September 2019, which is associated with London. Therefore, London is the last city visited.",\n "unordered_list": ["Berlin","London"]\n}\n```', | |
| ' "To find the date of the second most important game, we need to subtract 7 days from the date of the most important game. We can do this by counting back 7 days from April 14, 2005. April 14 - 7 days = April 7, 2005", "answer": "2005-04-07"}', | |
| ], | |
| "references": [ | |
| '{"answer": "352 BC"}', | |
| '{"unordered_list": ["London", "Berlin"]}', | |
| "{'answer': '2005-04-07'}", | |
| ], | |
| "result": {"accuracy": 2 / 3}, | |
| "per_item_accuracy": [True, True, False], | |
| } | |
| semantic_test_cases = { | |
| "predictions": [ | |
| '{"explanation": First, we need to find the third occurrence of E33 being the R53 of E22. We can see that it happened from 1959 to 1962, then from 1967 to 1968, and then from 1982 to 1984. The third occurrence happened from 1982 to 1984. We can then compute the duration by subtracting the start time from the end time.", "answer": 2}', | |
| ' "To find the duration, we need to find the start and end time when E97 was the R71 of E67. From the given facts, we can see that E97 was the R71 of E67 from 1961 to 1961, and also from 1964 to 1964. We need to find the first occurrence, which is from 1961 to 1961.", "answer": 1}', | |
| '{"explanation": "To find when E92 stopped being the R88 of E11, we need to look at the temporal facts where E92 was the R88 of E11 and find the end time. We see that E92 was the R88 of E11 from 1982 to 1985, and there is no other fact that indicates E92 stopped being the R88 of E11 before 1985. However, we also see that E92 was the R17 of E42 from 1986 to 1992, and E92 was the R88 of E42 from 1977 to 1979, but this is irrelevant to the question. Therefore, E92 stopped being the R88 of E11 in 1985.", "answer": 1985}', | |
| ], | |
| "references": ["2", "0", "1985"], | |
| "result": {"accuracy": 1 / 3}, | |
| "per_item_accuracy": [False, False, True], | |
| } | |
| def test_arithmetic_accuracy(): | |
| metric = TestOfTimeAccuracy() | |
| results = metric.compute( | |
| predictions=arithmetic_test_cases["predictions"], | |
| references=arithmetic_test_cases["references"], | |
| subset="arithmetic", | |
| ) | |
| assert results == arithmetic_test_cases["result"] | |
| def test_semantic_accuracy(): | |
| metric = TestOfTimeAccuracy() | |
| results = metric.compute( | |
| predictions=semantic_test_cases["predictions"], | |
| references=semantic_test_cases["references"], | |
| subset="semantic", | |
| ) | |
| assert results == semantic_test_cases["result"] | |
| def test_per_item_arithmetic_accuracy(): | |
| metric = TestOfTimeAccuracy() | |
| results = metric.compute( | |
| predictions=arithmetic_test_cases["predictions"], | |
| references=arithmetic_test_cases["references"], | |
| subset="arithmetic", | |
| return_average=False, | |
| ) | |
| assert results["accuracy"] == arithmetic_test_cases["per_item_accuracy"] | |
| def test_per_item_semantic_accuracy(): | |
| metric = TestOfTimeAccuracy() | |
| results = metric.compute( | |
| predictions=semantic_test_cases["predictions"], | |
| references=semantic_test_cases["references"], | |
| subset="semantic", | |
| return_average=False, | |
| ) | |
| assert results["accuracy"] == semantic_test_cases["per_item_accuracy"] | |
| def test_invalid_subset(): | |
| metric = TestOfTimeAccuracy() | |
| with pytest.raises(ValueError): | |
| metric.compute( | |
| predictions=arithmetic_test_cases["predictions"], | |
| references=arithmetic_test_cases["references"], | |
| subset="invalid", | |
| ) | |