|
4 | 4 |
|
5 | 5 | import argparse |
6 | 6 | from pathlib import Path |
| 7 | +from collections import defaultdict |
| 8 | +from pyexpat import model |
7 | 9 |
|
8 | 10 | from codeclash.analysis.llm_as_judge.utils import InstanceBatch, get_instances |
9 | 11 |
|
|
13 | 15 | parser.add_argument("-o", "--output-file", type=Path, help="Path to the output file", default="instances.json") |
14 | 16 | args = parser.parse_args() |
15 | 17 |
|
16 | | - SELECTED_ROUNDS = [1, 2, 3, 5, 10, 15] |
| 18 | + SELECTED_ROUNDS = [1, 2, 3, 5, 10, 12, 14, 15] |
17 | 19 | SELECTED_GAME = "BattleSnake" |
| 20 | + NUMBER_OF_INDEPENDENT_GAMES = 3 |
18 | 21 |
|
19 | 22 | # first get all instances, then filter |
20 | 23 | instances = sorted(get_instances(args.input_dir), key=lambda x: x.instance_id) |
|
24 | 27 | instances = [instance for instance in instances if instance.round_number in SELECTED_ROUNDS] |
25 | 28 | print(f"Filtered to {len(instances)} instances because of round number") |
26 | 29 |
|
27 | | - # OK, now it gest more complicated, because we only want to keep one |
28 | | - # instance per combination of game, lm, and round |
29 | | - unique = {} |
| 30 | + grouped = defaultdict(list) |
30 | 31 | for instance in instances: |
31 | | - key = (*instance.get_lm_name_self_opponent(), instance.round_number) |
32 | | - if key not in unique: |
33 | | - unique[key] = instance |
34 | | - instances = list(unique.values()) |
| 32 | + model_name_player, model_name_opponent = instance.get_lm_name_self_opponent() |
| 33 | + if model_name_player == model_name_opponent: |
| 34 | + continue |
| 35 | + key = (model_name_player, model_name_opponent, instance.round_number) |
| 36 | + grouped[key].append(instance) |
| 37 | + |
| 38 | + selected_instances = [] |
| 39 | + for key, instance_list in grouped.items(): |
| 40 | + if len(instance_list) < NUMBER_OF_INDEPENDENT_GAMES: |
| 41 | + print(f"Warning: Only found {len(instance_list)} instances for {key}, need {NUMBER_OF_INDEPENDENT_GAMES}") |
| 42 | + selected_count = min(len(instance_list), NUMBER_OF_INDEPENDENT_GAMES) |
| 43 | + selected_instances.extend(instance_list[:selected_count]) |
| 44 | + |
| 45 | + instances = selected_instances |
35 | 46 | unique_models = set([instance.get_lm_name_self_opponent()[0] for instance in instances]) |
36 | | - print(unique_models) |
37 | | - print(f"Filtered to {len(instances)} instances after deduplication for game repetitions for {len(unique_models)} unique model matchups") |
| 47 | + print(f"Filtered to {len(instances)} instances after keeping {NUMBER_OF_INDEPENDENT_GAMES} for game repetitions for {len(unique_models)} unique model matchups") |
38 | 48 |
|
39 | 49 | batch = InstanceBatch(instances=instances) |
40 | 50 | args.output_file.write_text(batch.model_dump_json()) |
|
0 commit comments