Returns the scores
(self, predictions, references, k=[1, 10, 100], num_workers=4, timeout=3.0)
| 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 |
| 193 | pass_at_k = {f"pass@{k}": estimate_pass_at_k(total, correct, k).mean() for k in ks if (total >= k).all()} |
| 194 | |
| 195 | return pass_at_k, results |
| 196 | |
| 197 | |
| 198 | def estimate_pass_at_k(num_samples, num_correct, k): |
nothing calls this directly
no test coverage detected