Upload standard.py with huggingface_hub
Browse files2 unmodified lines34567894 unmodified lines14151617181911 unmodified lines313233343536378 unmodified lines46474849505183 unmodified lines13513613713813914019 unmodified lines16016116216316416516610 unmodified lines1771781791801811821838 unmodified lines1921931941951961971981992002012022032042052062072088 unmodified lines2172182192202212222237 unmodified lines2312322332342352367 unmodified lines2442452462472482492502512 unmodified linesfrom .card import TaskCardfrom .dataclass import Field, InternalField, OptionalFieldfrom .formats import Format, SystemFormatfrom .instructions import EmptyInstruction, Instructionfrom .logging_utils import get_loggerfrom .operator import SourceSequentialOperator, StreamingOperatorfrom .operators import (4 unmodified linesfrom .recipe import Recipefrom .schema import ToUnitxtGroupfrom .splitters import Sampler, SeparateSplit, SpreadSplitfrom .templates import Templatelogger = get_logger()11 unmodified linesclass BaseRecipe(Recipe, SourceSequentialOperator):card: TaskCardtemplate: Template = Noneinstruction: Instruction = Field(default_factory=EmptyInstruction)format: Format = Field(default_factory=SystemFormat)loader_limit: int = None8 unmodified linesdemos_pool_size: int = Nonenum_demos: int = 0demos_pool_name: str = "demos_pool"demos_taken_from: str = "train"83 unmodified linesfrom_split=self.demos_taken_from,to_split_names=[self.demos_pool_name, self.demos_taken_from],to_split_sizes=[int(self.demos_pool_size)],))19 unmodified linessampler=self.sampler,))self.steps.append(self.instruction)self.steps.append(self.format)if self.augmentor.augment_model_input:self.steps.append(self.augmentor)10 unmodified linesclass StandardRecipeWithIndexes(BaseRecipe):instruction_card_index: int = Nonetemplate_card_index: int = Nonedef prepare(self):8 unmodified linesself.template = self.card.templates[self.template_card_index]except Exception as e:if isinstance(self.card.templates, dict):options = self.card.templates.keys()else:options = list(range(0, len(self.card.templates)))raise ValueError(f"card_template_index '{self.template_card_index}' is not in card. Available options: {options}") from eassert (self.instruction_card_index is None or self.instruction is None), "Specify either instruction or instruction_card_index"if self.instruction_card_index is not None:self.instruction = self.card.instructions[int(self.instruction_card_index)]super().prepare()8 unmodified linesAttributes: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.loader_limit (int, optional): Specifies the maximum number of instances per stream to be returned from the loader (used to reduce loading time in large datasets)format (SystemFormat, optional): SystemFormat object to be used for the recipe.train_refiner (StreamRefiner, optional): Train refiner to be used in the recipe.7 unmodified linesdemos_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.augmentor (Augmentor) : Augmentor to be used to pseudo randomly augment the source text7 unmodified linesby 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."""pass2 unmodified lines3456784 unmodified lines1314151617181911 unmodified lines313233343536378 unmodified lines4647484950515283 unmodified lines13613713813914014114219 unmodified lines16216316416516616716810 unmodified lines1791801811821831848 unmodified lines1931941951961971981992002012022032048 unmodified lines2132142152162172182197 unmodified lines2272282292302312322337 unmodified lines2412422432442452462472 unmodified linesfrom .card import TaskCardfrom .dataclass import Field, InternalField, OptionalFieldfrom .formats import Format, SystemFormatfrom .logging_utils import get_loggerfrom .operator import SourceSequentialOperator, StreamingOperatorfrom .operators import (4 unmodified linesfrom .recipe import Recipefrom .schema import ToUnitxtGroupfrom .splitters import Sampler, SeparateSplit, SpreadSplitfrom .system_prompts import EmptySystemPrompt, SystemPromptfrom .templates import Templatelogger = get_logger()11 unmodified linesclass BaseRecipe(Recipe, SourceSequentialOperator):card: TaskCardtemplate: Template = Nonesystem_prompt: SystemPrompt = Field(default_factory=EmptySystemPrompt)format: Format = Field(default_factory=SystemFormat)loader_limit: int = None8 unmodified linesdemos_pool_size: int = Nonenum_demos: int = 0demos_removed_from_data: bool = Truedemos_pool_name: str = "demos_pool"demos_taken_from: str = "train"83 unmodified linesfrom_split=self.demos_taken_from,to_split_names=[self.demos_pool_name, self.demos_taken_from],to_split_sizes=[int(self.demos_pool_size)],remove_targets_from_source_split=self.demos_removed_from_data,))19 unmodified linessampler=self.sampler,))self.steps.append(self.system_prompt)self.steps.append(self.format)if self.augmentor.augment_model_input:self.steps.append(self.augmentor)10 unmodified linesclass StandardRecipeWithIndexes(BaseRecipe):template_card_index: int = Nonedef prepare(self):8 unmodified linesself.template = self.card.templates[self.template_card_index]except Exception as e:if isinstance(self.card.templates, dict):options = list(self.card.templates.keys())else:options = list(range(0, len(self.card.templates)))raise ValueError(f"card_template_index '{self.template_card_index}' is not defined in card. Possible card_template_index options: {options}") from esuper().prepare()8 unmodified linesAttributes:card (TaskCard): TaskCard object associated with the recipe.template (Template, optional): Template object to be used for the recipe.system_prompt (SystemPrompt, optional): SystemPrompt object to be used for the recipe.loader_limit (int, optional): Specifies the maximum number of instances per stream to be returned from the loader (used to reduce loading time in large datasets)format (SystemFormat, optional): SystemFormat object to be used for the recipe.train_refiner (StreamRefiner, optional): Train refiner to be used in the recipe.7 unmodified linesdemos_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".demos_removed_from_data (bool, optional): whether to remove the demos from the source data, Default is Truesampler (Sampler, optional): Sampler object to be used in the recipe.steps (List[StreamingOperator], optional): List of StreamingOperator objects to be used in the recipe.augmentor (Augmentor) : Augmentor to be used to pseudo randomly augment the source text7 unmodified linesby arranging all the steps, refiners, and renderers in a sequential manner.Raises:AssertionError: If both template and template_card_index are specified at the same time."""pass
standard.py+10-14