Download instructions.py from unitxt/data: direct link, hf CLI and curl.
- Browser
- Download file 1.5 kB
-
https://huggingface.co/datasets/unitxt/data/resolve/c5dfd57b4e6d1eef1483348bf44cf5bf0f48dcb0/instructions.py
- Command line
-
hf download hf://datasets/unitxt/data@c5dfd57b4e6d1eef1483348bf44cf5bf0f48dcb0/instructions.py
-
curl -L -o instructions.py https://huggingface.co/datasets/unitxt/data/resolve/c5dfd57b4e6d1eef1483348bf44cf5bf0f48dcb0/instructions.py
1.5 kB
| from abc import abstractmethod | |
| from typing import Any, Dict, Optional | |
| from .collections import ListCollection | |
| from .dataclass import NonPositionalField | |
| from .operator import StreamInstanceOperator | |
| class Instruction(StreamInstanceOperator): | |
| """The role of instruction is to add instruction to every instance. | |
| Meaning the instruction is taking the instance and generating instruction field for it. | |
| """ | |
| skip_rendered_instance: bool = NonPositionalField(default=True) | |
| def process( | |
| self, instance: Dict[str, Any], stream_name: Optional[str] = None | |
| ) -> Dict[str, Any]: | |
| if self.skip_rendered_instance: | |
| if "instruction" in instance: | |
| return instance | |
| instance["instruction"] = self.get_instruction(instance) | |
| return instance | |
| def get_instruction(self, instance: Dict[str, object]) -> str: | |
| pass | |
| class TextualInstruction(Instruction): | |
| text: str | |
| def get_instruction(self, instance: Dict[str, object]) -> str: | |
| return self.text | |
| class EmptyInstruction(Instruction): | |
| def get_instruction(self, instance: Dict[str, object]) -> str: | |
| return "" | |
| class InstructionsList(ListCollection): | |
| def verify(self): | |
| for instruction in self.items: | |
| assert isinstance(instruction, Instruction) | |
| class InstructionsDict(Dict): | |
| def verify(self): | |
| for _key, instruction in self.items(): | |
| assert isinstance(instruction, Instruction) | |