2222
2323
2424import numpy as np
25- from inspect_ai .dataset import Sample
26- from inspect_ai .scorer import Score , Target , accuracy , scorer , stderr
27- from inspect_ai .solver import TaskState
2825
29- import lighteval .tasks .extended .ifeval .instructions_registry as instructions_registry
26+ import lighteval .tasks .tasks .ifeval .instructions_registry as instructions_registry
3027from lighteval .metrics .metrics_sample import SampleLevelComputation
31- from lighteval .metrics .utils .metric_utils import SampleLevelMetricGrouping
28+ from lighteval .metrics .utils .metric_utils import (
29+ SampleLevelMetricGrouping ,
30+ )
3231from lighteval .models .model_output import ModelResponse
3332from lighteval .tasks .lighteval_task import LightevalTaskConfig
3433from lighteval .tasks .requests import Doc , SamplingMethod
3736
3837# Very specific task where there are no precise outputs but instead we test if the format obeys rules
3938@requires ("langdetect" )
40- def ifeval_prompt (record ):
41- metadata = {"instruction_id_list" : record ["instruction_id_list" ], "kwargs" : record ["kwargs" ]}
42-
43- return Sample (
44- input = record ["prompt" ],
45- metadata = metadata ,
39+ def ifeval_prompt (line , task_name : str = "" ):
40+ return Doc (
41+ task_name = task_name ,
42+ query = line ["prompt" ],
43+ choices = ["" ],
44+ gold_index = 0 ,
45+ instruction = "" ,
46+ specific = {"instructions_id_list" : line ["instruction_id_list" ], "kwargs" : line ["kwargs" ]},
4647 )
4748
4849
4950submetric_names = [
5051 "prompt_level_strict_acc" ,
52+ "inst_level_strict_acc" ,
5153 "prompt_level_loose_acc" ,
54+ "inst_level_loose_acc" ,
55+ ]
56+
57+ REASONING_TAG_PAIRS = [
58+ ("<think>" , "</think>" ),
5259]
5360
5461
55- @scorer (
56- metrics = {
57- "prompt_level_strict_acc" : [accuracy (), stderr ()],
58- "prompt_level_loose_acc" : [accuracy (), stderr ()],
59- }
60- )
61- def ifeval_scorer ():
62- async def score (state : TaskState , target : Target ):
63- response = state .output .completion
62+ class IFEvalMetrics (SampleLevelComputation ):
63+ def compute (self , doc : Doc , model_response : ModelResponse , ** kwargs ) -> dict :
64+ response = model_response .final_text [0 ]
6465
6566 # Strict instructions
66- instruction_list = state . metadata [ "instruction_id_list " ]
67- all_kwargs = state . metadata ["kwargs" ]
68- prompt = state . input
67+ instruction_list = doc . specific [ "instructions_id_list " ]
68+ all_kwargs = doc . specific ["kwargs" ]
69+ prompt = doc . query
6970
7071 # Loose instructions
7172 r = response .split ("\n " )
@@ -116,19 +117,12 @@ async def score(state: TaskState, target: Target):
116117
117118 is_following_list_loose .append (is_following )
118119
119- return Score (
120- value = {
121- "prompt_level_strict_acc" : int (all (is_following_list_strict )),
122- "prompt_level_loose_acc" : int (all (is_following_list_loose )),
123- }
124- )
125-
126- return score
127-
128-
129- class IFEvalMetrics (SampleLevelComputation ):
130- def compute (self , doc : Doc , model_response : ModelResponse , ** kwargs ) -> dict :
131- pass
120+ return {
121+ "prompt_level_strict_acc" : int (all (is_following_list_strict )),
122+ "inst_level_strict_acc" : is_following_list_strict ,
123+ "prompt_level_loose_acc" : int (all (is_following_list_loose )),
124+ "inst_level_loose_acc" : is_following_list_loose ,
125+ }
132126
133127
134128@requires ("langdetect" )
@@ -155,12 +149,17 @@ def agg_inst_level_acc(items):
155149ifeval = LightevalTaskConfig (
156150 name = "ifeval" ,
157151 prompt_function = ifeval_prompt ,
158- dataset_repo = "google/IFEval" ,
159- dataset_subset = "default" ,
160- dataset_split = "train" ,
161- dataset_revision = "main" ,
162- metrics = [],
163- system_prompt = "FOLLOW THE INSTRUCTIONS STRICTLY." ,
152+ suite = ["extended" ],
153+ hf_repo = "google/IFEval" ,
154+ hf_subset = "default" ,
155+ metrics = [ifeval_metrics ],
156+ hf_avail_splits = ["train" ],
157+ evaluation_splits = ["train" ],
158+ few_shots_split = "train" ,
159+ few_shots_select = "random_sampling" ,
160+ generation_size = 1280 ,
161+ stop_sequence = [], # no stop sequence, will use eot token
162+ version = "0.1" ,
164163)
165164
166165
0 commit comments