Dil AI KILAVUZU

Hızlı Ayarlama

Prompt tuning adapts a frozen language model to a new task by learning a short sequence of trainable vectors, called a soft prompt, that is prepended to every input.

Bu kılavuzu dinleyinAI tarafından anlatılan · ~8 min

Bu sayfada9 min read
  1. Genel Bakış
  2. Önemli çıkarımlar
  3. Derin Dalış
  4. Training a complaint classifier with a soft prompt in Hugging Face PEFT
  5. Gerçek Dünya Uygulaması
  6. Hızlı Ayarlamanın Geleceği
  7. Uygulamaya koymak
  8. Kaynaklar ve ek okuma
  9. Keşfetmeye Devam Edin
  10. Sık sorulan sorular

Genel Bakış

Only those vectors change during training, so one shared model can serve many tasks while each task stores a few thousand numbers instead of a full copy of the model.

Önemli çıkarımlar

  1. Prompt tuning trains only a short matrix of virtual-token embeddings that is prepended to the input, while every weight of the language model stays frozen.
  2. The 2021 Google paper by Lester, Al-Rfou and Constant showed prompt tuning matches full fine-tuning on SuperGLUE once T5 models reach about 11 billion parameters.
  3. A five-token soft prompt on T5-XXL holds 20,480 parameters, compared with 11 billion for a fully fine-tuned copy of the same model.
  4. Prompt tuning beat full fine-tuning on most out-of-domain question-answering tests in the original study, including a 12.5-point F1 gain on TextbookQA.
  5. On models smaller than about a billion parameters, deeper variants such as prefix tuning and P-Tuning v2 usually work better than input-only soft prompts.

Derin Dalış

Prompt tuning is a way to teach an existing language model a new job without changing the model itself. A normal text prompt is a string of words, such as "Classify the sentiment of this review". A soft prompt is different: it is a short list of numeric vectors that live in the same space as the model's word embeddings (the vectors the model uses to represent each token), but they do not have to correspond to any real word. The model's billions of weights stay frozen. Training adjusts only the soft prompt, using ordinary gradient descent on labeled examples, until the frozen model produces the right outputs when the prompt sits in front of each input.

The mechanism has four steps. First, choose a prompt length p, typically between 5 and 100 virtual tokens, and create a matrix of p vectors, each with the same width e as the model's embeddings. Second, initialize those vectors, either randomly, by copying embeddings of common vocabulary words, or by copying embeddings of the class label words such as "positive" and "negative". Third, for each training example, convert the input text to embeddings as usual, concatenate the prompt matrix in front of them, and run the frozen model forward. Fourth, compute the task loss on the model's output and backpropagate it only into the prompt matrix. At inference time the learned prompt is attached to new inputs in exactly the same way. Because the prompt is the only task-specific artifact, a single deployed model can handle many tasks by swapping prompts per request.

The technique was introduced by Brian Lester, Rami Al-Rfou and Noah Constant of Google in "The Power of Scale for Parameter-Efficient Prompt Tuning", submitted to arXiv in April 2021 and published at EMNLP 2021. Its central finding is about scale. Using T5 models from small to XXL (11 billion parameters), the authors showed that prompt tuning lags behind full fine-tuning on small models but closes the gap as models pass a few billion parameters. They also report that GPT-3's few-shot prompting scored 71.8 on SuperGLUE against 89.3 for a fine-tuned T5-XXL, even though GPT-3 is 16 times larger. Google's February 2022 research blog summarizes the headline: on T5-XXL, prompt tuning matches model tuning while training about 20,000 parameters to steer an 11-billion-parameter model.

The paper's ablations give practical guidance. Lengthening the prompt beyond about 20 tokens generally gave only small gains, and the XXL model still gave strong results with a single-token prompt. Initializing from class-label embeddings beat random initialization on small and medium models, but the difference vanished at XXL size. A surprising detail concerned pretraining: T5's original span-corruption objective, where the model fills in masked spans with sentinel tokens, made frozen models poor prompt targets. The authors continued training T5 1.1 checkpoints with a plain language-modeling objective for up to 100,000 steps and released these "LM-adapted" checkpoints, which became the standard starting point for prompt-tuning experiments.

Prominent alternatives sit on a spectrum of how much of the model they touch. Prompt design, or hand-written prompting, trains nothing and relies on the model following instructions and a few examples. Prefix tuning, proposed by Xiang Lisa Li and Percy Liang in January 2021, learns continuous vectors that are inserted at every transformer layer rather than only at the input, training about 0.1% of the parameters of GPT-2 and BART. P-Tuning v2, by Xiao Liu and colleagues at Tsinghua (ACL 2022), applies deep prompts to every layer and reports matching fine-tuning across model sizes and harder tasks such as sequence labeling, with 0.1% to 3% of parameters tuned. LoRA, from Microsoft researchers in June 2021, instead adds small low-rank matrices to the weight updates and reports 10,000 times fewer trainable parameters than full fine-tuning of GPT-3 175B. Full fine-tuning updates every weight and usually gives the strongest per-task result, at the cost of storing a full model copy for each task.

The main appeal is robustness and economy. Lester and colleagues trained on SQuAD and tested on out-of-domain question-answering datasets from the MRQA 2019 shared task; prompt tuning beat full fine-tuning on most of them, with a 12.5-point F1 gap on TextbookQA. Transferring a paraphrase detector from the QQP dataset to MRPC, prompt tuning scored 76.3% accuracy against 73.1% for full fine-tuning. The authors interpret this as evidence that freezing the model limits overfitting to quirks of the training set. Storage is the other benefit: with a five-token prompt on T5-XXL, each task needs 20,480 parameters instead of another 11-billion-parameter copy, which the paper notes takes 42 GiB on disk.

The method has clear limits. On models below roughly a billion parameters, plain prompt tuning trails full fine-tuning by a wide margin on SuperGLUE, which is why P-Tuning v2 and prefix tuning add trainable vectors at deeper layers. Training can be slow to converge and sensitive to learning rate; the Google work used a learning rate of 0.3, far higher than typical fine-tuning rates. Learned prompts are hard to interpret, since their vectors rarely match real words; the paper found nearest-neighbor words formed loose semantic clusters, not readable instructions. Prompts also consume context: every virtual token occupies a position the input could have used. Finally, a prompt is tied to the exact model it was trained on, so upgrading the base model means retraining every prompt.

In practice the costs are modest. Training requires a forward and backward pass through the full frozen model, so GPU memory for activations is similar to fine-tuning, but optimizer state is needed only for the prompt, which removes most of the memory for gradients and Adam statistics. Hugging Face's PEFT library exposes the method through a PromptTuningConfig object where the user sets the number of virtual tokens and the initialization, either random, sampled vocabulary or a text string. Its documented example on a 559-million-parameter BLOOMZ model trains 8,192 parameters, about 0.0015% of the total, and the resulting checkpoint is a few kilobytes.

04Çalışılan örnek

Training a complaint classifier with a soft prompt in Hugging Face PEFT

  1. Load a small causal language model such as bigscience/bloomz-560m and its tokenizer with the transformers library.

  2. Create a PromptTuningConfig with task_type CAUSAL_LM, prompt_tuning_init set to TEXT and an initialization string such as 'Classify if the tweet is a complaint or no complaint.'

  3. Set num_virtual_tokens to the token length of that string so every virtual token starts from a real word embedding.

  4. Wrap the model with get_peft_model and call print_trainable_parameters to confirm only a few thousand parameters are trainable.

  5. Format each labeled tweet as input text followed by the label word, then train for a few epochs with a relatively high learning rate.

  6. Save the adapter, which writes only the prompt matrix, and reload it on top of the untouched base model for inference.

Ne gösteriyor?

The saved adapter is a few kilobytes and contains roughly 8,192 numbers. Check it by generating labels for held-out tweets and comparing accuracy with an untuned base model given the same text prompt.

Gerçek Dünya Uygulaması

Google's 2021 study tuned soft prompts on a frozen T5-XXL model with 11 billion parameters and matched full fine-tuning on the SuperGLUE language-understanding benchmark while training a tiny fraction of the weights.

A support team can train one soft prompt to classify tweets as complaints or not complaints on bigscience/bloomz-560m using Hugging Face PEFT, which reports about 8,192 trainable parameters against 559 million in the base model.

A service hosting many customers can keep one frozen model in memory and batch requests from different tasks together, swapping only the small prompt matrix attached to each request.

Researchers built cheap ensembles by training five prompts for the same SuperGLUE task on a single frozen T5-XXL and taking a majority vote, which beat the average single prompt on every task.

The SPoT method from Google (ACL 2022) first learns a prompt on source tasks and reuses it to initialize a prompt for a new target task, matching or beating full fine-tuning on SuperGLUE.

Hızlı Ayarlamanın Geleceği

Research since 2021 has focused on making soft prompts reusable and less dependent on model scale. SPoT (Vu and colleagues, ACL 2022) showed that a prompt learned on one or more source tasks can initialize a prompt for a new task, and its study covered 26 NLP tasks in 160 source and target combinations, reporting results that match or beat full fine-tuning on SuperGLUE with up to 27,000 times fewer task-specific parameters. P-Tuning v2 (ACL 2022) extended competitive results to smaller models by adding prompts at every layer. Open problems remain. Soft prompts are tied to one base model, so transferring them across model versions or architectures is an active question. Interpretability is limited because learned vectors rarely map to words. In industry, low-rank methods such as LoRA (2021) have become the more common choice for adapting open models, partly because their weights merge into the base model and add no inference tokens, while prompt tuning remains attractive where many tasks must share a single frozen model in one batch. Whether newer, larger models make soft prompts even more competitive, as the 2021 scaling result suggests, is still being studied on current architectures.

Uygulamaya koymak

Neden önemli?

  • Hız ve ölçek. Dil iş akışları tutarlılıktan ödün vermeden daha hızlı ilerleyebilir.
  • Erişim ve erişim. Diller ve iletişim tarzları arasında erişimi genişletir.
  • Daha net kararlar. Otomasyon tekrarlamayı yönetirken ekipler karar vermeye daha fazla zaman ayırabilir.

Dikkat edin

  • Halüsinasyonlu gerçekler sessizce raporlara, destek akışlarına veya araştırma çıktılarına girebilir.
  • İstem hassasiyeti, benzer istekler arasında tutarsız sonuçlar yaratabilir.
  • Erişim kontrolleri zayıfsa hassas metin verileri açığa çıkabilir.

Sonraki adımlar

  1. Kullanıma sunmadan önce çıktı formatını, tonunu ve kalite standartlarını tanımlayın.
  2. Doğruluğun önemli olduğu durumlarda güvenilir kaynaklarla zemin müdahaleleri.
  3. Yüksek riskli çıktılar için insan incelemesi kontrol noktası bulundurun.
  4. Arıza modellerini takip edin ve istemleri veya iş akışlarını düzenli olarak yeniden eğitin.

Kaynaklar ve ek okuma

  1. arXiv (EMNLP 2021)The Power of Scale for Parameter-Efficient Prompt Tuning
  2. Google ResearchGuiding Frozen Language Models with Learned Soft Prompts
  3. arXiv (ACL 2021)Prefix-Tuning: Optimizing Continuous Prompts for Generation
  4. arXiv (ACL 2022)P-Tuning v2: Prompt Tuning Can Be Comparable to Fine-tuning Universally Across Scales and Tasks
  5. arXiv (ACL 2022)SPoT: Better Frozen Model Adaptation through Soft Prompt Transfer
  6. arXivLoRA: Low-Rank Adaptation of Large Language Models
  7. Hugging Face PEFT documentationPrompt tuning

Keşfetmeye Devam Edin

Ücretsiz bülten

Günlük AI brifingini alın

Hafta içi her sabah sade İngilizce yazılmış, doğrulanmış üç yapay zeka hikayesi. Sonsuza kadar ücretsiz, reklam yok.

Hafta içi her gün bir e-posta. Tek tıklamayla aboneliğinizi iptal edin. Adresinizi asla satmayız veya paylaşmayız.

Kendinizi test edin

Take the Prompt Tuning quiz

Her yanıtla ilgili anında geri bildirim ve bir kursu geçtiğinizde doğrulanabilir bir kimliğe sahip paylaşılabilir bir sertifika.

Testi başlat

Ücretsiz AI eğitimini destekleyin. AI Understanding, bir 501(c)(3) kâr amacı gütmeyen kuruluştur; hiçbir zaman reklam yoktur, ödeme duvarı yoktur. Bağış yap

Sık sorulan sorular

Hızlı Ayarlama Nedir?

Prompt tuning adapts a frozen language model to a new task by learning a short sequence of trainable vectors, called a soft prompt, that is prepended to every input. Only those vectors change during training, so one shared model can serve many tasks while each task stores a few thousand numbers instead of a full copy of the model.

İstem ayarlamada 'yumuşak istem' nedir?

Yumuşak istemler, insan tarafından okunabilen sözcükler değil, yerleştirme alanındaki eğitilebilir sürekli vektörlerdir.

Hızlı ayarlama, eğitilebilir vektörlerini nereye ekler?

İstem ayarlama, yumuşak istemleri yalnızca girişte ekler; bu, onu önek ayarlamadan daha hafif kılan şeydir.

Orijinal makale model ölçeği hakkında hangi şaşırtıcı etkiyi vurguladı?

Makalenin başlığı 'ölçeğin gücünü' vurguluyordu: daha büyük modeller, hızlı ayarlamanın tam ince ayara rakip olmasına izin veriyor.

Hızlı ayarlamayı kim başlattı?

Google şirketinden Brian Lester, Rami Al-Rfou ve Noah Constant, 2021'de hızlı ayarlama makalesini yayınladı.

Anında ayarlama, tek bir modelden birçok görevin yerine getirilmesini nasıl mümkün kılar?

Yalnızca küçük bir geçici istem göreve özeldir, dolayısıyla donmuş bir model, istemleri değiştirerek birçok görevi barındırabilir.