GPT-1 was pre-trained on plain running text, but many tasks give it structured input: a sentence pair, or a document with a question and several answers. Instead of adding task-specific layers, the paper rewrites each input as token sequences the pre-trained model can read, and puts a single linear layer on top. Build those sequences and the output distribution for each task.
Every sequence starts with a start token and ends with an extract token; the model's final activation at the extract token represents the sequence. Parts are separated by a delim token. All tokens are integer ids and every text field is a list of ids.
build_inputs(task, fields, start, delim, extract) returns a list of sequences:
"classification", fields text: one sequence [start] + text + [extract];"entailment", fields premise, hypothesis: one sequence with the premise, delim, then the hypothesis;"similarity", fields a, b: two sequences, a, delim, b and then b, delim, a, in that order;"multiple_choice", fields context, question, answers (a list of id lists): one sequence per answer, in order: the context followed directly by the question, then delim, then that answer.Any other task raises ValueError.
task_distribution(task, fields, encode, W_y, start, delim, extract) returns the model's output probabilities as a list of floats rounded to 4 decimals. encode(seq) stands in for the pre-trained transformer and returns the final activation at the extract token, a vector of length .
(d,) or (d, 1)) and gives each answer's sequence one score ; a soft-max over the answers gives one probability per answer.