MCPcopy Create free account
hub / github.com/huggingface/evaluate / CodeEval

Class CodeEval

metrics/code_eval/code_eval.py:135–195  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

133
134@evaluate.utils.file_utils.add_start_docstrings(_DESCRIPTION, _KWARGS_DESCRIPTION)
135class CodeEval(evaluate.Metric):
136 def _info(self):
137 return evaluate.MetricInfo(
138 # This is the description that will appear on the metrics page.
139 description=_DESCRIPTION,
140 citation=_CITATION,
141 inputs_description=_KWARGS_DESCRIPTION,
142 # This defines the format of each prediction and reference
143 features=datasets.Features(
144 {
145 "predictions": datasets.Sequence(datasets.Value("string")),
146 "references": datasets.Value("string"),
147 }
148 ),
149 homepage="https://github.com/openai/human-eval",
150 codebase_urls=["https://github.com/openai/human-eval"],
151 reference_urls=["https://github.com/openai/human-eval"],
152 license=_LICENSE,
153 )
154
155 def _compute(self, predictions, references, k=[1, 10, 100], num_workers=4, timeout=3.0):
156 """Returns the scores"""
157
158 if os.getenv("HF_ALLOW_CODE_EVAL", 0) != "1":
159 raise ValueError(_WARNING)
160
161 if os.name == "nt":
162 raise NotImplementedError("This metric is currently not supported on Windows.")
163
164 with ThreadPoolExecutor(max_workers=num_workers) as executor:
165 futures = []
166 completion_id = Counter()
167 n_samples = 0
168 results = defaultdict(list)
169
170 for task_id, (candidates, test_case) in enumerate(zip(predictions, references)):
171 for candidate in candidates:
172 test_program = candidate + "\n" + test_case
173 args = (test_program, timeout, task_id, completion_id[task_id])
174 future = executor.submit(check_correctness, *args)
175 futures.append(future)
176 completion_id[task_id] += 1
177 n_samples += 1
178
179 for future in as_completed(futures):
180 result = future.result()
181 results[result["task_id"]].append((result["completion_id"], result))
182
183 total, correct = [], []
184 for result in results.values():
185 result.sort()
186 passed = [r[1]["passed"] for r in result]
187 total.append(len(passed))
188 correct.append(sum(passed))
189 total = np.array(total)
190 correct = np.array(correct)
191
192 ks = k

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…