Scaling Up to Large Language Models
How to Model NLP Tasks?
Define the problem clearly: What specific NLP task are you trying to solve? (e.g., sentiment analysis, question answering, machine translation, code generation).
Analyze the data for challenges:
Multilingual? Does it involve multiple languages?
Dialectal? Does it contain variations within a language?
Domain-specific? Is the language from a particular field (e.g., medical, legal)?
Conversational? Is it informal, with slang and colloquialisms?
Chronological? Does the order of the data matter (e.g., time-series data)?
Core: What is your input/output? What machine learning algorithms are applicable?
Data Size and Quality:
How much data is available? Is it labeled?
Is it clean and well-formatted? If not, what preprocessing techniques are applicable?
Select an appropriate model architecture (e.g., sequence-to-sequence, classification/regression).
Select appropriate approaches given data (e.g., fine-tuning with labeled data / continual pre-training for unlabeled data).
Identify suitable metrics for both implicit (e.g., training/validation loss, perplexity) and explicit evaluation.
e.g., AUROC, Precision, Recall, F1, Spearman/Pearson’s Correlation, BLEU, ROUGE, BERTScore, TER.
To be explained in Lecture 9 on Evaluating model performance comprehensively.
Example: Categorizing customer feedback from an online retail platform.
Customer feedback is a written statement and a review on a scale of 1-5 stars; categories can be positive, negative, or neutral.
NLP Research Background
Modeling NLP tasks, following NLP research, and publishing your research.
The NLP Research Community
Research papers on ACL Anthology – 93k+ papers!
Search for relevant areas by:
Topic (to learn which methods are applied).
Method (to learn which topics it is applied to).
Great way to learn about current topics and ongoing research and a good archive of NLP papers.
ACL Anthology data is also used by research.
Task Example: Given research papers, authors, paper metadata (including links to codebase) and presentation video, what tasks are possible?
Research Papers
Most NLP papers are published as 9-page conference papers (long papers) with 3 reviewers (double blind review process).
Other types of papers:
Short papers (5 pages).
Findings papers.
Systems demo track.
Industry track.
Journal papers (up to 12 pages, or unlimited).
Survey Papers [e.g., IJCAI Survey track].
Venues: ACL, EMNLP, NAACL, EACL, AACL, COLING, LREC, AAAI, IJCAI, NeurIPS, ICLR, CVPR, ECCV, Interspeech, IWSLT, and various other conferences and workshops.
NLP Research Tracks
Machine Learning for NLP
Interpretability & Analysis of Models for NLP
Resources & Evaluation
Ethics & NLP
Phonology, Morphology & Word Segmentation
Syntax: Tagging, Chunking & Parsing
Semantics: Lexical
Semantics: Sentence-level Semantics, Textual Inference & Other areas
Linguistic Theories, Cognitive Modeling & Psycholinguistics
Information Extraction
Information Retrieval & Text Mining
Question Answering
Summarization
Machine Translation & Multilinguality
Speech & Multimodality
Discourse & Pragmatics
Sentiment Analysis, Stylistic Analysis, & Argument Mining
Dialogue & Interactive Systems
Language Grounding to Vision, Robotics & Beyond
Computational Social Science & Cultural Analytics
NLP Applications
Often Special themes are introduced.
Follow NLP Research
arXiv papers.
Twitter accounts.
NLP researchers with active accounts (grad students, profs, industry folks).
Official conference accounts.
“NLP Highlights” podcast.
“NLP News” newsletter, ‘NLP People’ (https://nlppeople.com/jobs/).
Huggingface, Microsoft Research, Google DeepMind, Meta AI (FAIR), Amazon, AI4Bharat, eBay Research, NVIDIA Research, academic labs (StanfordNLP, MBZUAI, CFILT@IITB, SurreyNLP) and many startups (Cohere, Anthropic).
How to Begin NLP Research
Find a relevant problem and identify recent research.
Find good or popular tools:
Identify papers, ask around, search the web.
Trying to identify the best tool for your job:
Produces appropriate, sufficiently detailed output?
Accurate? (on the measure you care about).
Robust? (accurate on your data, not just theirs).
Fast?
Easy and flexible to use? Nice file formats, command line options, visualization?
Trainable for new data and languages? How slow is training?
Open-source and easy to extend?
Shared Tasks
Dijkstra would participate in a shared task ☺
Competitions organized by research community which invite participation.
Components:
Training data (optional).
Development data (optional).
Test data, for evaluating the final participating systems.
Evaluation metric(s) (how well does the system perform).
Additional Training/Synthetic data (optional).
A prize (optional; with clear rules on what data can be used).
Easy to write system description paper.
Large Language Models (LLMs)
Natural Language Processing (NLP)
'Understand’ Human Language
A key goal of NLP research is to ensure that machines understand human language.
Analyse Human Language
Textual analytics, extraction, and retrieval to analyze the information present in human language.
Generate Human Language
Generation of understandable human language to interface with people.
Different Types of Attention
Diagram illustrating encoder-decoder architecture with self-attention and masked self-attention.
Pre-trained Transformer Flavors
Encoders
Examples: BERT, RoBERTa, SciBERT.
Captures bidirectional context.
Decoders
Examples: GPT-2, GPT-3, LaMDA
Also known as: causal or auto-regressive language model
Natural if the goal is generation, but cannot condition on future words
Encoder-Decoders
Examples: BART, T5, Meena
Conditional generation based on an encoded input
Autoregressive Decoders
A non-auto-regressive model:
Inputs and outputs are different.
Use case: Assigning labels for each word (e.g., part-of-speech tagging).
A “causal” or an auto-regressive model:
Each output is the next input in the sequence.
Use case: Generating tokens (e.g., language modeling).
The GPT Family
GPT (2018): 117 million parameters - Improving Language Understanding by Generative Pre-Training.
GPT-2 (2019): 1.5 billion parameters - Language Models are Unsupervised Multitask Learners.
GPT-3 (2020): 175 billion parameters - Language Models are Few-Shot Learners; NeurIPS 2020 best paper.
GPT Anatomy
An autoregressive model that predicts the next token given tokens so far (either predicted or given as part of input).
Masked Self-Attention (Decoders)
Masks future tokens by interfering in the self-attention calculation, blocking information from tokens to the right of the position being calculated.
Prevents positions from 'peeking' at tokens to its right.
Decoder-only (block)
As it processes each subword, it masks the “future” words and conditions on (i.e., attends to) the previous words.
Decoder Stack
Diagram illustrating token embeddings and decoder layers.
Pre-training Decoder Stack
Language models generate text by predicting the next token given a prompt.
Formally, given a prompt (input) , where is a token at the i-th index.
A causal language model (autoregressive decoder) estimates the probability of the next token as , where is the parameter of the language model.
Models are trained using causal language modeling loss:
, where T is the total number of tokens in a sequence.
During inference (generation), given a prompt x, the model generates new tokens by sampling
Model Inference based on the probability distribution of the vocabulary given the preceding tokens.
How do such models decode?
Pick an output token based on its probability (sample).
Sampling Techniques
Using various sampling techniques!
For instance, top-k and top-p are most commonly used!
Top-k sampling
Probabilities for all possible next tokens are generated and sorted in descending order.
Only the top-k tokens are considered for the next step.
A token is then randomly sampled from this reduced set based on their probabilities.
Lower k: more focused and deterministic output, as the model has fewer options.
Higher k: introduces more randomness and creativity, as a wider range of potential tokens is considered.
In essence, “choosing the next word from the top-k suggestions”.
Top-p (nucleus) sampling
Selects the smallest set of most probable tokens whose cumulative probability exceeds a threshold p.
The cumulative probability is calculated as you go down the list.
Once the cumulative probability reaches or exceeds p, the remaining lower-probability tokens are discarded.
The next token is then randomly sampled from this nucleus of tokens.
Lower p: more focused and coherent output, as only the most likely tokens remain.
Higher p: allows for more diverse and surprising output, as a larger set of tokens becomes eligible for sampling.
In essence, "choosing the next word from a set of suggestions that together make up a certain level of confidence (prob.)“.
Combining top-k and top-p sampling
Apply top-k to narrow down the candidate set, then apply top-p to this reduced set.
The first GPT (or GPT-1)
Illustrations of GPT-1 architecture for various tasks (Classification, Entailment, Similarity, Multiple Choice).
Emergent abilities of large language models: GPT (2018)
GPT (117M parameters; Radford et al., 2018)
Transformer decoder with 12 layers.
Trained on BooksCorpus: over 7000 unique books (4.6GB text).
Showed that language modeling at scale can be an effective pretraining technique for downstream tasks like natural language inference.
Example: [START] The man is in the doorway [SEP] The person is near the door [EXTRACT]
GPT-2
GPT-2 is quite identical to GPT-1, but:
Layer norm moved to the input of each sub-block.
Vocabulary extended to 50,257 tokens and context size increased from 512 to 1024.
Trained on 8 million docs from the web (Common Crawl), minus Wikipedia.
https://huggingface.co/gpt2
Lab Assignment: Train your own GPT-2 from scratch on the “Tiny-Shakespeare” dataset, utilizing some pre-trained GPT-2 weights.
GPT-2 Variants
GPT-2 Small, Medium, Large, Extra Large with varying model dimensionality and decoder layers.
Emergent abilities of large language models: GPT-2 (2019)
GPT-2 (1.5B parameters; Radford et al., 2019)
Same architecture as GPT, just bigger (117M -> 1.5B)
Trained on much more data: 4GB -> 40GB of internet text data (WebText)
Scrape links posted on Reddit w/ at least 3 upvotes (rough proxy of human quality)
Zero-shot Capabilities
One key emergent ability in GPT-2 is zero-shot: the ability to do many tasks without any examples, and no gradient updates, by simply:
Specifying the right sequence prediction problem (e.g. question answering):
Passage: Tom Brady… Q: Where was Tom Brady born? A: …Comparing probabilities of sequences (e.g., Winograd Schema Challenge):
The cat couldn’t fit into the hat because it was too big. Does it = the cat or the hat? ≡ Is P(…because the cat was too big) >= P(…because the hat was too big)? [Radford et al., 2019]
GPT-3
More layers & parameters
Bigger dataset
Longer training
Larger embedding/hidden dimension
Larger context window
GPT-3 (175B parameters; Brown et al., 2020)
Another increase in size (1.5B -> 175B) and data (40GB -> over 600GB)
Bigger is better?
BERT-Base model has 12 transformer blocks, 12 attention heads, 110M parameters
BERT-Large model has 24 transformer blocks, 16 attention heads, 340M parameters
GPT-2 is trained on 40GB of text data (8M webpages)! – 1.5B parameters
GPT-3 is an even bigger version of GPT-2, but since then, none of the GPT-series models have been open-sourced – 175B parameters
GPT-4 is estimated to have roughly 1.8 trillion parameters [estimated number, unconfirmed by OpenAI].
GPT-4o Mini could be as small as 8 billion parameters.
GPT-4o onwards
GPT-4 ‘o’-series of models can emulate the thinking process.
Enabled by reinforcement learning (RL), and by adding more synthetic data to the RL pipeline (after pre-training; called post-training phase)
Models can simulate an inner monologue, where they articulate their reasoning process step-by-step; helps in verifying the accuracy of their conclusion
Learning – Embedded within Pre-training Objective
Examples:
University of Surrey is located in _, United Kingdom. [Trivia]
I put ___ fork down on the table. [syntax]
The woman walked across the street, checking for traffic over ___ shoulder. [coreference]
I went to the ocean to see the fish, turtles, seals, and _. [lexical semantics/topic]
Overall, the value I got from the two hours watching it was the sum total of the popcorn and the drink. The movie was ___. [sentiment]
Iroh went into the kitchen to make some tea. Standing next to Iroh, Zuko pondered his destiny. Zuko left the . [some reasoning – this is harder]
I was thinking about the sequence that goes 1, 1, 2, 3, 5, 8, 13, 21, ____ [some basic arithmetic; they may not learn the Fibonnaci sequence]
Prompting a language model
Pretraining Knowledge
Language models learn various linguistic patterns during pretraining, such as syntax, coreference, and semantics.
Zero/Few-Shot Capabilities
GPT-2 onwards LLMs can perform tasks with and without limited examples, by predicting sequences or comparing probabilities.
Prompt Engineering
Crafting prompts that reformulate tasks to resemble those solved during pretraining.
Emergent few-shot learning
Specify a task by simply prepending examples of the task before your example
Also called in-context learning, to stress that no gradient updates are performed when learning a new task (there is a separate literature on few-shot learning with gradient updates).
Example prompt for translation quality scoring.
Emergent few-shot learning: Observed improvement in performance as an increasing number of examples are provided
Illustrated by leaderboard data.
Few-shot learning is an emergent property of model scale
Cycle letters: pleap -> apple
Random insertion: a.p!p/l!e -> apple
Reversed words: elppa -> apple
New methods of "prompting" LMs
Comparison of Zero/few-shot prompting vs. Traditional fine-tuning.
New methods of “prompting” LMs
Lab Assignment: Get familiar with zero-shot, one-shot and few-shot scenarios by prompt engineering for Dialogue Summarization.
Limits of prompting for harder tasks?
Some tasks seem too hard for even large LMs to learn through prompting alone, especially tasks involving richer, multi-step reasoning.
Solution: change the prompt!
Chain-of-thought prompting
Example illustrating the difference between standard prompting and chain-of-thought prompting for math word problems.
Chain-of-thought prompting, also emergent with model scale
Graph comparing performance of standard prompting vs. chain-of-thought prompting for different model scales.
Chain-of-thought prompting: Is reasoning necessary?
Do we even need examples of reasoning? Can we just ask the model to reason through things?
Zero-shot Chain-of-thought prompting
Example:
Q: A juggler can juggle 16 balls. Half of the balls are golf balls, and half of the golf balls are blue. How many blue golf balls are there?\ A: Let’s think step by step.
There are 16 balls in total. Half of the balls are golf balls. That means there are 8 golf balls. Half of the golf balls are blue. That means there are 4 blue golf balls.
Zero-shot Chain-of-thought prompting: Results show greatly outperforms zero-shot
Zero-shot Chain-of-thought prompting: Different Trigger Prompts
Varying accuracy based on the specific prompt used to trigger chain-of-thought reasoning.
Summary
Variants to BERT are available.
NLP tasks can be clubbed together, depending on the role/need in the pipeline.
Autoregressive Decoders are Transformer variants with stacked decoders.
Impressive task-level generation performance seen with emergent properties, in both zero-/few-shot scenarios, including CoT.
Modeling for an NLP task may very well be a matter of creating/engineering a detailed prompt, but ensuring accurate outputs from LLMs still requires supervised training data.
Next Lecture: LLM Prompting, Tuning & Task Evaluation in NLP.
Acknowledgements
Part of slides used from J. Eisner, J. Hockenmaier and Vivek Srikumar.
Images and GIF from Jay Alammar’s blogs.