@@ -43,25 +43,25 @@ def __init__(
43
43
model_path ,
44
44
unitxt_recipe : str ,
45
45
):
46
- task = self .assign_task_name ()
47
- tasks_dir = self .assign_tasks_dir (task )
46
+ unitxt_task = self .assign_task_name ()
47
+ tasks_dir = self .assign_tasks_dir (unitxt_task )
48
48
super ().__init__ (
49
- model_path = model_path , tasks_dir = tasks_dir , tasks = [task ], few_shots = 0
49
+ model_path = model_path , tasks_dir = tasks_dir , tasks = [unitxt_task ], few_shots = 0
50
50
)
51
51
self .unitxt_recipe = unitxt_recipe
52
52
53
- def assign_tasks_dir (self , task ):
54
- return f"{ TEMP_DIR_PREFIX } _{ task } "
53
+ def assign_tasks_dir (self , task_name ):
54
+ return f"{ TEMP_DIR_PREFIX } _{ task_name } "
55
55
56
56
def assign_task_name (self ):
57
57
return str (uuid4 ())
58
58
59
- def prepare_unitxt_files (self ) -> tuple :
60
- task = self .tasks [0 ]
61
- yaml_file = os .path .join (self .tasks_dir , f"{ task } .yaml" )
59
+ def prepare_unitxt_files (self ) -> None :
60
+ taskname = self .tasks [0 ]
61
+ yaml_file = os .path .join (str ( self .tasks_dir ) , f"{ taskname } .yaml" )
62
62
create_unitxt_pointer (self .tasks_dir )
63
63
create_unitxt_yaml (
64
- yaml_file = yaml_file , unitxt_recipe = self .unitxt_recipe , task_name = task
64
+ yaml_file = yaml_file , unitxt_recipe = self .unitxt_recipe , task_name = taskname
65
65
)
66
66
67
67
def remove_unitxt_files (self ):
@@ -71,7 +71,7 @@ def remove_unitxt_files(self):
71
71
shutil .rmtree (self .tasks_dir )
72
72
else :
73
73
logger .warning (
74
- f "unitxt tasks dir did not start with '{ TEMP_DIR_PREFIX } ' and therefor was not deleted"
74
+ "unitxt tasks dir did not start with '%s ' and therefor was not deleted" , TEMP_DIR_PREFIX
75
75
)
76
76
77
77
def run (self , server_url : str | None = None ) -> tuple :
@@ -101,7 +101,7 @@ def run(self, server_url: str | None = None) -> tuple:
101
101
for metric in metrics :
102
102
scores [metric ] = instance [metric ][0 ]
103
103
instance_scores [i ] = scores
104
- except Exception as e :
104
+ except KeyError as e :
105
105
logger .error ("Error in extracting single instance scores" )
106
106
logger .error (e )
107
107
logger .error (e .__traceback__ )
@@ -112,15 +112,15 @@ def run(self, server_url: str | None = None) -> tuple:
112
112
113
113
def create_unitxt_yaml (yaml_file , unitxt_recipe , task_name ):
114
114
data = {"task" : f"{ task_name } " , "include" : "unitxt" , "recipe" : f"{ unitxt_recipe } " }
115
- with open (yaml_file , "w" ) as file :
115
+ with open (yaml_file , "w" , encoding = "utf-8" ) as file :
116
116
yaml .dump (data , file , default_flow_style = False )
117
- logger .debug (f "task { task } unitxt recipe written to { yaml_file } " )
117
+ logger .debug ("task %s unitxt recipe written to %s" , task_name , yaml_file )
118
118
119
119
120
120
def create_unitxt_pointer (tasks_dir ):
121
121
class_line = "class: !function " + task .__file__ .replace ("task.py" , "task.Unitxt" )
122
122
output_file = os .path .join (tasks_dir , "unitxt" )
123
123
os .makedirs (os .path .dirname (output_file ), exist_ok = True )
124
- with open (output_file , "w" ) as f :
124
+ with open (output_file , "w" , encoding = "utf-8" ) as f :
125
125
f .write (class_line )
126
- logger .debug (f "Unitxt task pointer written to { output_file } " )
126
+ logger .debug ("Unitxt task pointer written to %s" , output_file )
0 commit comments