unitxt icon indicating copy to clipboard operation
unitxt copied to clipboard

Add DynamicFormat that uses different SystemFormat based on size of demos list and existence of instruction.

Open elronbandel opened this issue 1 year ago • 0 comments

class DynamicFormat(Format):
  few_shot_format: Format
  few_shot_with_instruction_format: Format
  zero_shot_format: Format
  zero_shot_with_instruction_format: Format
      
  def process(instance):
     has_instruction =  "instruction" not in instance or len(instance["instruction"] == 0
     has_demos =  len(instance["demos"]) == 0
     if has_demos:
         if has_instruction:
             format = self.few_shot_with_instruction_format
         else:
             format = self.few_shot_format
     else:
         if has_instruction:
            format = self.zero_shot_with_instruction_format
         else:
            format = self.zero_shot_format
     return format.process_instance(instance)

elronbandel avatar Mar 20 '24 09:03 elronbandel