Datasets:

ArXiv:
Elron commited on
Commit
bad7464
1 Parent(s): b3257a4

Upload operators.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. operators.py +4 -8
operators.py CHANGED
@@ -1232,17 +1232,13 @@ class ComputeExpressionMixin(Artifact):
1232
 
1233
  def prepare(self):
1234
  # can not do the imports here, because object does not pickle with imports
1235
- self.globs = {}
1236
- self.to_import = True
 
1237
 
1238
  def compute_expression(self, instance: dict) -> Any:
1239
- if self.to_import:
1240
- for module_name in self.imports_list:
1241
- self.globs[module_name] = import_module(module_name)
1242
- self.to_import = False
1243
-
1244
  if settings.allow_unverified_code:
1245
- return eval(self.expression, self.globs, instance)
1246
 
1247
  raise ValueError(
1248
  f"Cannot run expression by {self} when unitxt.settings.allow_unverified_code=False either set it to True or set {settings.allow_unverified_code_key} environment variable."
 
1232
 
1233
  def prepare(self):
1234
  # can not do the imports here, because object does not pickle with imports
1235
+ self.globals = {
1236
+ module_name: import_module(module_name) for module_name in self.imports_list
1237
+ }
1238
 
1239
  def compute_expression(self, instance: dict) -> Any:
 
 
 
 
 
1240
  if settings.allow_unverified_code:
1241
+ return eval(self.expression, self.globals, instance)
1242
 
1243
  raise ValueError(
1244
  f"Cannot run expression by {self} when unitxt.settings.allow_unverified_code=False either set it to True or set {settings.allow_unverified_code_key} environment variable."