Spaces:
Sleeping
Sleeping
Create ecoeval/datasets.py
Browse files- ecoeval/datasets.py +91 -0
ecoeval/datasets.py
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# ecoeval/datasets.py
|
| 2 |
+
from typing import List
|
| 3 |
+
from datasets import Dataset
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
def _tiny_python_benchmark() -> Dataset:
|
| 7 |
+
"""
|
| 8 |
+
Very small internal dataset of Python tasks with prompts + unit tests.
|
| 9 |
+
Each row has: prompt, test_code
|
| 10 |
+
"""
|
| 11 |
+
tasks = [
|
| 12 |
+
{
|
| 13 |
+
"prompt": "Write a Python function add(a, b) that returns their sum.",
|
| 14 |
+
"test_code": "assert add(1, 2) == 3\nassert add(-1, 5) == 4",
|
| 15 |
+
},
|
| 16 |
+
{
|
| 17 |
+
"prompt": "Write a Python function is_prime(n) that returns True if n is a prime number, False otherwise.",
|
| 18 |
+
"test_code": (
|
| 19 |
+
"assert is_prime(2)\n"
|
| 20 |
+
"assert is_prime(3)\n"
|
| 21 |
+
"assert not is_prime(4)\n"
|
| 22 |
+
"assert is_prime(17)\n"
|
| 23 |
+
"assert not is_prime(1)"
|
| 24 |
+
),
|
| 25 |
+
},
|
| 26 |
+
{
|
| 27 |
+
"prompt": "Write a Python function factorial(n) that returns n! for non-negative n.",
|
| 28 |
+
"test_code": (
|
| 29 |
+
"assert factorial(0) == 1\n"
|
| 30 |
+
"assert factorial(3) == 6\n"
|
| 31 |
+
"assert factorial(5) == 120"
|
| 32 |
+
),
|
| 33 |
+
},
|
| 34 |
+
{
|
| 35 |
+
"prompt": "Write a Python function reverse_string(s) that returns the reversed string.",
|
| 36 |
+
"test_code": (
|
| 37 |
+
"assert reverse_string('abc') == 'cba'\n"
|
| 38 |
+
"assert reverse_string('') == ''\n"
|
| 39 |
+
"assert reverse_string('racecar') == 'racecar'"
|
| 40 |
+
),
|
| 41 |
+
},
|
| 42 |
+
{
|
| 43 |
+
"prompt": "Write a Python function fibonacci(n) that returns a list of the first n Fibonacci numbers, starting from 0.",
|
| 44 |
+
"test_code": (
|
| 45 |
+
"assert fibonacci(1) == [0]\n"
|
| 46 |
+
"assert fibonacci(5) == [0, 1, 1, 2, 3]\n"
|
| 47 |
+
"assert fibonacci(0) == []"
|
| 48 |
+
),
|
| 49 |
+
},
|
| 50 |
+
{
|
| 51 |
+
"prompt": "Write a Python function count_vowels(s) that returns the number of vowels in the string s.",
|
| 52 |
+
"test_code": (
|
| 53 |
+
"assert count_vowels('hello') == 2\n"
|
| 54 |
+
"assert count_vowels('xyz') == 0\n"
|
| 55 |
+
"assert count_vowels('AEiou') == 5"
|
| 56 |
+
),
|
| 57 |
+
},
|
| 58 |
+
{
|
| 59 |
+
"prompt": "Write a Python function flatten(lst) that takes a list of lists of integers and returns a single flattened list.",
|
| 60 |
+
"test_code": (
|
| 61 |
+
"assert flatten([[1,2],[3,4]]) == [1,2,3,4]\n"
|
| 62 |
+
"assert flatten([]) == []\n"
|
| 63 |
+
"assert flatten([[1],[2],[3]]) == [1,2,3]"
|
| 64 |
+
),
|
| 65 |
+
},
|
| 66 |
+
{
|
| 67 |
+
"prompt": "Write a Python function is_palindrome(s) that returns True if s is a palindrome, ignoring case and spaces.",
|
| 68 |
+
"test_code": (
|
| 69 |
+
"assert is_palindrome('racecar')\n"
|
| 70 |
+
"assert is_palindrome('RaceCar')\n"
|
| 71 |
+
"assert is_palindrome('nurses run')\n"
|
| 72 |
+
"assert not is_palindrome('hello')"
|
| 73 |
+
),
|
| 74 |
+
},
|
| 75 |
+
]
|
| 76 |
+
return Dataset.from_list(tasks)
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
_AVAILABLE_DATASETS = {
|
| 80 |
+
"tiny-python-benchmark": _tiny_python_benchmark,
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
def list_available_datasets() -> List[str]:
|
| 85 |
+
return sorted(_AVAILABLE_DATASETS.keys())
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
def load_dataset_by_name(name: str) -> Dataset:
|
| 89 |
+
if name not in _AVAILABLE_DATASETS:
|
| 90 |
+
raise ValueError(f"Unknown dataset: {name}")
|
| 91 |
+
return _AVAILABLE_DATASETS[name]()
|