Template-free prompt construction
Sourced from the Axolotl documentation with permission
Template-free prompt construction with the input_output
format
Background
Masking Inputs
One of the most popular features of axolotl is setting the following configuration value:
If you declare a dataset formats such as alpaca
or chatml
, axolotl knows what is an input (i.e. human) vs. an output (i.e. the assistant) and masks the input labels so that your model can focus on predicting the outputs only.
You may not want prompt templates
However, there are many situations where you don’t want to use one of these formats or templates. This is because they can:
Add unnecessary boilerplate to your prompts.
Create artifacts like special delimiters
<|im_start|>
that can quickly become footguns if you don’t include them correctly at inference time.Enforce a chat interface when you do not want one. Sometimes you just want to fine-tune a model to a very specific task and do NOT want multi-turn conversations, roles, etc.
Limit you to only certain roles that the template allows.
The input_output
format
input_output
formatYou can construct your prompts without a template by using the input_output
format, by setting type: input_output
in your configuration file like this:
config.yml
Unlike type: completion
, which is also template-free, type: input_output
allows you to mask segments of your text. More details on how this works are described below.
Usage
This is how you can use the input_output
format:
Prepare Data
To use the input_output
format, collect your data in the following format into a jsonl file (below is the first row from the file output
.jsonl` pretty printed):
Set label:false
when you want to mask a segment of text so that the model isn’t trained on it. Some things to keep in mind:
EOS, BOS, spaces, newlines etc. are entirely up to you.
Axolotl concatenates all the segments as-is.
The tokenizer doesn’t add anything additional. Notice how I added spaces, newlines, <s>
(BOS), and </s>
(EOS) myself.
Make sure you check the materialised output to validate that the prompt is getting assembled how you like.
Use type:
input_output
type:
input_output
Let’s materialise data with our output.jsonl
file by setting type: input_output
in our axolotl config:
You can use the following command to materialise your data. The --debug
flag will print the tokens, along with the labels so you can verify that the correct items are being ignored:
The format is decoded_token
(label
, token_id
), for example, <s>(1, 1)
means that the token is <s>
, the label is 1
and the token_id is 1
. When the label is -100
then that token is ignored for training.
Check the prompts
Here is another way to check the materialised output:
We can check that the right tokens are ignored by comparing the labels to each token:
0
<s>
1
1
Hello
22557
2
13
3
hi
12014
4
there
736
5
!
28808
6
.
28723
7
28705
8
good
-100
9
bye
-100
10
-100
11
fare
19111
12
well
5458
13
</s>
2
If we look at the input data, the above table seems correct!
The jsonl version is repeated below for reference:
Last updated