Shortcuts

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:
  • sample (Mapping[str, Any]) – a single data sample with instruction

  • column_map (Optional[Dict[str, str]]) – a mapping from the expected placeholder names in the template to the column names in the sample. If None, assume these are identical.

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

Docs

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources