Upload standard.py with huggingface_hub
Browse files2 unmodified lines34566784 unmodified lines1314151617181911 unmodified lines31323334343536378 unmodified lines4647484950515283 unmodified lines13613713813914014114219 unmodified lines16216316416316516616716810 unmodified lines1791801811801821831848 unmodified lines1931941951951961971981991992002012012022032042052022032048 unmodified lines2132142152202162172182197 unmodified lines2272282292302312322337 unmodified lines2412422432472482442452462472 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 .system_prompts import EmptySystemPrompt, SystemPromptfrom .templates import Template
logger = get_logger()11 unmodified linesclass BaseRecipe(Recipe, SourceSequentialOperator): card: TaskCard template: Template = None instruction: Instruction = Field(default_factory=EmptyInstruction) system_prompt: SystemPrompt = Field(default_factory=EmptySystemPrompt) format: Format = Field(default_factory=SystemFormat)
loader_limit: int = None8 unmodified lines
demos_pool_size: int = None num_demos: int = 0 demos_removed_from_data: bool = True
demos_pool_name: str = "demos_pool" demos_taken_from: str = "train"83 unmodified lines from_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 lines sampler=self.sampler, ) ) self.steps.append(self.instruction) self.steps.append(self.system_prompt) self.steps.append(self.format) if self.augmentor.augment_model_input: self.steps.append(self.augmentor)10 unmodified lines
class StandardRecipeWithIndexes(BaseRecipe): instruction_card_index: int = None template_card_index: int = None
def prepare(self):8 unmodified lines self.template = self.card.templates[self.template_card_index] except Exception as e: if isinstance(self.card.templates, dict): options = self.card.templates.keys() 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 in card. Available options: {options}" f"card_template_index '{self.template_card_index}' is not defined in card. Possible card_template_index options: {options}" ) from e assert ( 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 lines 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. 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 lines 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". demos_removed_from_data (bool, optional): whether to remove the demos from the source data, Default is True 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 lines by 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_index are specified at the same time. AssertionError: If both template and template_card_index are specified at the same time. """
passstandard.py+10-14