Upload standard.py with huggingface_hub
Browse files123456789101 unmodified line12131415161718192021222324252 unmodified lines28293031323313 unmodified lines474849505152539 unmodified lines63646566676814 unmodified lines8384858687888911 unmodified lines101102103from typing import Listfrom .card import TaskCardfrom .dataclass import InternalFieldfrom .formats import ICLFormatfrom .instructions import Instructionfrom .operator import SourceSequntialOperator, StreamingOperatorfrom .recipe import Recipefrom .renderers import StandardRendererfrom .schema import ToUnitxtGroup1 unmodified linefrom .templates import Templateclass StandardRecipe(Recipe, SourceSequntialOperator):card: TaskCardtemplate: Template = Noneinstruction: Instruction = Noneformat: ICLFormat = ICLFormat()demos_pool_size: int = Nonenum_demos: int = Nonedemos_pool_name: str = "demos_pool"demos_taken_from: str = "train"2 unmodified linessteps: List[StreamingOperator] = InternalField(default_factory=list)def prepare(self):self.steps = [self.card.loader,13 unmodified lines))if self.num_demos is not None:sampler = self.card.samplerif self.sampler is not None:9 unmodified lines))render = StandardRenderer(instruction=self.instruction,template=self.template,14 unmodified lines)class StandardRecipeWithIndexes(StandardRecipe):instruction_card_index: int = Nonetemplate_card_index: int = None11 unmodified linesself.instruction = self.card.instructions[int(self.instruction_card_index)]super().prepare()12345678910111 unmodified line1314151617181920212223242526272829303132333435362 unmodified lines39404142434445464748495051525354555613 unmodified lines707172737475769 unmodified lines868788899091929394959697989910014 unmodified lines11511611711811912012111 unmodified lines133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177from typing import Listfrom .card import TaskCardfrom .dataclass import InternalField, OptionalFieldfrom .formats import ICLFormatfrom .instructions import Instructionfrom .operator import SourceSequntialOperator, StreamingOperatorfrom .operators import StreamRefinerfrom .recipe import Recipefrom .renderers import StandardRendererfrom .schema import ToUnitxtGroup1 unmodified linefrom .templates import Templateclass BaseRecipe(Recipe, SourceSequntialOperator):card: TaskCardtemplate: Template = Noneinstruction: Instruction = Noneformat: ICLFormat = ICLFormat()max_train_instances: int = Nonemax_validation_instances: int = Nonemax_test_instances: int = Nonetrain_refiner: StreamRefiner = OptionalField(default_factory=lambda: StreamRefiner(apply_to_streams=["train"]))validation_refiner: StreamRefiner = OptionalField(default_factory=lambda: StreamRefiner(apply_to_streams=["validation"]))test_refiner: StreamRefiner = OptionalField(default_factory=lambda: StreamRefiner(apply_to_streams=["test"]))demos_pool_size: int = Nonenum_demos: int = 0demos_pool_name: str = "demos_pool"demos_taken_from: str = "train"2 unmodified linessteps: List[StreamingOperator] = InternalField(default_factory=list)def verify(self):super().verify()if self.num_demos > 0:if self.demos_pool_size is None or self.demos_pool_size < 1:raise ValueError("When using demonstrations both num_demos and demos_pool_size should be assigned with postive integers.")if self.demos_pool_size < self.num_demos:raise ValueError(f"demos_pool_size must be bigger than num_demos={self.num_demos}, Got demos_pool_size={self.demos_pool_size}")def prepare(self):self.steps = [self.card.loader,13 unmodified lines))if self.num_demos > 0:sampler = self.card.samplerif self.sampler is not None:9 unmodified lines))self.train_refiner.max_instances = self.max_train_instancesself.steps.append(self.train_refiner)self.validation_refiner.max_instances = self.max_validation_instancesself.steps.append(self.validation_refiner)self.test_refiner.max_instances = self.max_test_instancesself.steps.append(self.test_refiner)render = StandardRenderer(instruction=self.instruction,template=self.template,14 unmodified lines)class StandardRecipeWithIndexes(BaseRecipe):instruction_card_index: int = Nonetemplate_card_index: int = None11 unmodified linesself.instruction = self.card.instructions[int(self.instruction_card_index)]super().prepare()class StandardRecipe(StandardRecipeWithIndexes):"""This class represents a standard recipe for data processing and preperation.This class can be used to prepare a recipewith all necessary steps, refiners and renderers included. It allows to set variousparameters and steps in a sequential manner for preparing the recipe.Attributes:card (TaskCard): TaskCard object associated with the recipe.template (Template, optional): Template object to be used for the recipe.instruction (Instruction, optional): Instruction object to be used for the recipe.format (ICLFormat, optional): ICLFormat object to be used for the recipe.train_refiner (StreamRefiner, optional): Train refiner to be used in the recipe.max_train_instances (int, optional): Maximum training instances for the refiner.validation_refiner (StreamRefiner, optional): Validation refiner to be used in the recipe.max_validation_instances (int, optional): Maximum validation instances for the refiner.test_refiner (StreamRefiner, optional): Test refiner to be used in the recipe.max_test_instances (int, optional): Maximum test instances for the refiner.demos_pool_size (int, optional): Size of the demos pool.num_demos (int, optional): Number of demos to be used.demos_pool_name (str, optional): Name of the demos pool. Default is "demos_pool".demos_taken_from (str, optional): Specifies from where the demos are taken. Default is "train".demos_field (str, optional): Field name for demos. Default is "demos".sampler (Sampler, optional): Sampler object to be used in the recipe.steps (List[StreamingOperator], optional): List of StreamingOperator objects to be used in the recipe.instruction_card_index (int, optional): Index of instruction card to be usedfor preparing the recipe.template_card_index (int, optional): Index of template card to be used forpreparing the recipe.Methods:prepare(): This overridden method is used for preparing the recipeby arranging all the steps, refiners, and renderers in a sequential manner.Raises:AssertionError: If both template and template_card_index, or instruction and instruction_card_indexare specified at the same time."""pass
standard.py+79-5