CSE 587: Deep Learning for Natural
Language Processing
Lecture 7. Prompt-based Methods

Rui Zhang
Spring 2023

Many slides from Pengfei Liu and Graham Neubig

1What is Prompt?
OpenAI GPT-3 Writes Entire Articles

2

Prompt
Downstream tasks are reformulated to look more like those solved during theoriginal LM training with the help of a textual prompt. For example,●●●

Natural Language Generation. e.g., GPT-3 in the previous slides.
Sentiment Analysis:○ Input: “I love this movie.”○ Prompt: “I love this movie. It was a __ movie”.
○ Output: a sentiment word, e.g., goodMachine Translation:○ Input: “I love this movie.”○ Prompt: “English: I love this movie. French:”○ Output: the French translation
3

Workflow of Prompting●●●

Step 1: Prompt Addition
Step 2: Answer Search
Step 3: Answer Mapping4Prompt Addition
Given the input, construct the prompt following a template.

5

Example: Sentiment Analysis

6Answer Prediction
Given the prompt, predict the answer [z]7Example: Sentiment Analysis

8Answer Mapping
Given the answer, map it to a class label.

9

Example: Sentiment Analysis

10Prompts for Different Tasks

11

Prompt Engineering: Design of Prompts
Prompt engineering is the process of creating a prompting function f_prompt(x)that results in the most effective performance on the downstream task.
Manual Template Engineering● Configure the manual template based on the characteristics of the task
Automated Template Learning● Discrete Prompt: Search in discrete space● Continuous Prompt: Search in continuous space

12Automated Template Learning
Discrete Prompt: Search in discrete space● Prompt Mining● Prompt Paraphrasing● Gradient-based SearchContinuous Prompt: Search in continuous space● Prompt/Prefix Tuning

13

Prompt Mining (Jiang et al. 2020)
Middle-word Prompts Following the observation that words in the middle of thesubject and object are often indicative of the relation, we directly use those words
as prompts.

14

Prompt Mining (Jiang et al. 2020)
Middle-word Prompts Following the observation that words in the middle of thesubject and object are often indicative of the relation, we directly use those words
as prompts.
Dependency-based Prompts We parse sentences with a dependency parser
to identify the shortest dependency path between the subject and object, thenuses the phrase spanning from the leftmost word to the rightmost word in thedependency path as a prompt.

15Prompt Paraphrasing (Jiang et al. 2020)
Paraphrase an existing prompt to get other candidates, e.g. back translation withbeam search

16

Editing-based Search (Prasad et al., 2022)

17

Gradient-based Search (Shin et al. 2020)
We develop AUTOPROMPT, an automated method to create prompts for a diverse set oftasks, based on a gradient-guided search.
The trigger tokens are shared across all inputs and determined using a gradient-basedsearch.

18

Prefix Tuning (Li and Liang 2021)
Prefix-Tuning: Optimizing Continuous
Prompts for Generation
Optimize the embeddings of a prompt,instead of the words.

19

Prompt Tuning (Lester et al. 2021)

20

Prompt Tuning (Lester et al. 2021)

21

Prefix Tuning vs Prompt Tuning●●"Prefix Tuning" optimizes prefix of all layers.
"Prompt Tuning" optimizes only the embedding layer.

22Prompt-based Training Strategies

23Prompt-based Training Strategies

24How is Transformer used
We can use Transformer separately for each task.
Transformer is initialized randomly, and trained for each dataset using supervised
learning.

Sentiment Analysis

SA Data

Vanilla Transformer

Machine Translation

MT Data

Vanilla Transformer

Named Entity Recognition

NER Data

Vanilla Transformer

25

Pretraining●●●First train Transformer using a lot of general text using unsupervised learning.
This is called pretraining.
Then train the pretrained Transformer for a specific task using supervised
learning.This is called finetuning.
The whole process can be called transfer learning.

Large Corpus

Transformer

Pretraining

Sentiment Analysis

Finetuning

Machine Translation

Finetuning

Named Entity Recognition

Finetuning
26

Four Paradigms of NLP27

Fully Supervised Learning (Non-Neural Network)
Model: Logistic Regression, Decision Tree, SVM, CRF
Engineering: Feature Engineering
Time Period: Most popular through 2015
Characteristics:● Non-neural machine learning models mainly used
● Require manually defined feature extraction
Representative Work:● Manual features -> linear or kernelized support vector machine (SVM)● Manual features -> conditional random fields (CRF)28

Fully Supervised Learning (Neural Network)
Model: Neural Networks (RNN, CNN, LSTM, Transformers)
Engineering: Architecture Engineering
Time Period: About 2013-2018
Characteristics:● Rely on neural networks● Do not need to manually define features, but should modify the network structure (e.g.:LSTM v.s CNN)
● Sometimes used pre-training of LMs, but often only for shallow features such asembeddings
Representative Work
● CNN for Text Classification

29

Pretrain, Finetune
Model: Pretrained Language Models (discussed in the last lecture)Engineering: Objective Engineering
Time Period: 2017-Now
Characteristics:● Pre-trained LMs (PLMs) used as initialization of full model - both shallow and deepfeatures● Less work on architecture design, but engineer objective functions
Representative Work:● BERT → Fine Tuning30

Pretrain, Prompt, Predict
Model: Pretrained Language Models
Engineering: Prompt Engineering
Date: 2019-Now
Characteristic:● NLP tasks are modeled entirely by relying on LMs● The tasks of shallow and deep feature extraction, and prediction of the data are all
given to the LM● Engineering of prompts is requiredRepresentative Work:● GPT-331

Four Paradigms of NLP

Dashed lines suggest thatdifferent tasks can be connectedby sharing parameters ofpre-trained models.

“LM→Task”: adapting LMs(objectives) to downstream tasks.
“Task→LM”: adapting downstreamtasks (formulations) to LMs
32

Recommended Readinghttps://arxiv.org/pdf/2107.13586.pdf

33

A useful library for Prompt Engineeringhttps://github.com/thunlp/OpenPrompt34