unitxt
unitxt copied to clipboard
Add DynamicFormat that uses different SystemFormat based on size of demos list and existence of instruction.
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)