AlpacaInstructTemplate¶
- class torchtune.data.AlpacaInstructTemplate[source]¶
Prompt template for Alpaca-style datasets. Template prompt changes slightly depending on if there’s an instruction + input or just an instruction.
Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request. ### Instruction: <YOUR INSTRUCTION HERE> ### Input: <YOUR INPUT HERE> ### Response:
Or without ‘input’
Below is an instruction that describes a task. Write a response that appropriately completes the request. ### Instruction: <YOUR INSTRUCITON HERE> ### Response:
- classmethod format(sample: Mapping[str, Any], column_map: Optional[Dict[str, str]] = None) str [source]¶
Generate prompt from instruction and input.
- Parameters:
Examples
>>> # Simple instruction >>> AlpacaInstructTemplate.format(sample={"instruction": "Write a poem"}) Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a poem\n\n### Response:\n
>>> # Instruction with input >>> AlpacaInstructTemplate.format(sample={"instruction": "Write a poem", "input": "The poem should be 5 lines long"}) Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a poem\n\n### Input:\n The poem should be 5 lines long\n\n### Response:\n
>>> # Instruction with column map where the 'instruction' key is actually named 'prompt' in the given sample >>> AlpacaInstructTemplate.format(sample={"prompt": "Write me a poem"}, column_map={"instruction": "prompt"}) Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a poem\n\n### Response:\n
- Returns:
The formatted prompt