skip to content

In prompt tuning, how do you choose the number of virtual tokens, and when does text or random initialization matter?

level: middleimportance: nice to knowfreq 18%

answer

  1. a dev-set choice, not a formula
  2. gains flatten, then can drop
  3. harder tasks wanted longer
  4. small data magnifies the start
  5. the largest model forgave most

basics

~20 s

Treat token count as a dev-set choice, because the best length varied by task and model size. Initialization mattered mostly on smaller models and small datasets, where published runs saw random starts lag real-word starts.

solid answer

~50 s

Both are tuning choices, and the published answers depend on model size and task. On length, Lester et al. (2021) saw one token do well at about 11 billion parameters, while most smaller models needed more, with marginal gains past 20. The P-tuning v2 paper reports simple classification preferring under 20 and hard token-labelling tasks around 100. Li and Liang (2021) saw longer prefixes lower training loss yet score slightly worse on test data, which suggests overfitting. So sweep a few lengths on a dev set and keep the shortest that holds up. On initialization, Lester et al. found class-label starts best, with the gap vanishing at their largest model. Li and Liang found real-word starts significantly better than random with little data. Qin and Eisner (2021), probing factual knowledge, found random nearly as good. So start from text or class labels when the model or dataset is small; at very large scale, expect less difference.

go deeper

for a junior

Recall that these are the two knobs a learned soft prompt has before training: the number of virtual tokens and the starting values. Know the options: random, vocabulary, class labels and text.

for a middle

Explain the shape of the published results: gains flatten with length, hard tasks want more, and initialization matters most on small models and small data. Quote each with its study's scope.

for a senior

Describe a sweep you would actually pay for: a few lengths, a few seeds, representative tasks rather than all of them, and a held-out check. Name overfitting as what a longer prompt can buy.

for a principal

Decide what a platform fixes as a default and what stays per task. A shared default length saves sweep cost, and a task that misses its bar is the one that earns its own sweep.

## Two choices, both tuning choices A learned soft prompt needs two decisions before training starts: how many **virtual tokens** to create, and what values those vectors begin with. The count sets the trainable parameters, `tokens x embedding width`. The initialization sets where optimization starts. Neither has a universal value, so the useful answer is what was measured, at what scale, and how to pick for your task. ## How many virtual tokens - **Too few can fail.** Lester et al. (2021) tested 1, 5, 20, 100 and 150 tokens and found that for most model sizes, going beyond one token was critical. Their largest model, about 11 billion parameters, gave strong results even with one. - **Gains flatten.** In the same study, going past 20 tokens gave marginal gains across all models, and going past 100 looked mildly detrimental on larger ones. - **Task difficulty moves the answer.** The P-tuning v2 paper (Liu et al., 2021) reports that simple classification generally preferred fewer than 20 tokens, while hard sequence labelling preferred around 100. - **Too many can overfit.** Li and Liang (2021) saw performance rise to a threshold, 200 for summarization and 10 for table-to-text, then drop slightly. Past it, training loss was lower and test performance slightly worse. - **Little data makes it sharper.** Liu et al. (2021), in their few-shot experiments, found the count had a great impact and that more was not always better. They suggest searching for it through model selection. Li and Liang also report a negligible effect of longer prefixes on inference speed, so in their setup speed was not the constraint. Each virtual token does take an input position, which matters on a tight input budget. ## What the vectors can start from | Start | How it works | Used by | |---|---|---| | Random | Values drawn at random, in Lester et al. uniformly from -0.5 to 0.5 | Lester et al.; Qin and Eisner | | Sampled vocabulary | Embeddings of common tokens | Lester et al. | | Class labels | Embeddings of the output label strings | Lester et al. | | Text | Embeddings of a short task instruction or related words | Li and Liang; Qin and Eisner start from existing prompts | With class labels you often run out of labels before tokens, and Lester et al. fill the rest with sampled vocabulary. One open-source implementation of text initialization truncates or repeats the text's tokens until they fit the count. ## When initialization matters - **Lester et al.:** class-label starts did best, with large gaps at small model sizes that disappeared at their largest model. - **Li and Liang:** a large impact in low-data settings. Random gave low performance with high variance, real words did significantly better, and task-relevant words did slightly better than irrelevant ones. - **Qin and Eisner (2021):** on factual knowledge probing, random was nearly as good as informed starts, though their winning system on one benchmark started from mined prompts. The three are not in conflict once you read their scope: model size, data volume and task differ. A smaller model or a small labelled set is where a word-like start has paid; a very large model has forgiven most choices. ## What text initialization does not do The text is a starting point. Training moves the vectors, and the result need not decode to that text. Lester et al. did find class labels often persist among a trained token's nearest vocabulary neighbours, but beyond that they did not find the prompts interpretable. Nor does a text start make the vectors portable: they are still fitted to one model. ## A sweep for a dozen narrow tasks A reasonable plan for this team's illustrative case, as common practice and not a published recipe: 1. Pick two representative tasks, one classification and one extraction. 2. Fix a start: class labels for classification, a short written instruction for extraction. 3. Train 5, 20 and 100 tokens with three seeds each: 2 x 3 x 3 = 18 runs, against 108 for all twelve tasks. 4. Compare on the dev set and keep the shortest length within noise of the best. 5. Confirm the winner on held-out data, use that length as the default for the other ten tasks, and re-sweep only the ones that miss their bar.

  • Why might a longer soft prompt score worse when it has more capacity?
    Li and Liang (2021) saw longer prefixes reach lower training loss with slightly worse test performance, which suggests overfitting. Lester et al. (2021) also found several tokens in long prompts sharing the same nearest neighbours, and read that as either excess capacity or difficulty localizing information to a position. More vectors stop helping once the task's signal is captured.
  • What do you do with class-label initialization when labels are multi-token or free-form?
    Lester et al. (2021) average the embeddings of a multi-token label into one vector. When they run out of labels before tokens, they fill the rest from sampled vocabulary. For tasks that generate short free-form text, they start from words related to the task. All of it is only a start: training then moves those vectors.

  • Use as many virtual tokens as you can afford, because more capacity always scores better.
  • A soft prompt initialized from text keeps that text and can be read back.
  • Random initialization is always fine, because backpropagation erases the starting point.
  • Text initialization always wins, whatever the model size or the amount of data.
  • Longer prefixes are ruled out because they slow inference badly.