Unit 2: Exploring Large Language Models (LLMs) - Subjective Questions
CSG202 — Generative Ai Fundamentals • Practice Questions with Detailed Answers
20 questions
Define Large Language Models (LLMs). What are the key characteristics that distinguish them from traditional language models?
Large Language Models (LLMs) are advanced deep learning models trained on massive volumes of text data to understand, generate, and manipulate human language.
Key Characteristics:
- Scale: They contain billions of parameters (e.g., GPT-3 has 175 billion parameters), which is far larger than traditional models.
- Transformer Architecture: Most LLMs are built on the transformer architecture, which uses self-attention mechanisms to process sequences in parallel.
- Pre-training and Fine-tuning: They are first pre-trained on general text corpora and later fine-tuned for specific tasks.
- Emergent Abilities: As models scale, they exhibit capabilities like reasoning, translation, and summarization that were not explicitly programmed.
- General-Purpose: A single LLM can perform many tasks (Q&A, code generation, summarization) without task-specific training.
Difference from Traditional Models: Traditional language models (like n-gram models) rely on statistical probabilities of short word sequences and are limited in context. LLMs capture long-range dependencies and semantic meaning, enabling far richer and more coherent text generation.
Explain the transformer architecture and why it is fundamental to modern LLMs.
The transformer architecture, introduced in the paper "Attention Is All You Need" (2017), is the foundational building block for modern LLMs.
Core Components:
- Self-Attention Mechanism: Allows the model to weigh the importance of different words in a sequence relative to each other, capturing context regardless of distance.
- Multi-Head Attention: Multiple attention mechanisms run in parallel to capture different types of relationships.
- Positional Encoding: Since transformers process tokens in parallel (not sequentially), positional encodings inject information about word order.
- Feed-Forward Networks: Applied to each position independently for further transformation.
- Encoder-Decoder Structure: The encoder processes input; the decoder generates output. Some LLMs use only the decoder (e.g., GPT) or only the encoder (e.g., BERT).
Why It Is Fundamental:
- Parallelization: Unlike RNNs, transformers process entire sequences at once, drastically speeding up training.
- Long-Range Dependencies: Self-attention captures relationships across long text spans.
- Scalability: The architecture scales effectively with more data and parameters, enabling the massive size of LLMs.
The attention score is computed as:
where , , and are the Query, Key, and Value matrices, and is the dimension of the keys.
Describe at least five real-world use cases of Large Language Models across different industries.
LLMs have broad applicability across industries. Key use cases include:
- Content Generation: Automatically drafting articles, marketing copy, emails, and social media posts.
- Chatbots and Virtual Assistants: Powering customer support bots that understand and respond to natural language queries (e.g., in banking, e-commerce).
- Code Generation and Assistance: Tools like GitHub Copilot help developers write, debug, and explain code.
- Language Translation: Providing high-quality, context-aware translation between languages.
- Summarization: Condensing long documents, legal contracts, or research papers into concise summaries.
- Sentiment Analysis: Analyzing customer reviews and feedback to gauge public opinion.
- Healthcare: Assisting with medical documentation, summarizing patient records, and answering clinical queries.
- Education: Acting as personalized tutors, generating quizzes, and explaining complex concepts.
Industry Impact: These use cases improve efficiency, reduce costs, and enable personalization at scale across finance, healthcare, retail, software development, and education.
What is Prompt Tuning? Explain how it differs from full fine-tuning of a model.
Prompt Tuning is a parameter-efficient technique for adapting a pre-trained LLM to specific tasks by learning a small set of continuous prompt vectors (soft prompts) while keeping the model's original weights frozen.
How It Works:
- Instead of updating billions of model parameters, prompt tuning learns task-specific soft prompts (trainable embeddings) prepended to the input.
- Only these prompt parameters are optimized during training.
Difference from Full Fine-Tuning:
| Aspect | Prompt Tuning | Full Fine-Tuning |
|---|---|---|
| Parameters Updated | Only soft prompts (small) | All model weights (billions) |
| Computational Cost | Low | Very high |
| Storage | One base model + small prompts per task | Separate full model per task |
| Performance | Comparable at large scale | Often slightly higher |
Advantages:
- Efficiency: Far fewer parameters to train and store.
- Flexibility: A single frozen model can serve many tasks with different prompts.
- Reduced Overfitting: Less prone to overfitting on small datasets.
Describe Google's Generative AI development tools and their key features.
Google offers a suite of tools and platforms for developing generative AI applications:
- Vertex AI: A unified machine learning platform that provides access to foundation models, tools for training, tuning, and deploying models, and MLOps capabilities.
- Generative AI Studio (Vertex AI Studio): A console-based tool that lets developers rapidly prototype and test prompts, tune models, and experiment with generative AI without deep coding.
- Model Garden: A repository within Vertex AI that offers a collection of pre-trained foundation models (including Google's and open-source models) ready for use.
- Gemini (formerly Bard/PaLM): Google's family of powerful multimodal LLMs capable of understanding text, images, audio, and code.
- Duet AI: An AI-powered collaborator integrated into Google Cloud and Workspace to assist with coding, writing, and productivity tasks.
- PaLM API: Provides programmatic access to Google's large language models for building applications.
Key Features:
- Managed Infrastructure: Scalable, secure cloud infrastructure.
- Prompt Design Tools: Interfaces to craft and refine prompts.
- Tuning Options: Support for prompt tuning and fine-tuning.
- Responsible AI: Built-in safety filters and governance tools.
Explain the concept of pre-training and fine-tuning in the context of LLMs. Why is this two-stage approach effective?
The development of LLMs typically follows a two-stage approach:
1. Pre-training:
- The model is trained on a massive, general corpus of unlabeled text (books, websites, articles).
- It learns general language patterns, grammar, facts, and reasoning through self-supervised objectives like predicting the next word or masked words.
- This stage is computationally expensive and time-consuming.
2. Fine-tuning:
- The pre-trained model is further trained on a smaller, task-specific labeled dataset.
- This adapts the general knowledge to a particular application (e.g., sentiment analysis, medical Q&A).
- Much faster and cheaper than pre-training.
Why It Is Effective:
- Transfer Learning: General knowledge learned during pre-training transfers to specific tasks, reducing the data needed.
- Efficiency: Expensive pre-training is done once; fine-tuning is repeated cheaply for many tasks.
- Better Performance: The model benefits from broad language understanding plus task specialization.
- Data Efficiency: Fine-tuning requires far less labeled data than training from scratch.
Distinguish between Prompt Engineering and Prompt Tuning.
Both techniques aim to guide an LLM's output, but they differ fundamentally:
Prompt Engineering:
- Involves manually crafting natural language prompts (instructions, examples, context) to elicit desired responses.
- No model training or parameter updates involved.
- Relies on human intuition and iterative experimentation.
- Uses discrete, human-readable text.
Prompt Tuning:
- Involves learning continuous soft prompt vectors through gradient-based optimization.
- The base model remains frozen, but the soft prompts are trainable parameters.
- Automated and data-driven.
- Soft prompts are not human-readable embeddings.
Comparison Table:
| Aspect | Prompt Engineering | Prompt Tuning |
|---|---|---|
| Approach | Manual crafting | Learned optimization |
| Training | None | Requires training data |
| Representation | Discrete text | Continuous vectors |
| Human Effort | High | Low (after setup) |
| Adaptability | Immediate | Needs training cycle |
Explain the challenges and limitations associated with Large Language Models.
Despite their capabilities, LLMs face several challenges and limitations:
- Hallucinations: LLMs may generate plausible-sounding but factually incorrect or fabricated information.
- Bias: Models can inherit and amplify biases present in their training data, leading to unfair or discriminatory outputs.
- High Computational Cost: Training and running LLMs require enormous computing resources and energy.
- Lack of Real-Time Knowledge: Models are limited to knowledge from their training data and may not know recent events (knowledge cutoff).
- Context Window Limits: They can only process a finite amount of text at once.
- Interpretability: LLMs are often "black boxes," making it hard to understand why they produce specific outputs.
- Data Privacy: Risk of memorizing and leaking sensitive training data.
- Environmental Impact: Large carbon footprint from training.
Mitigation Strategies: Techniques like Retrieval-Augmented Generation (RAG), fine-tuning, human feedback (RLHF), and safety filters help address these issues.
Describe the role of the self-attention mechanism in LLMs with an example.
The self-attention mechanism is the core innovation that allows LLMs to understand context by relating different words in a sequence to each other.
How It Works:
- For each word (token), the model computes three vectors: Query (Q), Key (K), and Value (V).
- The attention score between words is computed as:
- This determines how much each word should "attend to" every other word.
Example:
Consider the sentence: "The animal didn't cross the street because it was too tired."
- Self-attention helps the model determine that "it" refers to "animal" and not "street."
- The model assigns a higher attention weight between "it" and "animal" based on context.
Significance:
- Context Understanding: Resolves ambiguities and captures relationships.
- Parallel Processing: Computes relationships for all words simultaneously.
- Long-Range Dependencies: Connects distant but related words effectively.
What is Vertex AI? Describe its significance in developing generative AI applications.
Vertex AI is Google Cloud's unified machine learning and AI platform that enables developers and data scientists to build, deploy, and scale ML models and generative AI applications.
Key Components for Generative AI:
- Vertex AI Studio: A tool for prototyping, testing prompts, and tuning foundation models.
- Model Garden: A curated library of pre-trained foundation models (Gemini, PaLM, open-source models).
- Foundation Model APIs: Access to Google's powerful LLMs.
- Tuning Capabilities: Support for prompt tuning and fine-tuning models on custom data.
- MLOps Tools: Pipelines, monitoring, and model management for production.
Significance:
- Unified Platform: Combines data engineering, training, tuning, and deployment in one place.
- Accessibility: Lowers the barrier to using state-of-the-art models.
- Scalability: Handles enterprise-scale workloads on Google Cloud infrastructure.
- Responsible AI: Includes safety, governance, and explainability tools.
- Integration: Works seamlessly with other Google Cloud services.
Compare Zero-shot, One-shot, and Few-shot learning in the context of LLM prompting.
These are prompting strategies that differ by the number of examples provided to the LLM within the prompt:
1. Zero-shot Learning:
- The model is given a task without any examples, relying entirely on its pre-trained knowledge.
- Example: "Translate 'hello' to French."
2. One-shot Learning:
- The model is given one example to demonstrate the task before performing it.
- Example: "English: cat -> French: chat. English: dog -> French: ?"
3. Few-shot Learning:
- The model is provided with multiple examples (typically 2-5) to better understand the task pattern.
- Example: Providing several translation pairs before asking for a new one.
Comparison Table:
| Type | Examples Given | Accuracy | Prompt Length |
|---|---|---|---|
| Zero-shot | 0 | Lower | Short |
| One-shot | 1 | Moderate | Medium |
| Few-shot | 2+ | Higher | Longer |
Key Insight: More examples generally improve performance but consume more of the context window.
Explain Google Gemini and its capabilities as a multimodal model.
Google Gemini is Google's family of advanced, natively multimodal large language models designed to understand and process multiple types of information seamlessly.
Multimodal Capabilities:
- Text: Understanding and generating natural language.
- Images: Interpreting and reasoning about visual content.
- Audio: Processing spoken language and sounds.
- Video: Understanding video content.
- Code: Generating, explaining, and debugging code across languages.
Model Variants:
- Gemini Ultra: The largest and most capable model for highly complex tasks.
- Gemini Pro: Balanced model for a wide range of tasks, suitable for scaling.
- Gemini Nano: Lightweight model optimized for on-device tasks (e.g., smartphones).
Key Features:
- Native Multimodality: Built from the ground up to handle different data types together, rather than combining separate models.
- Advanced Reasoning: Strong performance in reasoning, math, and coding benchmarks.
- Integration: Available through Vertex AI, Google AI Studio, and integrated into Google products.
Significance: Gemini represents Google's most capable AI, enabling richer applications that combine text, vision, and audio understanding.
Describe the process of tuning a foundation model using Google's Vertex AI. What are the different tuning methods available?
Tuning in Vertex AI adapts a general-purpose foundation model to perform better on specific tasks or domains.
Tuning Process:
- Prepare Data: Create a labeled dataset of input-output examples relevant to the task.
- Select Base Model: Choose a foundation model from Model Garden.
- Configure Tuning Job: Set parameters like learning rate and number of steps.
- Run Tuning: Vertex AI trains the model on the provided data.
- Evaluate and Deploy: Test the tuned model and deploy it to an endpoint.
Tuning Methods Available:
- Prompt Tuning (Parameter-Efficient Tuning): Learns soft prompts while keeping the base model frozen. Efficient and low-cost.
- Supervised Fine-Tuning (SFT): Updates model parameters using labeled input-output pairs to improve task-specific performance.
- Reinforcement Learning from Human Feedback (RLHF): Uses human preference data to align model outputs with desired behavior.
- Distillation: Transfers knowledge from a larger model to a smaller, efficient one.
Benefits: Tuning improves accuracy, adapts the model to specialized vocabulary, and produces more relevant, consistent outputs for a given use case.
What are soft prompts? Explain their role in prompt tuning.
Soft prompts are learnable continuous vector representations (embeddings) that are prepended to the input of an LLM during prompt tuning. Unlike hard prompts (natural language text written by humans), soft prompts are not human-readable words but numerical vectors optimized through training.
Role in Prompt Tuning:
- Trainable Parameters: During prompt tuning, only the soft prompt vectors are updated via gradient descent, while the base model weights stay frozen.
- Task Encoding: The soft prompts learn to encode task-specific information that guides the frozen model toward the desired behavior.
- Parameter Efficiency: Only a small number of parameters (the prompt embeddings) are trained, making the process highly efficient.
Advantages:
- Flexibility: Different soft prompts can be trained for different tasks using the same base model.
- Compact Storage: Each task requires only a small set of prompt vectors rather than a full model copy.
- Performance: At large model scales, soft prompt tuning can approach the performance of full fine-tuning.
Key Distinction: Hard prompts are discrete tokens chosen from vocabulary; soft prompts exist in continuous embedding space and can represent concepts that no single word captures.
Explain how LLMs are used in the software development lifecycle with specific examples.
LLMs have become powerful assistants throughout the software development lifecycle (SDLC):
- Code Generation: Tools like GitHub Copilot and Google's Duet AI generate code snippets, functions, and boilerplate from natural language descriptions.
- Code Completion: Providing intelligent, context-aware autocompletion as developers type.
- Debugging: Identifying bugs, explaining error messages, and suggesting fixes.
- Code Documentation: Automatically generating comments, docstrings, and technical documentation.
- Code Review: Analyzing code for quality, style, and potential issues.
- Test Generation: Creating unit tests and test cases automatically.
- Code Translation: Converting code from one programming language to another.
- Learning and Explanation: Explaining complex code or unfamiliar codebases to developers.
Example Workflow:
- A developer writes a comment:
// function to sort a list of users by age. - The LLM generates the corresponding function.
- The developer asks the LLM to generate unit tests for it.
- The LLM documents the function automatically.
Benefits: Increased productivity, reduced errors, faster onboarding, and lower development costs.
Distinguish between encoder-only, decoder-only, and encoder-decoder transformer architectures with examples.
Transformer-based models can be categorized into three architectural types based on which parts of the transformer they use:
1. Encoder-Only Models:
- Use only the encoder stack.
- Best for understanding tasks like classification, sentiment analysis, and named entity recognition.
- Process input bidirectionally (see full context).
- Example: BERT.
2. Decoder-Only Models:
- Use only the decoder stack.
- Best for generation tasks like text completion and conversation.
- Process text autoregressively (left-to-right, predicting the next token).
- Example: GPT series, PaLM.
3. Encoder-Decoder Models:
- Use both encoder and decoder stacks.
- Best for sequence-to-sequence tasks like translation and summarization.
- Encoder understands input; decoder generates output.
- Example: T5, BART.
Comparison Table:
| Architecture | Best For | Direction | Example |
|---|---|---|---|
| Encoder-only | Understanding | Bidirectional | BERT |
| Decoder-only | Generation | Left-to-right | GPT |
| Encoder-decoder | Seq-to-seq | Both | T5 |
Explain the concept of tokens and tokenization in LLMs. Why is tokenization important?
Tokenization is the process of breaking down input text into smaller units called tokens, which are the basic building blocks that an LLM processes.
What Are Tokens?
- Tokens can be words, subwords, characters, or punctuation depending on the tokenization method.
- For example, the word "unbelievable" might be split into subword tokens: "un", "believ", "able".
- On average, one token corresponds to roughly 4 characters or about 0.75 words in English.
Common Tokenization Methods:
- Byte-Pair Encoding (BPE): Merges frequent character pairs into subword units.
- WordPiece: Similar to BPE, used by BERT.
- SentencePiece: Language-independent subword tokenization.
Why Tokenization Is Important:
- Model Input: LLMs cannot process raw text; they work with numerical token IDs.
- Vocabulary Management: Subword tokenization handles rare and unknown words by breaking them into known pieces.
- Context Window: Model limits are measured in tokens (e.g., 4096 tokens), affecting how much text can be processed.
- Cost: API pricing is often based on the number of tokens processed.
Significance: Efficient tokenization balances vocabulary size, sequence length, and the ability to represent diverse text.
Describe Google AI Studio (Generative AI Studio) and how it helps developers build generative AI applications.
Google AI Studio (also known as Generative AI Studio within Vertex AI) is a web-based tool that provides a user-friendly environment for developers to explore, prototype, and build with Google's generative AI models.
Key Features:
- Prompt Design and Testing: An interactive interface to write, test, and refine prompts and immediately see model responses.
- Model Selection: Access to Google's foundation models like Gemini and PaLM.
- Prompt Gallery: Pre-built prompt examples for common use cases to jumpstart development.
- Parameter Tuning: Adjust settings like temperature, top-k, top-p, and output length to control response behavior.
- Multimodal Support: Test prompts with text, images, and other data types.
- Code Export: Generate code (Python, cURL, etc.) to integrate prompts into applications via API.
- Tuning Tools: Options to fine-tune or prompt-tune models on custom data.
How It Helps Developers:
- Rapid Prototyping: Quickly experiment with prompts without writing code.
- Lower Barrier to Entry: Accessible to those without deep ML expertise.
- Seamless Transition: Move from prototype to production by exporting code.
- Iterative Refinement: Easily test and compare different prompt strategies.
Explain the key parameters (temperature, top-k, top-p) that control an LLM's output and how each affects generation.
Several parameters control the randomness and creativity of an LLM's text generation:
1. Temperature:
- Controls the randomness of predictions by scaling the probability distribution.
- Low temperature (e.g., 0.1): More deterministic, focused, and predictable output.
- High temperature (e.g., 0.9): More diverse, creative, and random output.
- Mathematically, it adjusts the softmax: where is temperature.
2. Top-k Sampling:
- The model considers only the top most probable next tokens and samples from them.
- Example: If , only the 5 highest-probability tokens are candidates.
- Lower makes output more focused; higher adds diversity.
3. Top-p (Nucleus) Sampling:
- The model considers the smallest set of tokens whose cumulative probability exceeds a threshold .
- Example: If , it includes tokens until their combined probability reaches 90%.
- Adapts the candidate pool size dynamically based on the probability distribution.
Combined Effect: These parameters are tuned together to balance coherence (predictability) and creativity (diversity) based on the application's needs. For factual tasks, use low values; for creative tasks, use higher values.
Describe the ethical considerations and Responsible AI practices that should be followed when deploying LLMs.
Deploying LLMs responsibly requires careful attention to ethical considerations to prevent harm and ensure trustworthiness.
Key Ethical Considerations:
- Bias and Fairness: LLMs can perpetuate biases in training data; outputs must be monitored and mitigated to avoid discrimination.
- Misinformation: Hallucinations can spread false information; fact-checking and grounding are essential.
- Privacy: Models may leak sensitive data; personal information must be protected.
- Transparency: Users should know when they are interacting with AI.
- Accountability: Clear responsibility for AI decisions and outputs.
- Harmful Content: Preventing generation of toxic, violent, or illegal content.
Responsible AI Practices:
- Safety Filters: Implement content moderation to block harmful outputs.
- Human Oversight: Keep humans in the loop for critical decisions.
- Bias Testing: Regularly evaluate models for fairness across groups.
- Data Governance: Ensure training data is ethically sourced and privacy-compliant.
- Explainability: Provide insights into model behavior where possible.
- Grounding with RAG: Use retrieval-augmented generation to base answers on verified sources.
Google's Approach: Google's AI Principles guide responsible development, emphasizing fairness, safety, privacy, and accountability, with built-in safety tools in Vertex AI.
Define Large Language Models (LLMs). What are the key characteristics that distinguish them from traditional language models?
Large Language Models (LLMs) are advanced deep learning models trained on massive volumes of text data to understand, generate, and manipulate human language.
Key Characteristics:
- Scale: They contain billions of parameters (e.g., GPT-3 has 175 billion parameters), which is far larger than traditional models.
- Transformer Architecture: Most LLMs are built on the transformer architecture, which uses self-attention mechanisms to process sequences in parallel.
- Pre-training and Fine-tuning: They are first pre-trained on general text corpora and later fine-tuned for specific tasks.
- Emergent Abilities: As models scale, they exhibit capabilities like reasoning, translation, and summarization that were not explicitly programmed.
- General-Purpose: A single LLM can perform many tasks (Q&A, code generation, summarization) without task-specific training.
Difference from Traditional Models: Traditional language models (like n-gram models) rely on statistical probabilities of short word sequences and are limited in context. LLMs capture long-range dependencies and semantic meaning, enabling far richer and more coherent text generation.
Did this save you a night before the exam?
LPU Notes is free, and it stays free. Ads cover part of the server bill. The rest comes out of a student's own pocket: the domain, the storage, and keeping the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason. to try again.
Nothing here is ever locked, and nothing unlocks. Chip in only if it was worth it. What it pays for →